]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/3.14.3/grsecurity-3.0-3.14.3-201405101947.patch
Auto commit, grsecurity-3.1-4.9.16-201703180820.patch added.
[thirdparty/grsecurity-scrape.git] / test / 3.14.3 / grsecurity-3.0-3.14.3-201405101947.patch
CommitLineData
48e92f95
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..e289b9b 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,32 +101,40 @@ 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 crc32table.h*
90 cscope.*
91 defkeymap.c
92+devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97+dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101+exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105@@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109+gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116+hash
117+hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121@@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125-kconfig
126+kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133-linux
134+lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138@@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142-media
143 mconf
144+mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151+mkpiggy
152 mkprep
153 mkregtable
154 mktables
155@@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159+parse-events*
160+pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164@@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168+pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172@@ -203,7 +227,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176+randomize_layout_hash.h
177+randomize_layout_seed.h
178+realmode.lds
179+realmode.relocs
180 recordmcount
181+regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185@@ -213,8 +242,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189+signing_key*
190+size_overflow_hash.h
191 sImage
192+slabinfo
193 sm_tbl*
194+sortextable
195 split-include
196 syscalltab.h
197 tables.c
198@@ -224,6 +257,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202+user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206@@ -235,13 +269,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210+vdsox32.lds
211+vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218+vmlinux.bin.bz2
219 vmlinux.lds
220+vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224@@ -249,9 +287,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228+utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232+x509*
233 zImage*
234 zconf.hash.c
235+zconf.lex.c
236 zoffset.h
237diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238index 7116fda..d8ed6e8 100644
239--- a/Documentation/kernel-parameters.txt
240+++ b/Documentation/kernel-parameters.txt
241@@ -1084,6 +1084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246+ ignore grsecurity's /proc restrictions
247+
248+
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252@@ -2080,6 +2084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256+ nopcid [X86-64]
257+ Disable PCID (Process-Context IDentifier) even if it
258+ is supported by the processor.
259+
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263@@ -2347,6 +2355,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268+ virtualization environments that don't cope well with the
269+ expand down segment used by UDEREF on X86-32 or the frequent
270+ page table updates on X86-64.
271+
272+ pax_sanitize_slab=
273+ 0/1 to disable/enable slab object sanitization (enabled by
274+ default).
275+
276+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277+
278+ pax_extra_latent_entropy
279+ Enable a very simple form of latent entropy extraction
280+ from the first 4GB of memory as the bootmem allocator
281+ passes the memory pages to the buddy allocator.
282+
283+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284+ when the processor supports PCID.
285+
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289diff --git a/Makefile b/Makefile
290index eed07f3..2b75821 100644
291--- a/Makefile
292+++ b/Makefile
293@@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298-HOSTCXXFLAGS = -O2
299+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301+HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305@@ -423,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309-PHONY += scripts_basic
310-scripts_basic:
311+PHONY += scripts_basic gcc-plugins
312+scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316@@ -585,6 +586,72 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320+ifndef DISABLE_PAX_PLUGINS
321+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323+else
324+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325+endif
326+ifneq ($(PLUGINCC),)
327+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329+endif
330+ifdef CONFIG_PAX_MEMORY_STACKLEAK
331+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333+endif
334+ifdef CONFIG_KALLOCSTAT_PLUGIN
335+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336+endif
337+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341+endif
342+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346+endif
347+endif
348+ifdef CONFIG_CHECKER_PLUGIN
349+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351+endif
352+endif
353+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354+ifdef CONFIG_PAX_SIZE_OVERFLOW
355+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356+endif
357+ifdef CONFIG_PAX_LATENT_ENTROPY
358+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359+endif
360+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362+endif
363+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369+ifeq ($(KBUILD_EXTMOD),)
370+gcc-plugins:
371+ $(Q)$(MAKE) $(build)=tools/gcc
372+else
373+gcc-plugins: ;
374+endif
375+else
376+gcc-plugins:
377+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378+ $(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.))
379+else
380+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381+endif
382+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383+endif
384+endif
385+
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389@@ -779,7 +846,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398@@ -828,6 +895,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407@@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411-$(vmlinux-dirs): prepare scripts
412+$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416@@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430@@ -991,6 +1063,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439@@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443-modules_prepare: prepare scripts
444+modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448@@ -1072,7 +1146,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452- signing_key.x509.signer
453+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
454+ tools/gcc/randomize_layout_seed.h
455
456 # clean - Delete most, but leave enough to build external modules
457 #
458@@ -1112,6 +1187,7 @@ distclean: mrproper
459 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
460 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
461 -o -name '.*.rej' \
462+ -o -name '.*.rej' -o -name '*.so' \
463 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
464 -type f -print | xargs rm -f
465
466@@ -1273,6 +1349,8 @@ PHONY += $(module-dirs) modules
467 $(module-dirs): crmodverdir $(objtree)/Module.symvers
468 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
469
470+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
471+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
472 modules: $(module-dirs)
473 @$(kecho) ' Building modules, stage 2.';
474 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
475@@ -1412,17 +1490,21 @@ else
476 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
477 endif
478
479-%.s: %.c prepare scripts FORCE
480+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
481+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
482+%.s: %.c gcc-plugins prepare scripts FORCE
483 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
484 %.i: %.c prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486-%.o: %.c prepare scripts FORCE
487+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
488+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
489+%.o: %.c gcc-plugins prepare scripts FORCE
490 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
491 %.lst: %.c prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493-%.s: %.S prepare scripts FORCE
494+%.s: %.S gcc-plugins prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496-%.o: %.S prepare scripts FORCE
497+%.o: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 %.symtypes: %.c prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501@@ -1432,11 +1514,15 @@ endif
502 $(cmd_crmodverdir)
503 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
504 $(build)=$(build-dir)
505-%/: prepare scripts FORCE
506+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
507+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
508+%/: gcc-plugins prepare scripts FORCE
509 $(cmd_crmodverdir)
510 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
511 $(build)=$(build-dir)
512-%.ko: prepare scripts FORCE
513+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
514+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
515+%.ko: gcc-plugins prepare scripts FORCE
516 $(cmd_crmodverdir)
517 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
518 $(build)=$(build-dir) $(@:.ko=.o)
519diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
520index 78b03ef..da28a51 100644
521--- a/arch/alpha/include/asm/atomic.h
522+++ b/arch/alpha/include/asm/atomic.h
523@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
524 #define atomic_dec(v) atomic_sub(1,(v))
525 #define atomic64_dec(v) atomic64_sub(1,(v))
526
527+#define atomic64_read_unchecked(v) atomic64_read(v)
528+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
529+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
530+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
531+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
532+#define atomic64_inc_unchecked(v) atomic64_inc(v)
533+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
534+#define atomic64_dec_unchecked(v) atomic64_dec(v)
535+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
536+
537 #define smp_mb__before_atomic_dec() smp_mb()
538 #define smp_mb__after_atomic_dec() smp_mb()
539 #define smp_mb__before_atomic_inc() smp_mb()
540diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
541index ad368a9..fbe0f25 100644
542--- a/arch/alpha/include/asm/cache.h
543+++ b/arch/alpha/include/asm/cache.h
544@@ -4,19 +4,19 @@
545 #ifndef __ARCH_ALPHA_CACHE_H
546 #define __ARCH_ALPHA_CACHE_H
547
548+#include <linux/const.h>
549
550 /* Bytes per L1 (data) cache line. */
551 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
552-# define L1_CACHE_BYTES 64
553 # define L1_CACHE_SHIFT 6
554 #else
555 /* Both EV4 and EV5 are write-through, read-allocate,
556 direct-mapped, physical.
557 */
558-# define L1_CACHE_BYTES 32
559 # define L1_CACHE_SHIFT 5
560 #endif
561
562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
563 #define SMP_CACHE_BYTES L1_CACHE_BYTES
564
565 #endif
566diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
567index 968d999..d36b2df 100644
568--- a/arch/alpha/include/asm/elf.h
569+++ b/arch/alpha/include/asm/elf.h
570@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
571
572 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
573
574+#ifdef CONFIG_PAX_ASLR
575+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
576+
577+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
578+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
579+#endif
580+
581 /* $0 is set by ld.so to a pointer to a function which might be
582 registered using atexit. This provides a mean for the dynamic
583 linker to call DT_FINI functions for shared libraries that have
584diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
585index aab14a0..b4fa3e7 100644
586--- a/arch/alpha/include/asm/pgalloc.h
587+++ b/arch/alpha/include/asm/pgalloc.h
588@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
589 pgd_set(pgd, pmd);
590 }
591
592+static inline void
593+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
594+{
595+ pgd_populate(mm, pgd, pmd);
596+}
597+
598 extern pgd_t *pgd_alloc(struct mm_struct *mm);
599
600 static inline void
601diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
602index d8f9b7e..f6222fa 100644
603--- a/arch/alpha/include/asm/pgtable.h
604+++ b/arch/alpha/include/asm/pgtable.h
605@@ -102,6 +102,17 @@ struct vm_area_struct;
606 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
607 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
608 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
609+
610+#ifdef CONFIG_PAX_PAGEEXEC
611+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
612+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
613+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
614+#else
615+# define PAGE_SHARED_NOEXEC PAGE_SHARED
616+# define PAGE_COPY_NOEXEC PAGE_COPY
617+# define PAGE_READONLY_NOEXEC PAGE_READONLY
618+#endif
619+
620 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
621
622 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
623diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
624index 2fd00b7..cfd5069 100644
625--- a/arch/alpha/kernel/module.c
626+++ b/arch/alpha/kernel/module.c
627@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
628
629 /* The small sections were sorted to the end of the segment.
630 The following should definitely cover them. */
631- gp = (u64)me->module_core + me->core_size - 0x8000;
632+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
633 got = sechdrs[me->arch.gotsecindex].sh_addr;
634
635 for (i = 0; i < n; i++) {
636diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
637index 1402fcc..0b1abd2 100644
638--- a/arch/alpha/kernel/osf_sys.c
639+++ b/arch/alpha/kernel/osf_sys.c
640@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
641 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
642
643 static unsigned long
644-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
645- unsigned long limit)
646+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
647+ unsigned long limit, unsigned long flags)
648 {
649 struct vm_unmapped_area_info info;
650+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
651
652 info.flags = 0;
653 info.length = len;
654@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
655 info.high_limit = limit;
656 info.align_mask = 0;
657 info.align_offset = 0;
658+ info.threadstack_offset = offset;
659 return vm_unmapped_area(&info);
660 }
661
662@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
663 merely specific addresses, but regions of memory -- perhaps
664 this feature should be incorporated into all ports? */
665
666+#ifdef CONFIG_PAX_RANDMMAP
667+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
668+#endif
669+
670 if (addr) {
671- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
672+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
673 if (addr != (unsigned long) -ENOMEM)
674 return addr;
675 }
676
677 /* Next, try allocating at TASK_UNMAPPED_BASE. */
678- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
679- len, limit);
680+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
681+
682 if (addr != (unsigned long) -ENOMEM)
683 return addr;
684
685 /* Finally, try allocating in low memory. */
686- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
687+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
688
689 return addr;
690 }
691diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
692index 98838a0..b304fb4 100644
693--- a/arch/alpha/mm/fault.c
694+++ b/arch/alpha/mm/fault.c
695@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
696 __reload_thread(pcb);
697 }
698
699+#ifdef CONFIG_PAX_PAGEEXEC
700+/*
701+ * PaX: decide what to do with offenders (regs->pc = fault address)
702+ *
703+ * returns 1 when task should be killed
704+ * 2 when patched PLT trampoline was detected
705+ * 3 when unpatched PLT trampoline was detected
706+ */
707+static int pax_handle_fetch_fault(struct pt_regs *regs)
708+{
709+
710+#ifdef CONFIG_PAX_EMUPLT
711+ int err;
712+
713+ do { /* PaX: patched PLT emulation #1 */
714+ unsigned int ldah, ldq, jmp;
715+
716+ err = get_user(ldah, (unsigned int *)regs->pc);
717+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
718+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
719+
720+ if (err)
721+ break;
722+
723+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
724+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
725+ jmp == 0x6BFB0000U)
726+ {
727+ unsigned long r27, addr;
728+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
729+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
730+
731+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
732+ err = get_user(r27, (unsigned long *)addr);
733+ if (err)
734+ break;
735+
736+ regs->r27 = r27;
737+ regs->pc = r27;
738+ return 2;
739+ }
740+ } while (0);
741+
742+ do { /* PaX: patched PLT emulation #2 */
743+ unsigned int ldah, lda, br;
744+
745+ err = get_user(ldah, (unsigned int *)regs->pc);
746+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
747+ err |= get_user(br, (unsigned int *)(regs->pc+8));
748+
749+ if (err)
750+ break;
751+
752+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
753+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
754+ (br & 0xFFE00000U) == 0xC3E00000U)
755+ {
756+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
757+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
758+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
759+
760+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
761+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
762+ return 2;
763+ }
764+ } while (0);
765+
766+ do { /* PaX: unpatched PLT emulation */
767+ unsigned int br;
768+
769+ err = get_user(br, (unsigned int *)regs->pc);
770+
771+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
772+ unsigned int br2, ldq, nop, jmp;
773+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
774+
775+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
776+ err = get_user(br2, (unsigned int *)addr);
777+ err |= get_user(ldq, (unsigned int *)(addr+4));
778+ err |= get_user(nop, (unsigned int *)(addr+8));
779+ err |= get_user(jmp, (unsigned int *)(addr+12));
780+ err |= get_user(resolver, (unsigned long *)(addr+16));
781+
782+ if (err)
783+ break;
784+
785+ if (br2 == 0xC3600000U &&
786+ ldq == 0xA77B000CU &&
787+ nop == 0x47FF041FU &&
788+ jmp == 0x6B7B0000U)
789+ {
790+ regs->r28 = regs->pc+4;
791+ regs->r27 = addr+16;
792+ regs->pc = resolver;
793+ return 3;
794+ }
795+ }
796+ } while (0);
797+#endif
798+
799+ return 1;
800+}
801+
802+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
803+{
804+ unsigned long i;
805+
806+ printk(KERN_ERR "PAX: bytes at PC: ");
807+ for (i = 0; i < 5; i++) {
808+ unsigned int c;
809+ if (get_user(c, (unsigned int *)pc+i))
810+ printk(KERN_CONT "???????? ");
811+ else
812+ printk(KERN_CONT "%08x ", c);
813+ }
814+ printk("\n");
815+}
816+#endif
817
818 /*
819 * This routine handles page faults. It determines the address,
820@@ -133,8 +251,29 @@ retry:
821 good_area:
822 si_code = SEGV_ACCERR;
823 if (cause < 0) {
824- if (!(vma->vm_flags & VM_EXEC))
825+ if (!(vma->vm_flags & VM_EXEC)) {
826+
827+#ifdef CONFIG_PAX_PAGEEXEC
828+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
829+ goto bad_area;
830+
831+ up_read(&mm->mmap_sem);
832+ switch (pax_handle_fetch_fault(regs)) {
833+
834+#ifdef CONFIG_PAX_EMUPLT
835+ case 2:
836+ case 3:
837+ return;
838+#endif
839+
840+ }
841+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
842+ do_group_exit(SIGKILL);
843+#else
844 goto bad_area;
845+#endif
846+
847+ }
848 } else if (!cause) {
849 /* Allow reads even for write-only mappings */
850 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
851diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
852index 44298ad..29a20c0 100644
853--- a/arch/arm/Kconfig
854+++ b/arch/arm/Kconfig
855@@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
856
857 config UACCESS_WITH_MEMCPY
858 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
859- depends on MMU
860+ depends on MMU && !PAX_MEMORY_UDEREF
861 default y if CPU_FEROCEON
862 help
863 Implement faster copy_to_user and clear_user methods for CPU
864@@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
865 config KEXEC
866 bool "Kexec system call (EXPERIMENTAL)"
867 depends on (!SMP || PM_SLEEP_SMP)
868+ depends on !GRKERNSEC_KMEM
869 help
870 kexec is a system call that implements the ability to shutdown your
871 current kernel, and to start another kernel. It is like a reboot
872diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
873index 62d2cb5..09d45e3 100644
874--- a/arch/arm/include/asm/atomic.h
875+++ b/arch/arm/include/asm/atomic.h
876@@ -18,17 +18,35 @@
877 #include <asm/barrier.h>
878 #include <asm/cmpxchg.h>
879
880+#ifdef CONFIG_GENERIC_ATOMIC64
881+#include <asm-generic/atomic64.h>
882+#endif
883+
884 #define ATOMIC_INIT(i) { (i) }
885
886 #ifdef __KERNEL__
887
888+#define _ASM_EXTABLE(from, to) \
889+" .pushsection __ex_table,\"a\"\n"\
890+" .align 3\n" \
891+" .long " #from ", " #to"\n" \
892+" .popsection"
893+
894 /*
895 * On ARM, ordinary assignment (str instruction) doesn't clear the local
896 * strex/ldrex monitor on some implementations. The reason we can use it for
897 * atomic_set() is the clrex or dummy strex done on every exception return.
898 */
899 #define atomic_read(v) (*(volatile int *)&(v)->counter)
900+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
901+{
902+ return v->counter;
903+}
904 #define atomic_set(v,i) (((v)->counter) = (i))
905+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
906+{
907+ v->counter = i;
908+}
909
910 #if __LINUX_ARM_ARCH__ >= 6
911
912@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
913
914 prefetchw(&v->counter);
915 __asm__ __volatile__("@ atomic_add\n"
916+"1: ldrex %1, [%3]\n"
917+" adds %0, %1, %4\n"
918+
919+#ifdef CONFIG_PAX_REFCOUNT
920+" bvc 3f\n"
921+"2: bkpt 0xf103\n"
922+"3:\n"
923+#endif
924+
925+" strex %1, %0, [%3]\n"
926+" teq %1, #0\n"
927+" bne 1b"
928+
929+#ifdef CONFIG_PAX_REFCOUNT
930+"\n4:\n"
931+ _ASM_EXTABLE(2b, 4b)
932+#endif
933+
934+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
935+ : "r" (&v->counter), "Ir" (i)
936+ : "cc");
937+}
938+
939+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
940+{
941+ unsigned long tmp;
942+ int result;
943+
944+ prefetchw(&v->counter);
945+ __asm__ __volatile__("@ atomic_add_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_add_return\n"
953+"1: ldrex %1, [%3]\n"
954+" adds %0, %1, %4\n"
955+
956+#ifdef CONFIG_PAX_REFCOUNT
957+" bvc 3f\n"
958+" mov %0, %1\n"
959+"2: bkpt 0xf103\n"
960+"3:\n"
961+#endif
962+
963+" strex %1, %0, [%3]\n"
964+" teq %1, #0\n"
965+" bne 1b"
966+
967+#ifdef CONFIG_PAX_REFCOUNT
968+"\n4:\n"
969+ _ASM_EXTABLE(2b, 4b)
970+#endif
971+
972+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
973+ : "r" (&v->counter), "Ir" (i)
974+ : "cc");
975+
976+ smp_mb();
977+
978+ return result;
979+}
980+
981+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
982+{
983+ unsigned long tmp;
984+ int result;
985+
986+ smp_mb();
987+
988+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
989 "1: ldrex %0, [%3]\n"
990 " add %0, %0, %4\n"
991 " strex %1, %0, [%3]\n"
992@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
993
994 prefetchw(&v->counter);
995 __asm__ __volatile__("@ atomic_sub\n"
996+"1: ldrex %1, [%3]\n"
997+" subs %0, %1, %4\n"
998+
999+#ifdef CONFIG_PAX_REFCOUNT
1000+" bvc 3f\n"
1001+"2: bkpt 0xf103\n"
1002+"3:\n"
1003+#endif
1004+
1005+" strex %1, %0, [%3]\n"
1006+" teq %1, #0\n"
1007+" bne 1b"
1008+
1009+#ifdef CONFIG_PAX_REFCOUNT
1010+"\n4:\n"
1011+ _ASM_EXTABLE(2b, 4b)
1012+#endif
1013+
1014+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1015+ : "r" (&v->counter), "Ir" (i)
1016+ : "cc");
1017+}
1018+
1019+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1020+{
1021+ unsigned long tmp;
1022+ int result;
1023+
1024+ prefetchw(&v->counter);
1025+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1026 "1: ldrex %0, [%3]\n"
1027 " sub %0, %0, %4\n"
1028 " strex %1, %0, [%3]\n"
1029@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1030 smp_mb();
1031
1032 __asm__ __volatile__("@ atomic_sub_return\n"
1033-"1: ldrex %0, [%3]\n"
1034-" sub %0, %0, %4\n"
1035+"1: ldrex %1, [%3]\n"
1036+" subs %0, %1, %4\n"
1037+
1038+#ifdef CONFIG_PAX_REFCOUNT
1039+" bvc 3f\n"
1040+" mov %0, %1\n"
1041+"2: bkpt 0xf103\n"
1042+"3:\n"
1043+#endif
1044+
1045 " strex %1, %0, [%3]\n"
1046 " teq %1, #0\n"
1047 " bne 1b"
1048+
1049+#ifdef CONFIG_PAX_REFCOUNT
1050+"\n4:\n"
1051+ _ASM_EXTABLE(2b, 4b)
1052+#endif
1053+
1054 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1055 : "r" (&v->counter), "Ir" (i)
1056 : "cc");
1057@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1058 return oldval;
1059 }
1060
1061+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1062+{
1063+ unsigned long oldval, res;
1064+
1065+ smp_mb();
1066+
1067+ do {
1068+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1069+ "ldrex %1, [%3]\n"
1070+ "mov %0, #0\n"
1071+ "teq %1, %4\n"
1072+ "strexeq %0, %5, [%3]\n"
1073+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1074+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1075+ : "cc");
1076+ } while (res);
1077+
1078+ smp_mb();
1079+
1080+ return oldval;
1081+}
1082+
1083 #else /* ARM_ARCH_6 */
1084
1085 #ifdef CONFIG_SMP
1086@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1087
1088 return val;
1089 }
1090+
1091+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1092+{
1093+ return atomic_add_return(i, v);
1094+}
1095+
1096 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1097+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1098+{
1099+ (void) atomic_add_return(i, v);
1100+}
1101
1102 static inline int atomic_sub_return(int i, atomic_t *v)
1103 {
1104@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1105 return val;
1106 }
1107 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1108+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1109+{
1110+ (void) atomic_sub_return(i, v);
1111+}
1112
1113 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1114 {
1115@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 return ret;
1117 }
1118
1119+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1120+{
1121+ return atomic_cmpxchg(v, old, new);
1122+}
1123+
1124 #endif /* __LINUX_ARM_ARCH__ */
1125
1126 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1127+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1128+{
1129+ return xchg(&v->counter, new);
1130+}
1131
1132 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1133 {
1134@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 }
1136
1137 #define atomic_inc(v) atomic_add(1, v)
1138+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1139+{
1140+ atomic_add_unchecked(1, v);
1141+}
1142 #define atomic_dec(v) atomic_sub(1, v)
1143+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1144+{
1145+ atomic_sub_unchecked(1, v);
1146+}
1147
1148 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1149+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1150+{
1151+ return atomic_add_return_unchecked(1, v) == 0;
1152+}
1153 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1154 #define atomic_inc_return(v) (atomic_add_return(1, v))
1155+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1156+{
1157+ return atomic_add_return_unchecked(1, v);
1158+}
1159 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1160 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1161
1162@@ -221,6 +410,14 @@ typedef struct {
1163 long long counter;
1164 } atomic64_t;
1165
1166+#ifdef CONFIG_PAX_REFCOUNT
1167+typedef struct {
1168+ long long counter;
1169+} atomic64_unchecked_t;
1170+#else
1171+typedef atomic64_t atomic64_unchecked_t;
1172+#endif
1173+
1174 #define ATOMIC64_INIT(i) { (i) }
1175
1176 #ifdef CONFIG_ARM_LPAE
1177@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1178 return result;
1179 }
1180
1181+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1182+{
1183+ long long result;
1184+
1185+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1186+" ldrd %0, %H0, [%1]"
1187+ : "=&r" (result)
1188+ : "r" (&v->counter), "Qo" (v->counter)
1189+ );
1190+
1191+ return result;
1192+}
1193+
1194 static inline void atomic64_set(atomic64_t *v, long long i)
1195 {
1196 __asm__ __volatile__("@ atomic64_set\n"
1197@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1198 : "r" (&v->counter), "r" (i)
1199 );
1200 }
1201+
1202+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1203+{
1204+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1205+" strd %2, %H2, [%1]"
1206+ : "=Qo" (v->counter)
1207+ : "r" (&v->counter), "r" (i)
1208+ );
1209+}
1210 #else
1211 static inline long long atomic64_read(const atomic64_t *v)
1212 {
1213@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1214 return result;
1215 }
1216
1217+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1218+{
1219+ long long result;
1220+
1221+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1222+" ldrexd %0, %H0, [%1]"
1223+ : "=&r" (result)
1224+ : "r" (&v->counter), "Qo" (v->counter)
1225+ );
1226+
1227+ return result;
1228+}
1229+
1230 static inline void atomic64_set(atomic64_t *v, long long i)
1231 {
1232 long long tmp;
1233@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1234 : "r" (&v->counter), "r" (i)
1235 : "cc");
1236 }
1237+
1238+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1239+{
1240+ long long tmp;
1241+
1242+ prefetchw(&v->counter);
1243+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1244+"1: ldrexd %0, %H0, [%2]\n"
1245+" strexd %0, %3, %H3, [%2]\n"
1246+" teq %0, #0\n"
1247+" bne 1b"
1248+ : "=&r" (tmp), "=Qo" (v->counter)
1249+ : "r" (&v->counter), "r" (i)
1250+ : "cc");
1251+}
1252 #endif
1253
1254 static inline void atomic64_add(long long i, atomic64_t *v)
1255@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1256 __asm__ __volatile__("@ atomic64_add\n"
1257 "1: ldrexd %0, %H0, [%3]\n"
1258 " adds %Q0, %Q0, %Q4\n"
1259+" adcs %R0, %R0, %R4\n"
1260+
1261+#ifdef CONFIG_PAX_REFCOUNT
1262+" bvc 3f\n"
1263+"2: bkpt 0xf103\n"
1264+"3:\n"
1265+#endif
1266+
1267+" strexd %1, %0, %H0, [%3]\n"
1268+" teq %1, #0\n"
1269+" bne 1b"
1270+
1271+#ifdef CONFIG_PAX_REFCOUNT
1272+"\n4:\n"
1273+ _ASM_EXTABLE(2b, 4b)
1274+#endif
1275+
1276+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1277+ : "r" (&v->counter), "r" (i)
1278+ : "cc");
1279+}
1280+
1281+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1282+{
1283+ long long result;
1284+ unsigned long tmp;
1285+
1286+ prefetchw(&v->counter);
1287+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1288+"1: ldrexd %0, %H0, [%3]\n"
1289+" adds %Q0, %Q0, %Q4\n"
1290 " adc %R0, %R0, %R4\n"
1291 " strexd %1, %0, %H0, [%3]\n"
1292 " teq %1, #0\n"
1293@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1294 __asm__ __volatile__("@ atomic64_add_return\n"
1295 "1: ldrexd %0, %H0, [%3]\n"
1296 " adds %Q0, %Q0, %Q4\n"
1297+" adcs %R0, %R0, %R4\n"
1298+
1299+#ifdef CONFIG_PAX_REFCOUNT
1300+" bvc 3f\n"
1301+" mov %0, %1\n"
1302+" mov %H0, %H1\n"
1303+"2: bkpt 0xf103\n"
1304+"3:\n"
1305+#endif
1306+
1307+" strexd %1, %0, %H0, [%3]\n"
1308+" teq %1, #0\n"
1309+" bne 1b"
1310+
1311+#ifdef CONFIG_PAX_REFCOUNT
1312+"\n4:\n"
1313+ _ASM_EXTABLE(2b, 4b)
1314+#endif
1315+
1316+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1317+ : "r" (&v->counter), "r" (i)
1318+ : "cc");
1319+
1320+ smp_mb();
1321+
1322+ return result;
1323+}
1324+
1325+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1326+{
1327+ long long result;
1328+ unsigned long tmp;
1329+
1330+ smp_mb();
1331+
1332+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1333+"1: ldrexd %0, %H0, [%3]\n"
1334+" adds %Q0, %Q0, %Q4\n"
1335 " adc %R0, %R0, %R4\n"
1336 " strexd %1, %0, %H0, [%3]\n"
1337 " teq %1, #0\n"
1338@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1339 __asm__ __volatile__("@ atomic64_sub\n"
1340 "1: ldrexd %0, %H0, [%3]\n"
1341 " subs %Q0, %Q0, %Q4\n"
1342+" sbcs %R0, %R0, %R4\n"
1343+
1344+#ifdef CONFIG_PAX_REFCOUNT
1345+" bvc 3f\n"
1346+"2: bkpt 0xf103\n"
1347+"3:\n"
1348+#endif
1349+
1350+" strexd %1, %0, %H0, [%3]\n"
1351+" teq %1, #0\n"
1352+" bne 1b"
1353+
1354+#ifdef CONFIG_PAX_REFCOUNT
1355+"\n4:\n"
1356+ _ASM_EXTABLE(2b, 4b)
1357+#endif
1358+
1359+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1360+ : "r" (&v->counter), "r" (i)
1361+ : "cc");
1362+}
1363+
1364+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1365+{
1366+ long long result;
1367+ unsigned long tmp;
1368+
1369+ prefetchw(&v->counter);
1370+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1371+"1: ldrexd %0, %H0, [%3]\n"
1372+" subs %Q0, %Q0, %Q4\n"
1373 " sbc %R0, %R0, %R4\n"
1374 " strexd %1, %0, %H0, [%3]\n"
1375 " teq %1, #0\n"
1376@@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1377 __asm__ __volatile__("@ atomic64_sub_return\n"
1378 "1: ldrexd %0, %H0, [%3]\n"
1379 " subs %Q0, %Q0, %Q4\n"
1380-" sbc %R0, %R0, %R4\n"
1381+" sbcs %R0, %R0, %R4\n"
1382+
1383+#ifdef CONFIG_PAX_REFCOUNT
1384+" bvc 3f\n"
1385+" mov %0, %1\n"
1386+" mov %H0, %H1\n"
1387+"2: bkpt 0xf103\n"
1388+"3:\n"
1389+#endif
1390+
1391 " strexd %1, %0, %H0, [%3]\n"
1392 " teq %1, #0\n"
1393 " bne 1b"
1394+
1395+#ifdef CONFIG_PAX_REFCOUNT
1396+"\n4:\n"
1397+ _ASM_EXTABLE(2b, 4b)
1398+#endif
1399+
1400 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1401 : "r" (&v->counter), "r" (i)
1402 : "cc");
1403
1404- smp_mb();
1405-
1406 return result;
1407 }
1408
1409@@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1410 return oldval;
1411 }
1412
1413+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1414+ long long new)
1415+{
1416+ long long oldval;
1417+ unsigned long res;
1418+
1419+ smp_mb();
1420+
1421+ do {
1422+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1423+ "ldrexd %1, %H1, [%3]\n"
1424+ "mov %0, #0\n"
1425+ "teq %1, %4\n"
1426+ "teqeq %H1, %H4\n"
1427+ "strexdeq %0, %5, %H5, [%3]"
1428+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1429+ : "r" (&ptr->counter), "r" (old), "r" (new)
1430+ : "cc");
1431+ } while (res);
1432+
1433+ smp_mb();
1434+
1435+ return oldval;
1436+}
1437+
1438 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1439 {
1440 long long result;
1441@@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1443 {
1444 long long result;
1445- unsigned long tmp;
1446+ u64 tmp;
1447
1448 smp_mb();
1449
1450 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1451-"1: ldrexd %0, %H0, [%3]\n"
1452-" subs %Q0, %Q0, #1\n"
1453-" sbc %R0, %R0, #0\n"
1454+"1: ldrexd %1, %H1, [%3]\n"
1455+" subs %Q0, %Q1, #1\n"
1456+" sbcs %R0, %R1, #0\n"
1457+
1458+#ifdef CONFIG_PAX_REFCOUNT
1459+" bvc 3f\n"
1460+" mov %Q0, %Q1\n"
1461+" mov %R0, %R1\n"
1462+"2: bkpt 0xf103\n"
1463+"3:\n"
1464+#endif
1465+
1466 " teq %R0, #0\n"
1467-" bmi 2f\n"
1468+" bmi 4f\n"
1469 " strexd %1, %0, %H0, [%3]\n"
1470 " teq %1, #0\n"
1471 " bne 1b\n"
1472-"2:"
1473+"4:\n"
1474+
1475+#ifdef CONFIG_PAX_REFCOUNT
1476+ _ASM_EXTABLE(2b, 4b)
1477+#endif
1478+
1479 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1480 : "r" (&v->counter)
1481 : "cc");
1482@@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1483 " teq %0, %5\n"
1484 " teqeq %H0, %H5\n"
1485 " moveq %1, #0\n"
1486-" beq 2f\n"
1487+" beq 4f\n"
1488 " adds %Q0, %Q0, %Q6\n"
1489-" adc %R0, %R0, %R6\n"
1490+" adcs %R0, %R0, %R6\n"
1491+
1492+#ifdef CONFIG_PAX_REFCOUNT
1493+" bvc 3f\n"
1494+"2: bkpt 0xf103\n"
1495+"3:\n"
1496+#endif
1497+
1498 " strexd %2, %0, %H0, [%4]\n"
1499 " teq %2, #0\n"
1500 " bne 1b\n"
1501-"2:"
1502+"4:\n"
1503+
1504+#ifdef CONFIG_PAX_REFCOUNT
1505+ _ASM_EXTABLE(2b, 4b)
1506+#endif
1507+
1508 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1509 : "r" (&v->counter), "r" (u), "r" (a)
1510 : "cc");
1511@@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1512
1513 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1514 #define atomic64_inc(v) atomic64_add(1LL, (v))
1515+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1516 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1517+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1518 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1519 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1520 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1521+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1522 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1523 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1525diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1526index 75fe66b..ba3dee4 100644
1527--- a/arch/arm/include/asm/cache.h
1528+++ b/arch/arm/include/asm/cache.h
1529@@ -4,8 +4,10 @@
1530 #ifndef __ASMARM_CACHE_H
1531 #define __ASMARM_CACHE_H
1532
1533+#include <linux/const.h>
1534+
1535 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1536-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1537+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1538
1539 /*
1540 * Memory returned by kmalloc() may be used for DMA, so we must make
1541@@ -24,5 +26,6 @@
1542 #endif
1543
1544 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1545+#define __read_only __attribute__ ((__section__(".data..read_only")))
1546
1547 #endif
1548diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1549index 8b8b616..d973d24 100644
1550--- a/arch/arm/include/asm/cacheflush.h
1551+++ b/arch/arm/include/asm/cacheflush.h
1552@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1553 void (*dma_unmap_area)(const void *, size_t, int);
1554
1555 void (*dma_flush_range)(const void *, const void *);
1556-};
1557+} __no_const;
1558
1559 /*
1560 * Select the calling method
1561diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1562index 5233151..87a71fa 100644
1563--- a/arch/arm/include/asm/checksum.h
1564+++ b/arch/arm/include/asm/checksum.h
1565@@ -37,7 +37,19 @@ __wsum
1566 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1567
1568 __wsum
1569-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1570+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1571+
1572+static inline __wsum
1573+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1574+{
1575+ __wsum ret;
1576+ pax_open_userland();
1577+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1578+ pax_close_userland();
1579+ return ret;
1580+}
1581+
1582+
1583
1584 /*
1585 * Fold a partial checksum without adding pseudo headers
1586diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1587index df2fbba..63fe3e1 100644
1588--- a/arch/arm/include/asm/cmpxchg.h
1589+++ b/arch/arm/include/asm/cmpxchg.h
1590@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1591
1592 #define xchg(ptr,x) \
1593 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1594+#define xchg_unchecked(ptr,x) \
1595+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596
1597 #include <asm-generic/cmpxchg-local.h>
1598
1599diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1600index 6ddbe44..b5e38b1 100644
1601--- a/arch/arm/include/asm/domain.h
1602+++ b/arch/arm/include/asm/domain.h
1603@@ -48,18 +48,37 @@
1604 * Domain types
1605 */
1606 #define DOMAIN_NOACCESS 0
1607-#define DOMAIN_CLIENT 1
1608 #ifdef CONFIG_CPU_USE_DOMAINS
1609+#define DOMAIN_USERCLIENT 1
1610+#define DOMAIN_KERNELCLIENT 1
1611 #define DOMAIN_MANAGER 3
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613 #else
1614+
1615+#ifdef CONFIG_PAX_KERNEXEC
1616 #define DOMAIN_MANAGER 1
1617+#define DOMAIN_KERNEXEC 3
1618+#else
1619+#define DOMAIN_MANAGER 1
1620+#endif
1621+
1622+#ifdef CONFIG_PAX_MEMORY_UDEREF
1623+#define DOMAIN_USERCLIENT 0
1624+#define DOMAIN_UDEREF 1
1625+#define DOMAIN_VECTORS DOMAIN_KERNEL
1626+#else
1627+#define DOMAIN_USERCLIENT 1
1628+#define DOMAIN_VECTORS DOMAIN_USER
1629+#endif
1630+#define DOMAIN_KERNELCLIENT 1
1631+
1632 #endif
1633
1634 #define domain_val(dom,type) ((type) << (2*(dom)))
1635
1636 #ifndef __ASSEMBLY__
1637
1638-#ifdef CONFIG_CPU_USE_DOMAINS
1639+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1640 static inline void set_domain(unsigned val)
1641 {
1642 asm volatile(
1643@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1644 isb();
1645 }
1646
1647-#define modify_domain(dom,type) \
1648- do { \
1649- struct thread_info *thread = current_thread_info(); \
1650- unsigned int domain = thread->cpu_domain; \
1651- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1652- thread->cpu_domain = domain | domain_val(dom, type); \
1653- set_domain(thread->cpu_domain); \
1654- } while (0)
1655-
1656+extern void modify_domain(unsigned int dom, unsigned int type);
1657 #else
1658 static inline void set_domain(unsigned val) { }
1659 static inline void modify_domain(unsigned dom, unsigned type) { }
1660diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1661index f4b46d3..abc9b2b 100644
1662--- a/arch/arm/include/asm/elf.h
1663+++ b/arch/arm/include/asm/elf.h
1664@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 the loader. We need to make sure that it is out of the way of the program
1666 that it will "exec", and that there is sufficient room for the brk. */
1667
1668-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1669+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1670+
1671+#ifdef CONFIG_PAX_ASLR
1672+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1673+
1674+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1675+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1676+#endif
1677
1678 /* When the program starts, a1 contains a pointer to a function to be
1679 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1680@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1681 extern void elf_set_personality(const struct elf32_hdr *);
1682 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1683
1684-struct mm_struct;
1685-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1686-#define arch_randomize_brk arch_randomize_brk
1687-
1688 #ifdef CONFIG_MMU
1689 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1690 struct linux_binprm;
1691diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1692index de53547..52b9a28 100644
1693--- a/arch/arm/include/asm/fncpy.h
1694+++ b/arch/arm/include/asm/fncpy.h
1695@@ -81,7 +81,9 @@
1696 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1697 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1698 \
1699+ pax_open_kernel(); \
1700 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1701+ pax_close_kernel(); \
1702 flush_icache_range((unsigned long)(dest_buf), \
1703 (unsigned long)(dest_buf) + (size)); \
1704 \
1705diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1706index 2aff798..099eb15 100644
1707--- a/arch/arm/include/asm/futex.h
1708+++ b/arch/arm/include/asm/futex.h
1709@@ -45,6 +45,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1710 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1711 return -EFAULT;
1712
1713+ pax_open_userland();
1714+
1715 smp_mb();
1716 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1717 "1: ldrex %1, [%4]\n"
1718@@ -60,6 +62,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1719 : "cc", "memory");
1720 smp_mb();
1721
1722+ pax_close_userland();
1723+
1724 *uval = val;
1725 return ret;
1726 }
1727@@ -90,6 +94,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1728 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1729 return -EFAULT;
1730
1731+ pax_open_userland();
1732+
1733 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1734 "1: " TUSER(ldr) " %1, [%4]\n"
1735 " teq %1, %2\n"
1736@@ -100,6 +106,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1737 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1738 : "cc", "memory");
1739
1740+ pax_close_userland();
1741+
1742 *uval = val;
1743 return ret;
1744 }
1745@@ -122,6 +130,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 return -EFAULT;
1747
1748 pagefault_disable(); /* implies preempt_disable() */
1749+ pax_open_userland();
1750
1751 switch (op) {
1752 case FUTEX_OP_SET:
1753@@ -143,6 +152,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1754 ret = -ENOSYS;
1755 }
1756
1757+ pax_close_userland();
1758 pagefault_enable(); /* subsumes preempt_enable() */
1759
1760 if (!ret) {
1761diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1762index 83eb2f7..ed77159 100644
1763--- a/arch/arm/include/asm/kmap_types.h
1764+++ b/arch/arm/include/asm/kmap_types.h
1765@@ -4,6 +4,6 @@
1766 /*
1767 * This is the "bare minimum". AIO seems to require this.
1768 */
1769-#define KM_TYPE_NR 16
1770+#define KM_TYPE_NR 17
1771
1772 #endif
1773diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1774index 9e614a1..3302cca 100644
1775--- a/arch/arm/include/asm/mach/dma.h
1776+++ b/arch/arm/include/asm/mach/dma.h
1777@@ -22,7 +22,7 @@ struct dma_ops {
1778 int (*residue)(unsigned int, dma_t *); /* optional */
1779 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1780 const char *type;
1781-};
1782+} __do_const;
1783
1784 struct dma_struct {
1785 void *addr; /* single DMA address */
1786diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1787index f98c7f3..e5c626d 100644
1788--- a/arch/arm/include/asm/mach/map.h
1789+++ b/arch/arm/include/asm/mach/map.h
1790@@ -23,17 +23,19 @@ struct map_desc {
1791
1792 /* types 0-3 are defined in asm/io.h */
1793 enum {
1794- MT_UNCACHED = 4,
1795- MT_CACHECLEAN,
1796- MT_MINICLEAN,
1797+ MT_UNCACHED_RW = 4,
1798+ MT_CACHECLEAN_RO,
1799+ MT_MINICLEAN_RO,
1800 MT_LOW_VECTORS,
1801 MT_HIGH_VECTORS,
1802- MT_MEMORY_RWX,
1803+ __MT_MEMORY_RWX,
1804 MT_MEMORY_RW,
1805- MT_ROM,
1806- MT_MEMORY_RWX_NONCACHED,
1807+ MT_MEMORY_RX,
1808+ MT_ROM_RX,
1809+ MT_MEMORY_RW_NONCACHED,
1810+ MT_MEMORY_RX_NONCACHED,
1811 MT_MEMORY_RW_DTCM,
1812- MT_MEMORY_RWX_ITCM,
1813+ MT_MEMORY_RX_ITCM,
1814 MT_MEMORY_RW_SO,
1815 MT_MEMORY_DMA_READY,
1816 };
1817diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1818index f94784f..9a09a4a 100644
1819--- a/arch/arm/include/asm/outercache.h
1820+++ b/arch/arm/include/asm/outercache.h
1821@@ -35,7 +35,7 @@ struct outer_cache_fns {
1822 #endif
1823 void (*set_debug)(unsigned long);
1824 void (*resume)(void);
1825-};
1826+} __no_const;
1827
1828 extern struct outer_cache_fns outer_cache;
1829
1830diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1831index 4355f0e..cd9168e 100644
1832--- a/arch/arm/include/asm/page.h
1833+++ b/arch/arm/include/asm/page.h
1834@@ -23,6 +23,7 @@
1835
1836 #else
1837
1838+#include <linux/compiler.h>
1839 #include <asm/glue.h>
1840
1841 /*
1842@@ -114,7 +115,7 @@ struct cpu_user_fns {
1843 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1844 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1845 unsigned long vaddr, struct vm_area_struct *vma);
1846-};
1847+} __no_const;
1848
1849 #ifdef MULTI_USER
1850 extern struct cpu_user_fns cpu_user;
1851diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1852index 78a7793..e3dc06c 100644
1853--- a/arch/arm/include/asm/pgalloc.h
1854+++ b/arch/arm/include/asm/pgalloc.h
1855@@ -17,6 +17,7 @@
1856 #include <asm/processor.h>
1857 #include <asm/cacheflush.h>
1858 #include <asm/tlbflush.h>
1859+#include <asm/system_info.h>
1860
1861 #define check_pgt_cache() do { } while (0)
1862
1863@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1864 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1865 }
1866
1867+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1868+{
1869+ pud_populate(mm, pud, pmd);
1870+}
1871+
1872 #else /* !CONFIG_ARM_LPAE */
1873
1874 /*
1875@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1876 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1877 #define pmd_free(mm, pmd) do { } while (0)
1878 #define pud_populate(mm,pmd,pte) BUG()
1879+#define pud_populate_kernel(mm,pmd,pte) BUG()
1880
1881 #endif /* CONFIG_ARM_LPAE */
1882
1883@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1884 __free_page(pte);
1885 }
1886
1887+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1888+{
1889+#ifdef CONFIG_ARM_LPAE
1890+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1891+#else
1892+ if (addr & SECTION_SIZE)
1893+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1894+ else
1895+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1896+#endif
1897+ flush_pmd_entry(pmdp);
1898+}
1899+
1900 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1901 pmdval_t prot)
1902 {
1903@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1904 static inline void
1905 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1906 {
1907- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1908+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1909 }
1910 #define pmd_pgtable(pmd) pmd_page(pmd)
1911
1912diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1913index 5cfba15..f415e1a 100644
1914--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1915+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1916@@ -20,12 +20,15 @@
1917 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1918 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1919 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1920+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1921 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1922 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1923 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1924+
1925 /*
1926 * - section
1927 */
1928+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1929 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1930 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1931 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1932@@ -37,6 +40,7 @@
1933 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1934 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1935 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1936+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1937
1938 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1939 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1940@@ -66,6 +70,7 @@
1941 * - extended small page/tiny page
1942 */
1943 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1944+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1945 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1946 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1947 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1948diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1949index 219ac88..73ec32a 100644
1950--- a/arch/arm/include/asm/pgtable-2level.h
1951+++ b/arch/arm/include/asm/pgtable-2level.h
1952@@ -126,6 +126,9 @@
1953 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1954 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1955
1956+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1957+#define L_PTE_PXN (_AT(pteval_t, 0))
1958+
1959 /*
1960 * These are the memory types, defined to be compatible with
1961 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1962diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1963index 626989f..9d67a33 100644
1964--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1965+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1966@@ -75,6 +75,7 @@
1967 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1968 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1969 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1970+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1971 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1972
1973 /*
1974diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1975index 85c60ad..b0bbd7e 100644
1976--- a/arch/arm/include/asm/pgtable-3level.h
1977+++ b/arch/arm/include/asm/pgtable-3level.h
1978@@ -82,6 +82,7 @@
1979 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1980 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1981 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1982+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1983 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1984 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1985 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1986@@ -95,6 +96,7 @@
1987 /*
1988 * To be used in assembly code with the upper page attributes.
1989 */
1990+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1991 #define L_PTE_XN_HIGH (1 << (54 - 32))
1992 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1993
1994diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1995index 7d59b52..27a12f8 100644
1996--- a/arch/arm/include/asm/pgtable.h
1997+++ b/arch/arm/include/asm/pgtable.h
1998@@ -33,6 +33,9 @@
1999 #include <asm/pgtable-2level.h>
2000 #endif
2001
2002+#define ktla_ktva(addr) (addr)
2003+#define ktva_ktla(addr) (addr)
2004+
2005 /*
2006 * Just any arbitrary offset to the start of the vmalloc VM area: the
2007 * current 8MB value just means that there will be a 8MB "hole" after the
2008@@ -48,6 +51,9 @@
2009 #define LIBRARY_TEXT_START 0x0c000000
2010
2011 #ifndef __ASSEMBLY__
2012+extern pteval_t __supported_pte_mask;
2013+extern pmdval_t __supported_pmd_mask;
2014+
2015 extern void __pte_error(const char *file, int line, pte_t);
2016 extern void __pmd_error(const char *file, int line, pmd_t);
2017 extern void __pgd_error(const char *file, int line, pgd_t);
2018@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2019 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2020 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2021
2022+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2023+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2024+
2025+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2026+#include <asm/domain.h>
2027+#include <linux/thread_info.h>
2028+#include <linux/preempt.h>
2029+
2030+static inline int test_domain(int domain, int domaintype)
2031+{
2032+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2033+}
2034+#endif
2035+
2036+#ifdef CONFIG_PAX_KERNEXEC
2037+static inline unsigned long pax_open_kernel(void) {
2038+#ifdef CONFIG_ARM_LPAE
2039+ /* TODO */
2040+#else
2041+ preempt_disable();
2042+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2043+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2044+#endif
2045+ return 0;
2046+}
2047+
2048+static inline unsigned long pax_close_kernel(void) {
2049+#ifdef CONFIG_ARM_LPAE
2050+ /* TODO */
2051+#else
2052+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2053+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2054+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2055+ preempt_enable_no_resched();
2056+#endif
2057+ return 0;
2058+}
2059+#else
2060+static inline unsigned long pax_open_kernel(void) { return 0; }
2061+static inline unsigned long pax_close_kernel(void) { return 0; }
2062+#endif
2063+
2064 /*
2065 * This is the lowest virtual address we can permit any user space
2066 * mapping to be mapped at. This is particularly important for
2067@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2068 /*
2069 * The pgprot_* and protection_map entries will be fixed up in runtime
2070 * to include the cachable and bufferable bits based on memory policy,
2071- * as well as any architecture dependent bits like global/ASID and SMP
2072- * shared mapping bits.
2073+ * as well as any architecture dependent bits like global/ASID, PXN,
2074+ * and SMP shared mapping bits.
2075 */
2076 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2077
2078@@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2079 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2080 {
2081 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2082- L_PTE_NONE | L_PTE_VALID;
2083+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2084 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2085 return pte;
2086 }
2087diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2088index c4ae171..ea0c0c2 100644
2089--- a/arch/arm/include/asm/psci.h
2090+++ b/arch/arm/include/asm/psci.h
2091@@ -29,7 +29,7 @@ struct psci_operations {
2092 int (*cpu_off)(struct psci_power_state state);
2093 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2094 int (*migrate)(unsigned long cpuid);
2095-};
2096+} __no_const;
2097
2098 extern struct psci_operations psci_ops;
2099 extern struct smp_operations psci_smp_ops;
2100diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2101index 22a3b9b..7f214ee 100644
2102--- a/arch/arm/include/asm/smp.h
2103+++ b/arch/arm/include/asm/smp.h
2104@@ -112,7 +112,7 @@ struct smp_operations {
2105 int (*cpu_disable)(unsigned int cpu);
2106 #endif
2107 #endif
2108-};
2109+} __no_const;
2110
2111 /*
2112 * set platform specific SMP operations
2113diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2114index 71a06b2..8bb9ae1 100644
2115--- a/arch/arm/include/asm/thread_info.h
2116+++ b/arch/arm/include/asm/thread_info.h
2117@@ -88,9 +88,9 @@ struct thread_info {
2118 .flags = 0, \
2119 .preempt_count = INIT_PREEMPT_COUNT, \
2120 .addr_limit = KERNEL_DS, \
2121- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2122- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2123- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2124+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2125+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2126+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2127 .restart_block = { \
2128 .fn = do_no_restart_syscall, \
2129 }, \
2130@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2131 #define TIF_SYSCALL_AUDIT 9
2132 #define TIF_SYSCALL_TRACEPOINT 10
2133 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2134-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2135+/* within 8 bits of TIF_SYSCALL_TRACE
2136+ * to meet flexible second operand requirements
2137+ */
2138+#define TIF_GRSEC_SETXID 12
2139+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2140 #define TIF_USING_IWMMXT 17
2141 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2142 #define TIF_RESTORE_SIGMASK 20
2143@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2144 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2145 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2146 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2147+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2148
2149 /* Checks for any syscall work in entry-common.S */
2150 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2151- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2152+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2153
2154 /*
2155 * Change these and you break ASM code in entry-common.S
2156diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2157index 72abdc5..35acac1 100644
2158--- a/arch/arm/include/asm/uaccess.h
2159+++ b/arch/arm/include/asm/uaccess.h
2160@@ -18,6 +18,7 @@
2161 #include <asm/domain.h>
2162 #include <asm/unified.h>
2163 #include <asm/compiler.h>
2164+#include <asm/pgtable.h>
2165
2166 #if __LINUX_ARM_ARCH__ < 6
2167 #include <asm-generic/uaccess-unaligned.h>
2168@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2169 static inline void set_fs(mm_segment_t fs)
2170 {
2171 current_thread_info()->addr_limit = fs;
2172- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2173+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2174 }
2175
2176 #define segment_eq(a,b) ((a) == (b))
2177
2178+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2179+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2180+
2181+static inline void pax_open_userland(void)
2182+{
2183+
2184+#ifdef CONFIG_PAX_MEMORY_UDEREF
2185+ if (segment_eq(get_fs(), USER_DS)) {
2186+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2187+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2188+ }
2189+#endif
2190+
2191+}
2192+
2193+static inline void pax_close_userland(void)
2194+{
2195+
2196+#ifdef CONFIG_PAX_MEMORY_UDEREF
2197+ if (segment_eq(get_fs(), USER_DS)) {
2198+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2199+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2200+ }
2201+#endif
2202+
2203+}
2204+
2205 #define __addr_ok(addr) ({ \
2206 unsigned long flag; \
2207 __asm__("cmp %2, %0; movlo %0, #0" \
2208@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2209
2210 #define get_user(x,p) \
2211 ({ \
2212+ int __e; \
2213 might_fault(); \
2214- __get_user_check(x,p); \
2215+ pax_open_userland(); \
2216+ __e = __get_user_check(x,p); \
2217+ pax_close_userland(); \
2218+ __e; \
2219 })
2220
2221 extern int __put_user_1(void *, unsigned int);
2222@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2223
2224 #define put_user(x,p) \
2225 ({ \
2226+ int __e; \
2227 might_fault(); \
2228- __put_user_check(x,p); \
2229+ pax_open_userland(); \
2230+ __e = __put_user_check(x,p); \
2231+ pax_close_userland(); \
2232+ __e; \
2233 })
2234
2235 #else /* CONFIG_MMU */
2236@@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2237
2238 #endif /* CONFIG_MMU */
2239
2240+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2241 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2242
2243 #define user_addr_max() \
2244@@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2245 #define __get_user(x,ptr) \
2246 ({ \
2247 long __gu_err = 0; \
2248+ pax_open_userland(); \
2249 __get_user_err((x),(ptr),__gu_err); \
2250+ pax_close_userland(); \
2251 __gu_err; \
2252 })
2253
2254 #define __get_user_error(x,ptr,err) \
2255 ({ \
2256+ pax_open_userland(); \
2257 __get_user_err((x),(ptr),err); \
2258+ pax_close_userland(); \
2259 (void) 0; \
2260 })
2261
2262@@ -319,13 +360,17 @@ do { \
2263 #define __put_user(x,ptr) \
2264 ({ \
2265 long __pu_err = 0; \
2266+ pax_open_userland(); \
2267 __put_user_err((x),(ptr),__pu_err); \
2268+ pax_close_userland(); \
2269 __pu_err; \
2270 })
2271
2272 #define __put_user_error(x,ptr,err) \
2273 ({ \
2274+ pax_open_userland(); \
2275 __put_user_err((x),(ptr),err); \
2276+ pax_close_userland(); \
2277 (void) 0; \
2278 })
2279
2280@@ -425,11 +470,44 @@ do { \
2281
2282
2283 #ifdef CONFIG_MMU
2284-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2285-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2286+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2287+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2288+
2289+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+
2293+ check_object_size(to, n, false);
2294+ pax_open_userland();
2295+ ret = ___copy_from_user(to, from, n);
2296+ pax_close_userland();
2297+ return ret;
2298+}
2299+
2300+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2301+{
2302+ unsigned long ret;
2303+
2304+ check_object_size(from, n, true);
2305+ pax_open_userland();
2306+ ret = ___copy_to_user(to, from, n);
2307+ pax_close_userland();
2308+ return ret;
2309+}
2310+
2311 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2312-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2313+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2314 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2315+
2316+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2317+{
2318+ unsigned long ret;
2319+ pax_open_userland();
2320+ ret = ___clear_user(addr, n);
2321+ pax_close_userland();
2322+ return ret;
2323+}
2324+
2325 #else
2326 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2327 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2328@@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2329
2330 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2331 {
2332+ if ((long)n < 0)
2333+ return n;
2334+
2335 if (access_ok(VERIFY_READ, from, n))
2336 n = __copy_from_user(to, from, n);
2337 else /* security hole - plug it */
2338@@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2339
2340 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2341 {
2342+ if ((long)n < 0)
2343+ return n;
2344+
2345 if (access_ok(VERIFY_WRITE, to, n))
2346 n = __copy_to_user(to, from, n);
2347 return n;
2348diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2349index 5af0ed1..cea83883 100644
2350--- a/arch/arm/include/uapi/asm/ptrace.h
2351+++ b/arch/arm/include/uapi/asm/ptrace.h
2352@@ -92,7 +92,7 @@
2353 * ARMv7 groups of PSR bits
2354 */
2355 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2356-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2357+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2358 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2359 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2360
2361diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2362index 85e664b..419a1cd 100644
2363--- a/arch/arm/kernel/armksyms.c
2364+++ b/arch/arm/kernel/armksyms.c
2365@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2366
2367 /* networking */
2368 EXPORT_SYMBOL(csum_partial);
2369-EXPORT_SYMBOL(csum_partial_copy_from_user);
2370+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2371 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2372 EXPORT_SYMBOL(__csum_ipv6_magic);
2373
2374@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2375 #ifdef CONFIG_MMU
2376 EXPORT_SYMBOL(copy_page);
2377
2378-EXPORT_SYMBOL(__copy_from_user);
2379-EXPORT_SYMBOL(__copy_to_user);
2380-EXPORT_SYMBOL(__clear_user);
2381+EXPORT_SYMBOL(___copy_from_user);
2382+EXPORT_SYMBOL(___copy_to_user);
2383+EXPORT_SYMBOL(___clear_user);
2384
2385 EXPORT_SYMBOL(__get_user_1);
2386 EXPORT_SYMBOL(__get_user_2);
2387diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2388index 1879e8d..b2207fc 100644
2389--- a/arch/arm/kernel/entry-armv.S
2390+++ b/arch/arm/kernel/entry-armv.S
2391@@ -47,6 +47,87 @@
2392 9997:
2393 .endm
2394
2395+ .macro pax_enter_kernel
2396+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2397+ @ make aligned space for saved DACR
2398+ sub sp, sp, #8
2399+ @ save regs
2400+ stmdb sp!, {r1, r2}
2401+ @ read DACR from cpu_domain into r1
2402+ mov r2, sp
2403+ @ assume 8K pages, since we have to split the immediate in two
2404+ bic r2, r2, #(0x1fc0)
2405+ bic r2, r2, #(0x3f)
2406+ ldr r1, [r2, #TI_CPU_DOMAIN]
2407+ @ store old DACR on stack
2408+ str r1, [sp, #8]
2409+#ifdef CONFIG_PAX_KERNEXEC
2410+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2411+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2412+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2413+#endif
2414+#ifdef CONFIG_PAX_MEMORY_UDEREF
2415+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2416+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2417+#endif
2418+ @ write r1 to current_thread_info()->cpu_domain
2419+ str r1, [r2, #TI_CPU_DOMAIN]
2420+ @ write r1 to DACR
2421+ mcr p15, 0, r1, c3, c0, 0
2422+ @ instruction sync
2423+ instr_sync
2424+ @ restore regs
2425+ ldmia sp!, {r1, r2}
2426+#endif
2427+ .endm
2428+
2429+ .macro pax_open_userland
2430+#ifdef CONFIG_PAX_MEMORY_UDEREF
2431+ @ save regs
2432+ stmdb sp!, {r0, r1}
2433+ @ read DACR from cpu_domain into r1
2434+ mov r0, sp
2435+ @ assume 8K pages, since we have to split the immediate in two
2436+ bic r0, r0, #(0x1fc0)
2437+ bic r0, r0, #(0x3f)
2438+ ldr r1, [r0, #TI_CPU_DOMAIN]
2439+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2440+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2441+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2442+ @ write r1 to current_thread_info()->cpu_domain
2443+ str r1, [r0, #TI_CPU_DOMAIN]
2444+ @ write r1 to DACR
2445+ mcr p15, 0, r1, c3, c0, 0
2446+ @ instruction sync
2447+ instr_sync
2448+ @ restore regs
2449+ ldmia sp!, {r0, r1}
2450+#endif
2451+ .endm
2452+
2453+ .macro pax_close_userland
2454+#ifdef CONFIG_PAX_MEMORY_UDEREF
2455+ @ save regs
2456+ stmdb sp!, {r0, r1}
2457+ @ read DACR from cpu_domain into r1
2458+ mov r0, sp
2459+ @ assume 8K pages, since we have to split the immediate in two
2460+ bic r0, r0, #(0x1fc0)
2461+ bic r0, r0, #(0x3f)
2462+ ldr r1, [r0, #TI_CPU_DOMAIN]
2463+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2464+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2465+ @ write r1 to current_thread_info()->cpu_domain
2466+ str r1, [r0, #TI_CPU_DOMAIN]
2467+ @ write r1 to DACR
2468+ mcr p15, 0, r1, c3, c0, 0
2469+ @ instruction sync
2470+ instr_sync
2471+ @ restore regs
2472+ ldmia sp!, {r0, r1}
2473+#endif
2474+ .endm
2475+
2476 .macro pabt_helper
2477 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2478 #ifdef MULTI_PABORT
2479@@ -89,11 +170,15 @@
2480 * Invalid mode handlers
2481 */
2482 .macro inv_entry, reason
2483+
2484+ pax_enter_kernel
2485+
2486 sub sp, sp, #S_FRAME_SIZE
2487 ARM( stmib sp, {r1 - lr} )
2488 THUMB( stmia sp, {r0 - r12} )
2489 THUMB( str sp, [sp, #S_SP] )
2490 THUMB( str lr, [sp, #S_LR] )
2491+
2492 mov r1, #\reason
2493 .endm
2494
2495@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2496 .macro svc_entry, stack_hole=0
2497 UNWIND(.fnstart )
2498 UNWIND(.save {r0 - pc} )
2499+
2500+ pax_enter_kernel
2501+
2502 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2503+
2504 #ifdef CONFIG_THUMB2_KERNEL
2505 SPFIX( str r0, [sp] ) @ temporarily saved
2506 SPFIX( mov r0, sp )
2507@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2508 ldmia r0, {r3 - r5}
2509 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2510 mov r6, #-1 @ "" "" "" ""
2511+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2512+ @ offset sp by 8 as done in pax_enter_kernel
2513+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2514+#else
2515 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2516+#endif
2517 SPFIX( addeq r2, r2, #4 )
2518 str r3, [sp, #-4]! @ save the "real" r0 copied
2519 @ from the exception stack
2520@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2521 .macro usr_entry
2522 UNWIND(.fnstart )
2523 UNWIND(.cantunwind ) @ don't unwind the user space
2524+
2525+ pax_enter_kernel_user
2526+
2527 sub sp, sp, #S_FRAME_SIZE
2528 ARM( stmib sp, {r1 - r12} )
2529 THUMB( stmia sp, {r0 - r12} )
2530@@ -416,7 +513,9 @@ __und_usr:
2531 tst r3, #PSR_T_BIT @ Thumb mode?
2532 bne __und_usr_thumb
2533 sub r4, r2, #4 @ ARM instr at LR - 4
2534+ pax_open_userland
2535 1: ldrt r0, [r4]
2536+ pax_close_userland
2537 ARM_BE8(rev r0, r0) @ little endian instruction
2538
2539 @ r0 = 32-bit ARM instruction which caused the exception
2540@@ -450,11 +549,15 @@ __und_usr_thumb:
2541 */
2542 .arch armv6t2
2543 #endif
2544+ pax_open_userland
2545 2: ldrht r5, [r4]
2546+ pax_close_userland
2547 ARM_BE8(rev16 r5, r5) @ little endian instruction
2548 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2549 blo __und_usr_fault_16 @ 16bit undefined instruction
2550+ pax_open_userland
2551 3: ldrht r0, [r2]
2552+ pax_close_userland
2553 ARM_BE8(rev16 r0, r0) @ little endian instruction
2554 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2555 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2556@@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2557 */
2558 .pushsection .fixup, "ax"
2559 .align 2
2560-4: mov pc, r9
2561+4: pax_close_userland
2562+ mov pc, r9
2563 .popsection
2564 .pushsection __ex_table,"a"
2565 .long 1b, 4b
2566@@ -694,7 +798,7 @@ ENTRY(__switch_to)
2567 THUMB( str lr, [ip], #4 )
2568 ldr r4, [r2, #TI_TP_VALUE]
2569 ldr r5, [r2, #TI_TP_VALUE + 4]
2570-#ifdef CONFIG_CPU_USE_DOMAINS
2571+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2572 ldr r6, [r2, #TI_CPU_DOMAIN]
2573 #endif
2574 switch_tls r1, r4, r5, r3, r7
2575@@ -703,7 +807,7 @@ ENTRY(__switch_to)
2576 ldr r8, =__stack_chk_guard
2577 ldr r7, [r7, #TSK_STACK_CANARY]
2578 #endif
2579-#ifdef CONFIG_CPU_USE_DOMAINS
2580+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2581 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2582 #endif
2583 mov r5, r0
2584diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2585index a2dcafd..1048b5a 100644
2586--- a/arch/arm/kernel/entry-common.S
2587+++ b/arch/arm/kernel/entry-common.S
2588@@ -10,18 +10,46 @@
2589
2590 #include <asm/unistd.h>
2591 #include <asm/ftrace.h>
2592+#include <asm/domain.h>
2593 #include <asm/unwind.h>
2594
2595+#include "entry-header.S"
2596+
2597 #ifdef CONFIG_NEED_RET_TO_USER
2598 #include <mach/entry-macro.S>
2599 #else
2600 .macro arch_ret_to_user, tmp1, tmp2
2601+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2602+ @ save regs
2603+ stmdb sp!, {r1, r2}
2604+ @ read DACR from cpu_domain into r1
2605+ mov r2, sp
2606+ @ assume 8K pages, since we have to split the immediate in two
2607+ bic r2, r2, #(0x1fc0)
2608+ bic r2, r2, #(0x3f)
2609+ ldr r1, [r2, #TI_CPU_DOMAIN]
2610+#ifdef CONFIG_PAX_KERNEXEC
2611+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2612+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2613+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2614+#endif
2615+#ifdef CONFIG_PAX_MEMORY_UDEREF
2616+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2617+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2618+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2619+#endif
2620+ @ write r1 to current_thread_info()->cpu_domain
2621+ str r1, [r2, #TI_CPU_DOMAIN]
2622+ @ write r1 to DACR
2623+ mcr p15, 0, r1, c3, c0, 0
2624+ @ instruction sync
2625+ instr_sync
2626+ @ restore regs
2627+ ldmia sp!, {r1, r2}
2628+#endif
2629 .endm
2630 #endif
2631
2632-#include "entry-header.S"
2633-
2634-
2635 .align 5
2636 /*
2637 * This is the fast syscall return path. We do as little as
2638@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2639 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2640 #endif
2641
2642+ /*
2643+ * do this here to avoid a performance hit of wrapping the code above
2644+ * that directly dereferences userland to parse the SWI instruction
2645+ */
2646+ pax_enter_kernel_user
2647+
2648 adr tbl, sys_call_table @ load syscall table pointer
2649
2650 #if defined(CONFIG_OABI_COMPAT)
2651diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2652index 39f89fb..d612bd9 100644
2653--- a/arch/arm/kernel/entry-header.S
2654+++ b/arch/arm/kernel/entry-header.S
2655@@ -184,6 +184,60 @@
2656 msr cpsr_c, \rtemp @ switch back to the SVC mode
2657 .endm
2658
2659+ .macro pax_enter_kernel_user
2660+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2661+ @ save regs
2662+ stmdb sp!, {r0, r1}
2663+ @ read DACR from cpu_domain into r1
2664+ mov r0, sp
2665+ @ assume 8K pages, since we have to split the immediate in two
2666+ bic r0, r0, #(0x1fc0)
2667+ bic r0, r0, #(0x3f)
2668+ ldr r1, [r0, #TI_CPU_DOMAIN]
2669+#ifdef CONFIG_PAX_MEMORY_UDEREF
2670+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2671+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2672+#endif
2673+#ifdef CONFIG_PAX_KERNEXEC
2674+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2675+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2676+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2677+#endif
2678+ @ write r1 to current_thread_info()->cpu_domain
2679+ str r1, [r0, #TI_CPU_DOMAIN]
2680+ @ write r1 to DACR
2681+ mcr p15, 0, r1, c3, c0, 0
2682+ @ instruction sync
2683+ instr_sync
2684+ @ restore regs
2685+ ldmia sp!, {r0, r1}
2686+#endif
2687+ .endm
2688+
2689+ .macro pax_exit_kernel
2690+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2691+ @ save regs
2692+ stmdb sp!, {r0, r1}
2693+ @ read old DACR from stack into r1
2694+ ldr r1, [sp, #(8 + S_SP)]
2695+ sub r1, r1, #8
2696+ ldr r1, [r1]
2697+
2698+ @ write r1 to current_thread_info()->cpu_domain
2699+ mov r0, sp
2700+ @ assume 8K pages, since we have to split the immediate in two
2701+ bic r0, r0, #(0x1fc0)
2702+ bic r0, r0, #(0x3f)
2703+ str r1, [r0, #TI_CPU_DOMAIN]
2704+ @ write r1 to DACR
2705+ mcr p15, 0, r1, c3, c0, 0
2706+ @ instruction sync
2707+ instr_sync
2708+ @ restore regs
2709+ ldmia sp!, {r0, r1}
2710+#endif
2711+ .endm
2712+
2713 #ifndef CONFIG_THUMB2_KERNEL
2714 .macro svc_exit, rpsr, irq = 0
2715 .if \irq != 0
2716@@ -203,6 +257,9 @@
2717 blne trace_hardirqs_off
2718 #endif
2719 .endif
2720+
2721+ pax_exit_kernel
2722+
2723 msr spsr_cxsf, \rpsr
2724 #if defined(CONFIG_CPU_V6)
2725 ldr r0, [sp]
2726@@ -266,6 +323,9 @@
2727 blne trace_hardirqs_off
2728 #endif
2729 .endif
2730+
2731+ pax_exit_kernel
2732+
2733 ldr lr, [sp, #S_SP] @ top of the stack
2734 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2735 clrex @ clear the exclusive monitor
2736diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2737index 918875d..cd5fa27 100644
2738--- a/arch/arm/kernel/fiq.c
2739+++ b/arch/arm/kernel/fiq.c
2740@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2741 void *base = vectors_page;
2742 unsigned offset = FIQ_OFFSET;
2743
2744+ pax_open_kernel();
2745 memcpy(base + offset, start, length);
2746+ pax_close_kernel();
2747+
2748 if (!cache_is_vipt_nonaliasing())
2749 flush_icache_range((unsigned long)base + offset, offset +
2750 length);
2751diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2752index f5f381d..a6f36a1 100644
2753--- a/arch/arm/kernel/head.S
2754+++ b/arch/arm/kernel/head.S
2755@@ -437,7 +437,7 @@ __enable_mmu:
2756 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2757 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2758 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2759- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2760+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2761 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2762 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2763 #endif
2764diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2765index 45e4781..8eac93d 100644
2766--- a/arch/arm/kernel/module.c
2767+++ b/arch/arm/kernel/module.c
2768@@ -38,12 +38,39 @@
2769 #endif
2770
2771 #ifdef CONFIG_MMU
2772-void *module_alloc(unsigned long size)
2773+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2774 {
2775+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2776+ return NULL;
2777 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2778- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2779+ GFP_KERNEL, prot, NUMA_NO_NODE,
2780 __builtin_return_address(0));
2781 }
2782+
2783+void *module_alloc(unsigned long size)
2784+{
2785+
2786+#ifdef CONFIG_PAX_KERNEXEC
2787+ return __module_alloc(size, PAGE_KERNEL);
2788+#else
2789+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2790+#endif
2791+
2792+}
2793+
2794+#ifdef CONFIG_PAX_KERNEXEC
2795+void module_free_exec(struct module *mod, void *module_region)
2796+{
2797+ module_free(mod, module_region);
2798+}
2799+EXPORT_SYMBOL(module_free_exec);
2800+
2801+void *module_alloc_exec(unsigned long size)
2802+{
2803+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2804+}
2805+EXPORT_SYMBOL(module_alloc_exec);
2806+#endif
2807 #endif
2808
2809 int
2810diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2811index 07314af..c46655c 100644
2812--- a/arch/arm/kernel/patch.c
2813+++ b/arch/arm/kernel/patch.c
2814@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2816 int size;
2817
2818+ pax_open_kernel();
2819 if (thumb2 && __opcode_is_thumb16(insn)) {
2820 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2821 size = sizeof(u16);
2822@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2823 *(u32 *)addr = insn;
2824 size = sizeof(u32);
2825 }
2826+ pax_close_kernel();
2827
2828 flush_icache_range((uintptr_t)(addr),
2829 (uintptr_t)(addr) + size);
2830diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2831index 92f7b15..7048500 100644
2832--- a/arch/arm/kernel/process.c
2833+++ b/arch/arm/kernel/process.c
2834@@ -217,6 +217,7 @@ void machine_power_off(void)
2835
2836 if (pm_power_off)
2837 pm_power_off();
2838+ BUG();
2839 }
2840
2841 /*
2842@@ -230,7 +231,7 @@ void machine_power_off(void)
2843 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2844 * to use. Implementing such co-ordination would be essentially impossible.
2845 */
2846-void machine_restart(char *cmd)
2847+__noreturn void machine_restart(char *cmd)
2848 {
2849 local_irq_disable();
2850 smp_send_stop();
2851@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2852
2853 show_regs_print_info(KERN_DEFAULT);
2854
2855- print_symbol("PC is at %s\n", instruction_pointer(regs));
2856- print_symbol("LR is at %s\n", regs->ARM_lr);
2857+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2858+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2859 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2860 "sp : %08lx ip : %08lx fp : %08lx\n",
2861 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2862@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2863 return 0;
2864 }
2865
2866-unsigned long arch_randomize_brk(struct mm_struct *mm)
2867-{
2868- unsigned long range_end = mm->brk + 0x02000000;
2869- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2870-}
2871-
2872 #ifdef CONFIG_MMU
2873 #ifdef CONFIG_KUSER_HELPERS
2874 /*
2875@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2876
2877 static int __init gate_vma_init(void)
2878 {
2879- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2880+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2881 return 0;
2882 }
2883 arch_initcall(gate_vma_init);
2884@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2885
2886 const char *arch_vma_name(struct vm_area_struct *vma)
2887 {
2888- return is_gate_vma(vma) ? "[vectors]" :
2889- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2890- "[sigpage]" : NULL;
2891+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2892 }
2893
2894-static struct page *signal_page;
2895-extern struct page *get_signal_page(void);
2896-
2897 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2898 {
2899 struct mm_struct *mm = current->mm;
2900- unsigned long addr;
2901- int ret;
2902-
2903- if (!signal_page)
2904- signal_page = get_signal_page();
2905- if (!signal_page)
2906- return -ENOMEM;
2907
2908 down_write(&mm->mmap_sem);
2909- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2910- if (IS_ERR_VALUE(addr)) {
2911- ret = addr;
2912- goto up_fail;
2913- }
2914-
2915- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2916- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2917- &signal_page);
2918-
2919- if (ret == 0)
2920- mm->context.sigpage = addr;
2921-
2922- up_fail:
2923+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2924 up_write(&mm->mmap_sem);
2925- return ret;
2926+ return 0;
2927 }
2928 #endif
2929diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2930index 4693188..4596c5e 100644
2931--- a/arch/arm/kernel/psci.c
2932+++ b/arch/arm/kernel/psci.c
2933@@ -24,7 +24,7 @@
2934 #include <asm/opcodes-virt.h>
2935 #include <asm/psci.h>
2936
2937-struct psci_operations psci_ops;
2938+struct psci_operations psci_ops __read_only;
2939
2940 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2941
2942diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2943index 0dd3b79..e018f64 100644
2944--- a/arch/arm/kernel/ptrace.c
2945+++ b/arch/arm/kernel/ptrace.c
2946@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2947 return current_thread_info()->syscall;
2948 }
2949
2950+#ifdef CONFIG_GRKERNSEC_SETXID
2951+extern void gr_delayed_cred_worker(void);
2952+#endif
2953+
2954 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2955 {
2956 current_thread_info()->syscall = scno;
2957
2958+#ifdef CONFIG_GRKERNSEC_SETXID
2959+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2960+ gr_delayed_cred_worker();
2961+#endif
2962+
2963 /* Do the secure computing check first; failures should be fast. */
2964 if (secure_computing(scno) == -1)
2965 return -1;
2966diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2967index 1e8b030..37c3022 100644
2968--- a/arch/arm/kernel/setup.c
2969+++ b/arch/arm/kernel/setup.c
2970@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2971 unsigned int elf_hwcap __read_mostly;
2972 EXPORT_SYMBOL(elf_hwcap);
2973
2974+pteval_t __supported_pte_mask __read_only;
2975+pmdval_t __supported_pmd_mask __read_only;
2976
2977 #ifdef MULTI_CPU
2978-struct processor processor __read_mostly;
2979+struct processor processor __read_only;
2980 #endif
2981 #ifdef MULTI_TLB
2982-struct cpu_tlb_fns cpu_tlb __read_mostly;
2983+struct cpu_tlb_fns cpu_tlb __read_only;
2984 #endif
2985 #ifdef MULTI_USER
2986-struct cpu_user_fns cpu_user __read_mostly;
2987+struct cpu_user_fns cpu_user __read_only;
2988 #endif
2989 #ifdef MULTI_CACHE
2990-struct cpu_cache_fns cpu_cache __read_mostly;
2991+struct cpu_cache_fns cpu_cache __read_only;
2992 #endif
2993 #ifdef CONFIG_OUTER_CACHE
2994-struct outer_cache_fns outer_cache __read_mostly;
2995+struct outer_cache_fns outer_cache __read_only;
2996 EXPORT_SYMBOL(outer_cache);
2997 #endif
2998
2999@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3000 asm("mrc p15, 0, %0, c0, c1, 4"
3001 : "=r" (mmfr0));
3002 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3003- (mmfr0 & 0x000000f0) >= 0x00000030)
3004+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3005 cpu_arch = CPU_ARCH_ARMv7;
3006- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3007+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3008+ __supported_pte_mask |= L_PTE_PXN;
3009+ __supported_pmd_mask |= PMD_PXNTABLE;
3010+ }
3011+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3012 (mmfr0 & 0x000000f0) == 0x00000020)
3013 cpu_arch = CPU_ARCH_ARMv6;
3014 else
3015diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016index 04d6388..5115238 100644
3017--- a/arch/arm/kernel/signal.c
3018+++ b/arch/arm/kernel/signal.c
3019@@ -23,8 +23,6 @@
3020
3021 extern const unsigned long sigreturn_codes[7];
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@@ -395,8 +393,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@@ -600,33 +597,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 b7b4c86..47c4f77 100644
3074--- a/arch/arm/kernel/smp.c
3075+++ b/arch/arm/kernel/smp.c
3076@@ -73,7 +73,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/tcm.c b/arch/arm/kernel/tcm.c
3086index 7a3be1d..b00c7de 100644
3087--- a/arch/arm/kernel/tcm.c
3088+++ b/arch/arm/kernel/tcm.c
3089@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3090 .virtual = ITCM_OFFSET,
3091 .pfn = __phys_to_pfn(ITCM_OFFSET),
3092 .length = 0,
3093- .type = MT_MEMORY_RWX_ITCM,
3094+ .type = MT_MEMORY_RX_ITCM,
3095 }
3096 };
3097
3098@@ -267,7 +267,9 @@ no_dtcm:
3099 start = &__sitcm_text;
3100 end = &__eitcm_text;
3101 ram = &__itcm_start;
3102+ pax_open_kernel();
3103 memcpy(start, ram, itcm_code_sz);
3104+ pax_close_kernel();
3105 pr_debug("CPU ITCM: copied code from %p - %p\n",
3106 start, end);
3107 itcm_present = true;
3108diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3109index 172ee18..ce4ec3d 100644
3110--- a/arch/arm/kernel/traps.c
3111+++ b/arch/arm/kernel/traps.c
3112@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3113 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3114 {
3115 #ifdef CONFIG_KALLSYMS
3116- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3117+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3118 #else
3119 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3120 #endif
3121@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3122 static int die_owner = -1;
3123 static unsigned int die_nest_count;
3124
3125+extern void gr_handle_kernel_exploit(void);
3126+
3127 static unsigned long oops_begin(void)
3128 {
3129 int cpu;
3130@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3131 panic("Fatal exception in interrupt");
3132 if (panic_on_oops)
3133 panic("Fatal exception");
3134+
3135+ gr_handle_kernel_exploit();
3136+
3137 if (signr)
3138 do_exit(signr);
3139 }
3140@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3141 * The user helper at 0xffff0fe0 must be used instead.
3142 * (see entry-armv.S for details)
3143 */
3144+ pax_open_kernel();
3145 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3146+ pax_close_kernel();
3147 }
3148 return 0;
3149
3150@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3151 kuser_init(vectors_base);
3152
3153 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3154- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3155+
3156+#ifndef CONFIG_PAX_MEMORY_UDEREF
3157+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3158+#endif
3159+
3160 #else /* ifndef CONFIG_CPU_V7M */
3161 /*
3162 * on V7-M there is no need to copy the vector table to a dedicated
3163diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3164index 7bcee5c..e2f3249 100644
3165--- a/arch/arm/kernel/vmlinux.lds.S
3166+++ b/arch/arm/kernel/vmlinux.lds.S
3167@@ -8,7 +8,11 @@
3168 #include <asm/thread_info.h>
3169 #include <asm/memory.h>
3170 #include <asm/page.h>
3171-
3172+
3173+#ifdef CONFIG_PAX_KERNEXEC
3174+#include <asm/pgtable.h>
3175+#endif
3176+
3177 #define PROC_INFO \
3178 . = ALIGN(4); \
3179 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3180@@ -34,7 +38,7 @@
3181 #endif
3182
3183 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3184- defined(CONFIG_GENERIC_BUG)
3185+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3186 #define ARM_EXIT_KEEP(x) x
3187 #define ARM_EXIT_DISCARD(x)
3188 #else
3189@@ -90,6 +94,11 @@ SECTIONS
3190 _text = .;
3191 HEAD_TEXT
3192 }
3193+
3194+#ifdef CONFIG_PAX_KERNEXEC
3195+ . = ALIGN(1<<SECTION_SHIFT);
3196+#endif
3197+
3198 .text : { /* Real text segment */
3199 _stext = .; /* Text and read-only data */
3200 __exception_text_start = .;
3201@@ -112,6 +121,8 @@ SECTIONS
3202 ARM_CPU_KEEP(PROC_INFO)
3203 }
3204
3205+ _etext = .; /* End of text section */
3206+
3207 RO_DATA(PAGE_SIZE)
3208
3209 . = ALIGN(4);
3210@@ -142,7 +153,9 @@ SECTIONS
3211
3212 NOTES
3213
3214- _etext = .; /* End of text and rodata section */
3215+#ifdef CONFIG_PAX_KERNEXEC
3216+ . = ALIGN(1<<SECTION_SHIFT);
3217+#endif
3218
3219 #ifndef CONFIG_XIP_KERNEL
3220 . = ALIGN(PAGE_SIZE);
3221@@ -220,6 +233,11 @@ SECTIONS
3222 . = PAGE_OFFSET + TEXT_OFFSET;
3223 #else
3224 __init_end = .;
3225+
3226+#ifdef CONFIG_PAX_KERNEXEC
3227+ . = ALIGN(1<<SECTION_SHIFT);
3228+#endif
3229+
3230 . = ALIGN(THREAD_SIZE);
3231 __data_loc = .;
3232 #endif
3233diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3234index bd18bb8..87ede26 100644
3235--- a/arch/arm/kvm/arm.c
3236+++ b/arch/arm/kvm/arm.c
3237@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3238 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3239
3240 /* The VMID used in the VTTBR */
3241-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3242+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3243 static u8 kvm_next_vmid;
3244 static DEFINE_SPINLOCK(kvm_vmid_lock);
3245
3246@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3247 */
3248 static bool need_new_vmid_gen(struct kvm *kvm)
3249 {
3250- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3251+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3252 }
3253
3254 /**
3255@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3256
3257 /* First user of a new VMID generation? */
3258 if (unlikely(kvm_next_vmid == 0)) {
3259- atomic64_inc(&kvm_vmid_gen);
3260+ atomic64_inc_unchecked(&kvm_vmid_gen);
3261 kvm_next_vmid = 1;
3262
3263 /*
3264@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3265 kvm_call_hyp(__kvm_flush_vm_context);
3266 }
3267
3268- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3269+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3270 kvm->arch.vmid = kvm_next_vmid;
3271 kvm_next_vmid++;
3272
3273diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3274index 14a0d98..7771a7d 100644
3275--- a/arch/arm/lib/clear_user.S
3276+++ b/arch/arm/lib/clear_user.S
3277@@ -12,14 +12,14 @@
3278
3279 .text
3280
3281-/* Prototype: int __clear_user(void *addr, size_t sz)
3282+/* Prototype: int ___clear_user(void *addr, size_t sz)
3283 * Purpose : clear some user memory
3284 * Params : addr - user memory address to clear
3285 * : sz - number of bytes to clear
3286 * Returns : number of bytes NOT cleared
3287 */
3288 ENTRY(__clear_user_std)
3289-WEAK(__clear_user)
3290+WEAK(___clear_user)
3291 stmfd sp!, {r1, lr}
3292 mov r2, #0
3293 cmp r1, #4
3294@@ -44,7 +44,7 @@ WEAK(__clear_user)
3295 USER( strnebt r2, [r0])
3296 mov r0, #0
3297 ldmfd sp!, {r1, pc}
3298-ENDPROC(__clear_user)
3299+ENDPROC(___clear_user)
3300 ENDPROC(__clear_user_std)
3301
3302 .pushsection .fixup,"ax"
3303diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3304index 66a477a..bee61d3 100644
3305--- a/arch/arm/lib/copy_from_user.S
3306+++ b/arch/arm/lib/copy_from_user.S
3307@@ -16,7 +16,7 @@
3308 /*
3309 * Prototype:
3310 *
3311- * size_t __copy_from_user(void *to, const void *from, size_t n)
3312+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3313 *
3314 * Purpose:
3315 *
3316@@ -84,11 +84,11 @@
3317
3318 .text
3319
3320-ENTRY(__copy_from_user)
3321+ENTRY(___copy_from_user)
3322
3323 #include "copy_template.S"
3324
3325-ENDPROC(__copy_from_user)
3326+ENDPROC(___copy_from_user)
3327
3328 .pushsection .fixup,"ax"
3329 .align 0
3330diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3331index 6ee2f67..d1cce76 100644
3332--- a/arch/arm/lib/copy_page.S
3333+++ b/arch/arm/lib/copy_page.S
3334@@ -10,6 +10,7 @@
3335 * ASM optimised string functions
3336 */
3337 #include <linux/linkage.h>
3338+#include <linux/const.h>
3339 #include <asm/assembler.h>
3340 #include <asm/asm-offsets.h>
3341 #include <asm/cache.h>
3342diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3343index d066df6..df28194 100644
3344--- a/arch/arm/lib/copy_to_user.S
3345+++ b/arch/arm/lib/copy_to_user.S
3346@@ -16,7 +16,7 @@
3347 /*
3348 * Prototype:
3349 *
3350- * size_t __copy_to_user(void *to, const void *from, size_t n)
3351+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3352 *
3353 * Purpose:
3354 *
3355@@ -88,11 +88,11 @@
3356 .text
3357
3358 ENTRY(__copy_to_user_std)
3359-WEAK(__copy_to_user)
3360+WEAK(___copy_to_user)
3361
3362 #include "copy_template.S"
3363
3364-ENDPROC(__copy_to_user)
3365+ENDPROC(___copy_to_user)
3366 ENDPROC(__copy_to_user_std)
3367
3368 .pushsection .fixup,"ax"
3369diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3370index 7d08b43..f7ca7ea 100644
3371--- a/arch/arm/lib/csumpartialcopyuser.S
3372+++ b/arch/arm/lib/csumpartialcopyuser.S
3373@@ -57,8 +57,8 @@
3374 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3375 */
3376
3377-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3378-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3379+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3380+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3381
3382 #include "csumpartialcopygeneric.S"
3383
3384diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3385index 5306de3..aed6d03 100644
3386--- a/arch/arm/lib/delay.c
3387+++ b/arch/arm/lib/delay.c
3388@@ -28,7 +28,7 @@
3389 /*
3390 * Default to the loop-based delay implementation.
3391 */
3392-struct arm_delay_ops arm_delay_ops = {
3393+struct arm_delay_ops arm_delay_ops __read_only = {
3394 .delay = __loop_delay,
3395 .const_udelay = __loop_const_udelay,
3396 .udelay = __loop_udelay,
3397diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3398index 3e58d71..029817c 100644
3399--- a/arch/arm/lib/uaccess_with_memcpy.c
3400+++ b/arch/arm/lib/uaccess_with_memcpy.c
3401@@ -136,7 +136,7 @@ out:
3402 }
3403
3404 unsigned long
3405-__copy_to_user(void __user *to, const void *from, unsigned long n)
3406+___copy_to_user(void __user *to, const void *from, unsigned long n)
3407 {
3408 /*
3409 * This test is stubbed out of the main function above to keep
3410@@ -190,7 +190,7 @@ out:
3411 return n;
3412 }
3413
3414-unsigned long __clear_user(void __user *addr, unsigned long n)
3415+unsigned long ___clear_user(void __user *addr, unsigned long n)
3416 {
3417 /* See rational for this in __copy_to_user() above. */
3418 if (n < 64)
3419diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3420index f7ca97b..3d7e719 100644
3421--- a/arch/arm/mach-at91/setup.c
3422+++ b/arch/arm/mach-at91/setup.c
3423@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3424
3425 desc->pfn = __phys_to_pfn(base);
3426 desc->length = length;
3427- desc->type = MT_MEMORY_RWX_NONCACHED;
3428+ desc->type = MT_MEMORY_RW_NONCACHED;
3429
3430 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3431 base, length, desc->virtual);
3432diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3433index f3407a5..bd4256f 100644
3434--- a/arch/arm/mach-kirkwood/common.c
3435+++ b/arch/arm/mach-kirkwood/common.c
3436@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3437 clk_gate_ops.disable(hw);
3438 }
3439
3440-static struct clk_ops clk_gate_fn_ops;
3441+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3442+{
3443+ return clk_gate_ops.is_enabled(hw);
3444+}
3445+
3446+static struct clk_ops clk_gate_fn_ops = {
3447+ .enable = clk_gate_fn_enable,
3448+ .disable = clk_gate_fn_disable,
3449+ .is_enabled = clk_gate_fn_is_enabled,
3450+};
3451
3452 static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 const char *name,
3454@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3455 gate_fn->fn_en = fn_en;
3456 gate_fn->fn_dis = fn_dis;
3457
3458- /* ops is the gate ops, but with our enable/disable functions */
3459- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3460- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3461- clk_gate_fn_ops = clk_gate_ops;
3462- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3463- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3464- }
3465-
3466 clk = clk_register(dev, &gate_fn->gate.hw);
3467
3468 if (IS_ERR(clk))
3469diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3470index aead77a..a2253fa 100644
3471--- a/arch/arm/mach-omap2/board-n8x0.c
3472+++ b/arch/arm/mach-omap2/board-n8x0.c
3473@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3474 }
3475 #endif
3476
3477-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3478+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3479 .late_init = n8x0_menelaus_late_init,
3480 };
3481
3482diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3483index ab43755..ccfa231 100644
3484--- a/arch/arm/mach-omap2/gpmc.c
3485+++ b/arch/arm/mach-omap2/gpmc.c
3486@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3487 };
3488
3489 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3490-static struct irq_chip gpmc_irq_chip;
3491 static int gpmc_irq_start;
3492
3493 static struct resource gpmc_mem_root;
3494@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3495
3496 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3497
3498+static struct irq_chip gpmc_irq_chip = {
3499+ .name = "gpmc",
3500+ .irq_startup = gpmc_irq_noop_ret,
3501+ .irq_enable = gpmc_irq_enable,
3502+ .irq_disable = gpmc_irq_disable,
3503+ .irq_shutdown = gpmc_irq_noop,
3504+ .irq_ack = gpmc_irq_noop,
3505+ .irq_mask = gpmc_irq_noop,
3506+ .irq_unmask = gpmc_irq_noop,
3507+
3508+};
3509+
3510 static int gpmc_setup_irq(void)
3511 {
3512 int i;
3513@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3514 return gpmc_irq_start;
3515 }
3516
3517- gpmc_irq_chip.name = "gpmc";
3518- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3519- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3520- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3521- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3522- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3523- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3524- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3525-
3526 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3527 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3528
3529diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530index 667915d..2ee1219 100644
3531--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3532+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3533@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3534 int (*finish_suspend)(unsigned long cpu_state);
3535 void (*resume)(void);
3536 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3537-};
3538+} __no_const;
3539
3540 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3541 static struct powerdomain *mpuss_pd;
3542@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3543 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3544 {}
3545
3546-struct cpu_pm_ops omap_pm_ops = {
3547+static struct cpu_pm_ops omap_pm_ops __read_only = {
3548 .finish_suspend = default_finish_suspend,
3549 .resume = dummy_cpu_resume,
3550 .scu_prepare = dummy_scu_prepare,
3551diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3552index 3664562..72f85c6 100644
3553--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3554+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3555@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3556 return NOTIFY_OK;
3557 }
3558
3559-static struct notifier_block __refdata irq_hotplug_notifier = {
3560+static struct notifier_block irq_hotplug_notifier = {
3561 .notifier_call = irq_cpu_hotplug_notify,
3562 };
3563
3564diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3565index 01ef59d..32ae28a8 100644
3566--- a/arch/arm/mach-omap2/omap_device.c
3567+++ b/arch/arm/mach-omap2/omap_device.c
3568@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3569 struct platform_device __init *omap_device_build(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod *oh,
3572- void *pdata, int pdata_len)
3573+ const void *pdata, int pdata_len)
3574 {
3575 struct omap_hwmod *ohs[] = { oh };
3576
3577@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3578 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3579 int pdev_id,
3580 struct omap_hwmod **ohs,
3581- int oh_cnt, void *pdata,
3582+ int oh_cnt, const void *pdata,
3583 int pdata_len)
3584 {
3585 int ret = -ENOMEM;
3586diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3587index 78c02b3..c94109a 100644
3588--- a/arch/arm/mach-omap2/omap_device.h
3589+++ b/arch/arm/mach-omap2/omap_device.h
3590@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3591 /* Core code interface */
3592
3593 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3594- struct omap_hwmod *oh, void *pdata,
3595+ struct omap_hwmod *oh, const void *pdata,
3596 int pdata_len);
3597
3598 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3599 struct omap_hwmod **oh, int oh_cnt,
3600- void *pdata, int pdata_len);
3601+ const void *pdata, int pdata_len);
3602
3603 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3604 struct omap_hwmod **ohs, int oh_cnt);
3605diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3606index 66c60fe..c78950d 100644
3607--- a/arch/arm/mach-omap2/omap_hwmod.c
3608+++ b/arch/arm/mach-omap2/omap_hwmod.c
3609@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3610 int (*init_clkdm)(struct omap_hwmod *oh);
3611 void (*update_context_lost)(struct omap_hwmod *oh);
3612 int (*get_context_lost)(struct omap_hwmod *oh);
3613-};
3614+} __no_const;
3615
3616 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3617-static struct omap_hwmod_soc_ops soc_ops;
3618+static struct omap_hwmod_soc_ops soc_ops __read_only;
3619
3620 /* omap_hwmod_list contains all registered struct omap_hwmods */
3621 static LIST_HEAD(omap_hwmod_list);
3622diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3623index 95fee54..cfa9cf1 100644
3624--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3625+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3626@@ -10,6 +10,7 @@
3627
3628 #include <linux/kernel.h>
3629 #include <linux/init.h>
3630+#include <asm/pgtable.h>
3631
3632 #include "powerdomain.h"
3633
3634@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3635
3636 void __init am43xx_powerdomains_init(void)
3637 {
3638- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639+ pax_open_kernel();
3640+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3641+ pax_close_kernel();
3642 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3643 pwrdm_register_pwrdms(powerdomains_am43xx);
3644 pwrdm_complete_init();
3645diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3646index d15c7bb..b2d1f0c 100644
3647--- a/arch/arm/mach-omap2/wd_timer.c
3648+++ b/arch/arm/mach-omap2/wd_timer.c
3649@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3650 struct omap_hwmod *oh;
3651 char *oh_name = "wd_timer2";
3652 char *dev_name = "omap_wdt";
3653- struct omap_wd_timer_platform_data pdata;
3654+ static struct omap_wd_timer_platform_data pdata = {
3655+ .read_reset_sources = prm_read_reset_sources
3656+ };
3657
3658 if (!cpu_class_is_omap2() || of_have_populated_dt())
3659 return 0;
3660@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3661 return -EINVAL;
3662 }
3663
3664- pdata.read_reset_sources = prm_read_reset_sources;
3665-
3666 pdev = omap_device_build(dev_name, id, oh, &pdata,
3667 sizeof(struct omap_wd_timer_platform_data));
3668 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3669diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3670index b82dcae..44ee5b6 100644
3671--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3672+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3673@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3674 bool entered_lp2 = false;
3675
3676 if (tegra_pending_sgi())
3677- ACCESS_ONCE(abort_flag) = true;
3678+ ACCESS_ONCE_RW(abort_flag) = true;
3679
3680 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3681
3682diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3683index 2dea8b5..6499da2 100644
3684--- a/arch/arm/mach-ux500/setup.h
3685+++ b/arch/arm/mach-ux500/setup.h
3686@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3687 .type = MT_DEVICE, \
3688 }
3689
3690-#define __MEM_DEV_DESC(x, sz) { \
3691- .virtual = IO_ADDRESS(x), \
3692- .pfn = __phys_to_pfn(x), \
3693- .length = sz, \
3694- .type = MT_MEMORY_RWX, \
3695-}
3696-
3697 extern struct smp_operations ux500_smp_ops;
3698 extern void ux500_cpu_die(unsigned int cpu);
3699
3700diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3701index ca8ecde..58ba893 100644
3702--- a/arch/arm/mm/Kconfig
3703+++ b/arch/arm/mm/Kconfig
3704@@ -446,6 +446,7 @@ config CPU_32v5
3705
3706 config CPU_32v6
3707 bool
3708+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3709 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3710
3711 config CPU_32v6K
3712@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3713
3714 config CPU_USE_DOMAINS
3715 bool
3716+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3717 help
3718 This option enables or disables the use of domain switching
3719 via the set_fs() function.
3720@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3721 config KUSER_HELPERS
3722 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3723 default y
3724+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3725 help
3726 Warning: disabling this option may break user programs.
3727
3728@@ -811,7 +814,7 @@ config KUSER_HELPERS
3729 See Documentation/arm/kernel_user_helpers.txt for details.
3730
3731 However, the fixed address nature of these helpers can be used
3732- by ROP (return orientated programming) authors when creating
3733+ by ROP (Return Oriented Programming) authors when creating
3734 exploits.
3735
3736 If all of the binaries and libraries which run on your platform
3737diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3738index 9240364..a2b8cf3 100644
3739--- a/arch/arm/mm/alignment.c
3740+++ b/arch/arm/mm/alignment.c
3741@@ -212,10 +212,12 @@ union offset_union {
3742 #define __get16_unaligned_check(ins,val,addr) \
3743 do { \
3744 unsigned int err = 0, v, a = addr; \
3745+ pax_open_userland(); \
3746 __get8_unaligned_check(ins,v,a,err); \
3747 val = v << ((BE) ? 8 : 0); \
3748 __get8_unaligned_check(ins,v,a,err); \
3749 val |= v << ((BE) ? 0 : 8); \
3750+ pax_close_userland(); \
3751 if (err) \
3752 goto fault; \
3753 } while (0)
3754@@ -229,6 +231,7 @@ union offset_union {
3755 #define __get32_unaligned_check(ins,val,addr) \
3756 do { \
3757 unsigned int err = 0, v, a = addr; \
3758+ pax_open_userland(); \
3759 __get8_unaligned_check(ins,v,a,err); \
3760 val = v << ((BE) ? 24 : 0); \
3761 __get8_unaligned_check(ins,v,a,err); \
3762@@ -237,6 +240,7 @@ union offset_union {
3763 val |= v << ((BE) ? 8 : 16); \
3764 __get8_unaligned_check(ins,v,a,err); \
3765 val |= v << ((BE) ? 0 : 24); \
3766+ pax_close_userland(); \
3767 if (err) \
3768 goto fault; \
3769 } while (0)
3770@@ -250,6 +254,7 @@ union offset_union {
3771 #define __put16_unaligned_check(ins,val,addr) \
3772 do { \
3773 unsigned int err = 0, v = val, a = addr; \
3774+ pax_open_userland(); \
3775 __asm__( FIRST_BYTE_16 \
3776 ARM( "1: "ins" %1, [%2], #1\n" ) \
3777 THUMB( "1: "ins" %1, [%2]\n" ) \
3778@@ -269,6 +274,7 @@ union offset_union {
3779 " .popsection\n" \
3780 : "=r" (err), "=&r" (v), "=&r" (a) \
3781 : "0" (err), "1" (v), "2" (a)); \
3782+ pax_close_userland(); \
3783 if (err) \
3784 goto fault; \
3785 } while (0)
3786@@ -282,6 +288,7 @@ union offset_union {
3787 #define __put32_unaligned_check(ins,val,addr) \
3788 do { \
3789 unsigned int err = 0, v = val, a = addr; \
3790+ pax_open_userland(); \
3791 __asm__( FIRST_BYTE_32 \
3792 ARM( "1: "ins" %1, [%2], #1\n" ) \
3793 THUMB( "1: "ins" %1, [%2]\n" ) \
3794@@ -311,6 +318,7 @@ union offset_union {
3795 " .popsection\n" \
3796 : "=r" (err), "=&r" (v), "=&r" (a) \
3797 : "0" (err), "1" (v), "2" (a)); \
3798+ pax_close_userland(); \
3799 if (err) \
3800 goto fault; \
3801 } while (0)
3802diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3803index 7abde2c..9df495f 100644
3804--- a/arch/arm/mm/cache-l2x0.c
3805+++ b/arch/arm/mm/cache-l2x0.c
3806@@ -46,7 +46,7 @@ struct l2x0_of_data {
3807 void (*setup)(const struct device_node *, u32 *, u32 *);
3808 void (*save)(void);
3809 struct outer_cache_fns outer_cache;
3810-};
3811+} __do_const;
3812
3813 static bool of_init = false;
3814
3815diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3816index 6eb97b3..ac509f6 100644
3817--- a/arch/arm/mm/context.c
3818+++ b/arch/arm/mm/context.c
3819@@ -43,7 +43,7 @@
3820 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3821
3822 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3823-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3824+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3825 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3826
3827 static DEFINE_PER_CPU(atomic64_t, active_asids);
3828@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3829 {
3830 static u32 cur_idx = 1;
3831 u64 asid = atomic64_read(&mm->context.id);
3832- u64 generation = atomic64_read(&asid_generation);
3833+ u64 generation = atomic64_read_unchecked(&asid_generation);
3834
3835 if (asid != 0 && is_reserved_asid(asid)) {
3836 /*
3837@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3838 */
3839 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3840 if (asid == NUM_USER_ASIDS) {
3841- generation = atomic64_add_return(ASID_FIRST_VERSION,
3842+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3843 &asid_generation);
3844 flush_context(cpu);
3845 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3846@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3847 cpu_set_reserved_ttbr0();
3848
3849 asid = atomic64_read(&mm->context.id);
3850- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3851+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3852 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3853 goto switch_mm_fastpath;
3854
3855 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3856 /* Check that our ASID belongs to the current generation. */
3857 asid = atomic64_read(&mm->context.id);
3858- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3859+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3860 asid = new_context(mm, cpu);
3861 atomic64_set(&mm->context.id, asid);
3862 }
3863diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3864index eb8830a..5360ce7 100644
3865--- a/arch/arm/mm/fault.c
3866+++ b/arch/arm/mm/fault.c
3867@@ -25,6 +25,7 @@
3868 #include <asm/system_misc.h>
3869 #include <asm/system_info.h>
3870 #include <asm/tlbflush.h>
3871+#include <asm/sections.h>
3872
3873 #include "fault.h"
3874
3875@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3876 if (fixup_exception(regs))
3877 return;
3878
3879+#ifdef CONFIG_PAX_MEMORY_UDEREF
3880+ if (addr < TASK_SIZE) {
3881+ if (current->signal->curr_ip)
3882+ 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),
3883+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3884+ else
3885+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3886+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3887+ }
3888+#endif
3889+
3890+#ifdef CONFIG_PAX_KERNEXEC
3891+ if ((fsr & FSR_WRITE) &&
3892+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3893+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3894+ {
3895+ if (current->signal->curr_ip)
3896+ 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),
3897+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3898+ else
3899+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3900+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3901+ }
3902+#endif
3903+
3904 /*
3905 * No handler, we'll have to terminate things with extreme prejudice.
3906 */
3907@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3908 }
3909 #endif
3910
3911+#ifdef CONFIG_PAX_PAGEEXEC
3912+ if (fsr & FSR_LNX_PF) {
3913+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3914+ do_group_exit(SIGKILL);
3915+ }
3916+#endif
3917+
3918 tsk->thread.address = addr;
3919 tsk->thread.error_code = fsr;
3920 tsk->thread.trap_no = 14;
3921@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3922 }
3923 #endif /* CONFIG_MMU */
3924
3925+#ifdef CONFIG_PAX_PAGEEXEC
3926+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3927+{
3928+ long i;
3929+
3930+ printk(KERN_ERR "PAX: bytes at PC: ");
3931+ for (i = 0; i < 20; i++) {
3932+ unsigned char c;
3933+ if (get_user(c, (__force unsigned char __user *)pc+i))
3934+ printk(KERN_CONT "?? ");
3935+ else
3936+ printk(KERN_CONT "%02x ", c);
3937+ }
3938+ printk("\n");
3939+
3940+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3941+ for (i = -1; i < 20; i++) {
3942+ unsigned long c;
3943+ if (get_user(c, (__force unsigned long __user *)sp+i))
3944+ printk(KERN_CONT "???????? ");
3945+ else
3946+ printk(KERN_CONT "%08lx ", c);
3947+ }
3948+ printk("\n");
3949+}
3950+#endif
3951+
3952 /*
3953 * First Level Translation Fault Handler
3954 *
3955@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3956 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3957 struct siginfo info;
3958
3959+#ifdef CONFIG_PAX_MEMORY_UDEREF
3960+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3961+ if (current->signal->curr_ip)
3962+ 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),
3963+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3964+ else
3965+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3966+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3967+ goto die;
3968+ }
3969+#endif
3970+
3971 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3972 return;
3973
3974+die:
3975 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3976 inf->name, fsr, addr);
3977
3978@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3979 ifsr_info[nr].name = name;
3980 }
3981
3982+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3983+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3984+
3985 asmlinkage void __exception
3986 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3987 {
3988 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3989 struct siginfo info;
3990+ unsigned long pc = instruction_pointer(regs);
3991+
3992+ if (user_mode(regs)) {
3993+ unsigned long sigpage = current->mm->context.sigpage;
3994+
3995+ if (sigpage <= pc && pc < sigpage + 7*4) {
3996+ if (pc < sigpage + 3*4)
3997+ sys_sigreturn(regs);
3998+ else
3999+ sys_rt_sigreturn(regs);
4000+ return;
4001+ }
4002+ if (pc == 0xffff0f60UL) {
4003+ /*
4004+ * PaX: __kuser_cmpxchg64 emulation
4005+ */
4006+ // TODO
4007+ //regs->ARM_pc = regs->ARM_lr;
4008+ //return;
4009+ }
4010+ if (pc == 0xffff0fa0UL) {
4011+ /*
4012+ * PaX: __kuser_memory_barrier emulation
4013+ */
4014+ // dmb(); implied by the exception
4015+ regs->ARM_pc = regs->ARM_lr;
4016+ return;
4017+ }
4018+ if (pc == 0xffff0fc0UL) {
4019+ /*
4020+ * PaX: __kuser_cmpxchg emulation
4021+ */
4022+ // TODO
4023+ //long new;
4024+ //int op;
4025+
4026+ //op = FUTEX_OP_SET << 28;
4027+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4028+ //regs->ARM_r0 = old != new;
4029+ //regs->ARM_pc = regs->ARM_lr;
4030+ //return;
4031+ }
4032+ if (pc == 0xffff0fe0UL) {
4033+ /*
4034+ * PaX: __kuser_get_tls emulation
4035+ */
4036+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4037+ regs->ARM_pc = regs->ARM_lr;
4038+ return;
4039+ }
4040+ }
4041+
4042+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4043+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4044+ if (current->signal->curr_ip)
4045+ 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),
4046+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4047+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4048+ else
4049+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4050+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4051+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4052+ goto die;
4053+ }
4054+#endif
4055+
4056+#ifdef CONFIG_PAX_REFCOUNT
4057+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4058+ unsigned int bkpt;
4059+
4060+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4061+ current->thread.error_code = ifsr;
4062+ current->thread.trap_no = 0;
4063+ pax_report_refcount_overflow(regs);
4064+ fixup_exception(regs);
4065+ return;
4066+ }
4067+ }
4068+#endif
4069
4070 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4071 return;
4072
4073+die:
4074 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4075 inf->name, ifsr, addr);
4076
4077diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4078index cf08bdf..772656c 100644
4079--- a/arch/arm/mm/fault.h
4080+++ b/arch/arm/mm/fault.h
4081@@ -3,6 +3,7 @@
4082
4083 /*
4084 * Fault status register encodings. We steal bit 31 for our own purposes.
4085+ * Set when the FSR value is from an instruction fault.
4086 */
4087 #define FSR_LNX_PF (1 << 31)
4088 #define FSR_WRITE (1 << 11)
4089@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4090 }
4091 #endif
4092
4093+/* valid for LPAE and !LPAE */
4094+static inline int is_xn_fault(unsigned int fsr)
4095+{
4096+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4097+}
4098+
4099+static inline int is_domain_fault(unsigned int fsr)
4100+{
4101+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4102+}
4103+
4104 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4105 unsigned long search_exception_table(unsigned long addr);
4106
4107diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4108index 804d615..fcec50a 100644
4109--- a/arch/arm/mm/init.c
4110+++ b/arch/arm/mm/init.c
4111@@ -30,6 +30,8 @@
4112 #include <asm/setup.h>
4113 #include <asm/tlb.h>
4114 #include <asm/fixmap.h>
4115+#include <asm/system_info.h>
4116+#include <asm/cp15.h>
4117
4118 #include <asm/mach/arch.h>
4119 #include <asm/mach/map.h>
4120@@ -625,7 +627,46 @@ void free_initmem(void)
4121 {
4122 #ifdef CONFIG_HAVE_TCM
4123 extern char __tcm_start, __tcm_end;
4124+#endif
4125
4126+#ifdef CONFIG_PAX_KERNEXEC
4127+ unsigned long addr;
4128+ pgd_t *pgd;
4129+ pud_t *pud;
4130+ pmd_t *pmd;
4131+ int cpu_arch = cpu_architecture();
4132+ unsigned int cr = get_cr();
4133+
4134+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4135+ /* make pages tables, etc before .text NX */
4136+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4137+ pgd = pgd_offset_k(addr);
4138+ pud = pud_offset(pgd, addr);
4139+ pmd = pmd_offset(pud, addr);
4140+ __section_update(pmd, addr, PMD_SECT_XN);
4141+ }
4142+ /* make init NX */
4143+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4144+ pgd = pgd_offset_k(addr);
4145+ pud = pud_offset(pgd, addr);
4146+ pmd = pmd_offset(pud, addr);
4147+ __section_update(pmd, addr, PMD_SECT_XN);
4148+ }
4149+ /* make kernel code/rodata RX */
4150+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4151+ pgd = pgd_offset_k(addr);
4152+ pud = pud_offset(pgd, addr);
4153+ pmd = pmd_offset(pud, addr);
4154+#ifdef CONFIG_ARM_LPAE
4155+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4156+#else
4157+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4158+#endif
4159+ }
4160+ }
4161+#endif
4162+
4163+#ifdef CONFIG_HAVE_TCM
4164 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4165 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4166 #endif
4167diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4168index f9c32ba..8540068 100644
4169--- a/arch/arm/mm/ioremap.c
4170+++ b/arch/arm/mm/ioremap.c
4171@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4172 unsigned int mtype;
4173
4174 if (cached)
4175- mtype = MT_MEMORY_RWX;
4176+ mtype = MT_MEMORY_RX;
4177 else
4178- mtype = MT_MEMORY_RWX_NONCACHED;
4179+ mtype = MT_MEMORY_RX_NONCACHED;
4180
4181 return __arm_ioremap_caller(phys_addr, size, mtype,
4182 __builtin_return_address(0));
4183diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4184index 5e85ed3..b10a7ed 100644
4185--- a/arch/arm/mm/mmap.c
4186+++ b/arch/arm/mm/mmap.c
4187@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4188 struct vm_area_struct *vma;
4189 int do_align = 0;
4190 int aliasing = cache_is_vipt_aliasing();
4191+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4192 struct vm_unmapped_area_info info;
4193
4194 /*
4195@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4196 if (len > TASK_SIZE)
4197 return -ENOMEM;
4198
4199+#ifdef CONFIG_PAX_RANDMMAP
4200+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4201+#endif
4202+
4203 if (addr) {
4204 if (do_align)
4205 addr = COLOUR_ALIGN(addr, pgoff);
4206@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4207 addr = PAGE_ALIGN(addr);
4208
4209 vma = find_vma(mm, addr);
4210- if (TASK_SIZE - len >= addr &&
4211- (!vma || addr + len <= vma->vm_start))
4212+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4213 return addr;
4214 }
4215
4216@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4217 info.high_limit = TASK_SIZE;
4218 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4219 info.align_offset = pgoff << PAGE_SHIFT;
4220+ info.threadstack_offset = offset;
4221 return vm_unmapped_area(&info);
4222 }
4223
4224@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4225 unsigned long addr = addr0;
4226 int do_align = 0;
4227 int aliasing = cache_is_vipt_aliasing();
4228+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4229 struct vm_unmapped_area_info info;
4230
4231 /*
4232@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4233 return addr;
4234 }
4235
4236+#ifdef CONFIG_PAX_RANDMMAP
4237+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4238+#endif
4239+
4240 /* requesting a specific address */
4241 if (addr) {
4242 if (do_align)
4243@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4244 else
4245 addr = PAGE_ALIGN(addr);
4246 vma = find_vma(mm, addr);
4247- if (TASK_SIZE - len >= addr &&
4248- (!vma || addr + len <= vma->vm_start))
4249+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4250 return addr;
4251 }
4252
4253@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4254 info.high_limit = mm->mmap_base;
4255 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4256 info.align_offset = pgoff << PAGE_SHIFT;
4257+ info.threadstack_offset = offset;
4258 addr = vm_unmapped_area(&info);
4259
4260 /*
4261@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4262 {
4263 unsigned long random_factor = 0UL;
4264
4265+#ifdef CONFIG_PAX_RANDMMAP
4266+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4267+#endif
4268+
4269 /* 8 bits of randomness in 20 address space bits */
4270 if ((current->flags & PF_RANDOMIZE) &&
4271 !(current->personality & ADDR_NO_RANDOMIZE))
4272@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4273
4274 if (mmap_is_legacy()) {
4275 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4276+
4277+#ifdef CONFIG_PAX_RANDMMAP
4278+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4279+ mm->mmap_base += mm->delta_mmap;
4280+#endif
4281+
4282 mm->get_unmapped_area = arch_get_unmapped_area;
4283 } else {
4284 mm->mmap_base = mmap_base(random_factor);
4285+
4286+#ifdef CONFIG_PAX_RANDMMAP
4287+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4288+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4289+#endif
4290+
4291 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4292 }
4293 }
4294diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4295index b68c6b2..f66c492 100644
4296--- a/arch/arm/mm/mmu.c
4297+++ b/arch/arm/mm/mmu.c
4298@@ -39,6 +39,22 @@
4299 #include "mm.h"
4300 #include "tcm.h"
4301
4302+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4303+void modify_domain(unsigned int dom, unsigned int type)
4304+{
4305+ struct thread_info *thread = current_thread_info();
4306+ unsigned int domain = thread->cpu_domain;
4307+ /*
4308+ * DOMAIN_MANAGER might be defined to some other value,
4309+ * use the arch-defined constant
4310+ */
4311+ domain &= ~domain_val(dom, 3);
4312+ thread->cpu_domain = domain | domain_val(dom, type);
4313+ set_domain(thread->cpu_domain);
4314+}
4315+EXPORT_SYMBOL(modify_domain);
4316+#endif
4317+
4318 /*
4319 * empty_zero_page is a special page that is used for
4320 * zero-initialized data and COW.
4321@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4322 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4323 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4324
4325-static struct mem_type mem_types[] = {
4326+#ifdef CONFIG_PAX_KERNEXEC
4327+#define L_PTE_KERNEXEC L_PTE_RDONLY
4328+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4329+#else
4330+#define L_PTE_KERNEXEC L_PTE_DIRTY
4331+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4332+#endif
4333+
4334+static struct mem_type mem_types[] __read_only = {
4335 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4336 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4337 L_PTE_SHARED,
4338@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4339 .prot_sect = PROT_SECT_DEVICE,
4340 .domain = DOMAIN_IO,
4341 },
4342- [MT_UNCACHED] = {
4343+ [MT_UNCACHED_RW] = {
4344 .prot_pte = PROT_PTE_DEVICE,
4345 .prot_l1 = PMD_TYPE_TABLE,
4346 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4347 .domain = DOMAIN_IO,
4348 },
4349- [MT_CACHECLEAN] = {
4350- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4351+ [MT_CACHECLEAN_RO] = {
4352+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4353 .domain = DOMAIN_KERNEL,
4354 },
4355 #ifndef CONFIG_ARM_LPAE
4356- [MT_MINICLEAN] = {
4357- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4358+ [MT_MINICLEAN_RO] = {
4359+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4360 .domain = DOMAIN_KERNEL,
4361 },
4362 #endif
4363@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4364 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4365 L_PTE_RDONLY,
4366 .prot_l1 = PMD_TYPE_TABLE,
4367- .domain = DOMAIN_USER,
4368+ .domain = DOMAIN_VECTORS,
4369 },
4370 [MT_HIGH_VECTORS] = {
4371 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4372 L_PTE_USER | L_PTE_RDONLY,
4373 .prot_l1 = PMD_TYPE_TABLE,
4374- .domain = DOMAIN_USER,
4375+ .domain = DOMAIN_VECTORS,
4376 },
4377- [MT_MEMORY_RWX] = {
4378+ [__MT_MEMORY_RWX] = {
4379 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4380 .prot_l1 = PMD_TYPE_TABLE,
4381 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4382@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4383 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4384 .domain = DOMAIN_KERNEL,
4385 },
4386- [MT_ROM] = {
4387- .prot_sect = PMD_TYPE_SECT,
4388+ [MT_MEMORY_RX] = {
4389+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4390+ .prot_l1 = PMD_TYPE_TABLE,
4391+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4392+ .domain = DOMAIN_KERNEL,
4393+ },
4394+ [MT_ROM_RX] = {
4395+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4396 .domain = DOMAIN_KERNEL,
4397 },
4398- [MT_MEMORY_RWX_NONCACHED] = {
4399+ [MT_MEMORY_RW_NONCACHED] = {
4400 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4401 L_PTE_MT_BUFFERABLE,
4402 .prot_l1 = PMD_TYPE_TABLE,
4403 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4404 .domain = DOMAIN_KERNEL,
4405 },
4406+ [MT_MEMORY_RX_NONCACHED] = {
4407+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4408+ L_PTE_MT_BUFFERABLE,
4409+ .prot_l1 = PMD_TYPE_TABLE,
4410+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4411+ .domain = DOMAIN_KERNEL,
4412+ },
4413 [MT_MEMORY_RW_DTCM] = {
4414 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4415 L_PTE_XN,
4416@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4417 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4418 .domain = DOMAIN_KERNEL,
4419 },
4420- [MT_MEMORY_RWX_ITCM] = {
4421- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4422+ [MT_MEMORY_RX_ITCM] = {
4423+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4426 .domain = DOMAIN_KERNEL,
4427 },
4428 [MT_MEMORY_RW_SO] = {
4429@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4430 * Mark cache clean areas and XIP ROM read only
4431 * from SVC mode and no access from userspace.
4432 */
4433- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4434- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4436+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437+#ifdef CONFIG_PAX_KERNEXEC
4438+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4439+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4440+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441+#endif
4442+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4443+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4444 #endif
4445
4446 if (is_smp()) {
4447@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4448 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4449 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4450 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4451- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4452- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4453+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4454+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4455 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4456 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4457+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4458+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4459 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4460- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4461- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4462+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4463+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4464+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4465+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4466 }
4467 }
4468
4469@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4470 if (cpu_arch >= CPU_ARCH_ARMv6) {
4471 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4472 /* Non-cacheable Normal is XCB = 001 */
4473- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4474+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4475+ PMD_SECT_BUFFERED;
4476+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4477 PMD_SECT_BUFFERED;
4478 } else {
4479 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4480- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4481+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4482+ PMD_SECT_TEX(1);
4483+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4484 PMD_SECT_TEX(1);
4485 }
4486 } else {
4487- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4488+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4489+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4490 }
4491
4492 #ifdef CONFIG_ARM_LPAE
4493@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4494 vecs_pgprot |= PTE_EXT_AF;
4495 #endif
4496
4497+ user_pgprot |= __supported_pte_mask;
4498+
4499 for (i = 0; i < 16; i++) {
4500 pteval_t v = pgprot_val(protection_map[i]);
4501 protection_map[i] = __pgprot(v | user_pgprot);
4502@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4503
4504 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4505 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4506- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4507- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4508+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4509+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4510 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4511 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4512+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4513+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4514 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4515- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4516- mem_types[MT_ROM].prot_sect |= cp->pmd;
4517+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4518+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4519+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4520
4521 switch (cp->pmd) {
4522 case PMD_SECT_WT:
4523- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4524+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4525 break;
4526 case PMD_SECT_WB:
4527 case PMD_SECT_WBWA:
4528- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4529+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4530 break;
4531 }
4532 pr_info("Memory policy: %sData cache %s\n",
4533@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4534 return;
4535 }
4536
4537- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4538+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4539 md->virtual >= PAGE_OFFSET &&
4540 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4541 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4542@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4543 * called function. This means you can't use any function or debugging
4544 * method which may touch any device, otherwise the kernel _will_ crash.
4545 */
4546+
4547+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4548+
4549 static void __init devicemaps_init(const struct machine_desc *mdesc)
4550 {
4551 struct map_desc map;
4552 unsigned long addr;
4553- void *vectors;
4554
4555- /*
4556- * Allocate the vector page early.
4557- */
4558- vectors = early_alloc(PAGE_SIZE * 2);
4559-
4560- early_trap_init(vectors);
4561+ early_trap_init(&vectors);
4562
4563 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4564 pmd_clear(pmd_off_k(addr));
4565@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4566 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4567 map.virtual = MODULES_VADDR;
4568 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4569- map.type = MT_ROM;
4570+ map.type = MT_ROM_RX;
4571 create_mapping(&map);
4572 #endif
4573
4574@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4575 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4576 map.virtual = FLUSH_BASE;
4577 map.length = SZ_1M;
4578- map.type = MT_CACHECLEAN;
4579+ map.type = MT_CACHECLEAN_RO;
4580 create_mapping(&map);
4581 #endif
4582 #ifdef FLUSH_BASE_MINICACHE
4583 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4584 map.virtual = FLUSH_BASE_MINICACHE;
4585 map.length = SZ_1M;
4586- map.type = MT_MINICLEAN;
4587+ map.type = MT_MINICLEAN_RO;
4588 create_mapping(&map);
4589 #endif
4590
4591@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4592 * location (0xffff0000). If we aren't using high-vectors, also
4593 * create a mapping at the low-vectors virtual address.
4594 */
4595- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4596+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4597 map.virtual = 0xffff0000;
4598 map.length = PAGE_SIZE;
4599 #ifdef CONFIG_KUSER_HELPERS
4600@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4601 static void __init map_lowmem(void)
4602 {
4603 struct memblock_region *reg;
4604+#ifndef CONFIG_PAX_KERNEXEC
4605 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4606 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4607+#endif
4608
4609 /* Map all the lowmem memory banks. */
4610 for_each_memblock(memory, reg) {
4611@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4612 if (start >= end)
4613 break;
4614
4615+#ifdef CONFIG_PAX_KERNEXEC
4616+ map.pfn = __phys_to_pfn(start);
4617+ map.virtual = __phys_to_virt(start);
4618+ map.length = end - start;
4619+
4620+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4621+ struct map_desc kernel;
4622+ struct map_desc initmap;
4623+
4624+ /* when freeing initmem we will make this RW */
4625+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4626+ initmap.virtual = (unsigned long)__init_begin;
4627+ initmap.length = _sdata - __init_begin;
4628+ initmap.type = __MT_MEMORY_RWX;
4629+ create_mapping(&initmap);
4630+
4631+ /* when freeing initmem we will make this RX */
4632+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4633+ kernel.virtual = (unsigned long)_stext;
4634+ kernel.length = __init_begin - _stext;
4635+ kernel.type = __MT_MEMORY_RWX;
4636+ create_mapping(&kernel);
4637+
4638+ if (map.virtual < (unsigned long)_stext) {
4639+ map.length = (unsigned long)_stext - map.virtual;
4640+ map.type = __MT_MEMORY_RWX;
4641+ create_mapping(&map);
4642+ }
4643+
4644+ map.pfn = __phys_to_pfn(__pa(_sdata));
4645+ map.virtual = (unsigned long)_sdata;
4646+ map.length = end - __pa(_sdata);
4647+ }
4648+
4649+ map.type = MT_MEMORY_RW;
4650+ create_mapping(&map);
4651+#else
4652 if (end < kernel_x_start || start >= kernel_x_end) {
4653 map.pfn = __phys_to_pfn(start);
4654 map.virtual = __phys_to_virt(start);
4655 map.length = end - start;
4656- map.type = MT_MEMORY_RWX;
4657+ map.type = __MT_MEMORY_RWX;
4658
4659 create_mapping(&map);
4660 } else {
4661@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4662 map.pfn = __phys_to_pfn(kernel_x_start);
4663 map.virtual = __phys_to_virt(kernel_x_start);
4664 map.length = kernel_x_end - kernel_x_start;
4665- map.type = MT_MEMORY_RWX;
4666+ map.type = __MT_MEMORY_RWX;
4667
4668 create_mapping(&map);
4669
4670@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4671 create_mapping(&map);
4672 }
4673 }
4674+#endif
4675 }
4676 }
4677
4678diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4679index 5b217f4..c23f40e 100644
4680--- a/arch/arm/plat-iop/setup.c
4681+++ b/arch/arm/plat-iop/setup.c
4682@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4683 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4684 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4685 .length = IOP3XX_PERIPHERAL_SIZE,
4686- .type = MT_UNCACHED,
4687+ .type = MT_UNCACHED_RW,
4688 },
4689 };
4690
4691diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4692index a5bc92d..0bb4730 100644
4693--- a/arch/arm/plat-omap/sram.c
4694+++ b/arch/arm/plat-omap/sram.c
4695@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4696 * Looks like we need to preserve some bootloader code at the
4697 * beginning of SRAM for jumping to flash for reboot to work...
4698 */
4699+ pax_open_kernel();
4700 memset_io(omap_sram_base + omap_sram_skip, 0,
4701 omap_sram_size - omap_sram_skip);
4702+ pax_close_kernel();
4703 }
4704diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4705index ce6d763..cfea917 100644
4706--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4707+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4708@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4709 int (*started)(unsigned ch);
4710 int (*flush)(unsigned ch);
4711 int (*stop)(unsigned ch);
4712-};
4713+} __no_const;
4714
4715 extern void *samsung_dmadev_get_ops(void);
4716 extern void *s3c_dma_get_ops(void);
4717diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4718index 6c0f684..5faea9d 100644
4719--- a/arch/arm64/include/asm/uaccess.h
4720+++ b/arch/arm64/include/asm/uaccess.h
4721@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4722 flag; \
4723 })
4724
4725+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4726 #define access_ok(type, addr, size) __range_ok(addr, size)
4727 #define user_addr_max get_fs
4728
4729diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4730index c3a58a1..78fbf54 100644
4731--- a/arch/avr32/include/asm/cache.h
4732+++ b/arch/avr32/include/asm/cache.h
4733@@ -1,8 +1,10 @@
4734 #ifndef __ASM_AVR32_CACHE_H
4735 #define __ASM_AVR32_CACHE_H
4736
4737+#include <linux/const.h>
4738+
4739 #define L1_CACHE_SHIFT 5
4740-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4741+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4742
4743 /*
4744 * Memory returned by kmalloc() may be used for DMA, so we must make
4745diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4746index d232888..87c8df1 100644
4747--- a/arch/avr32/include/asm/elf.h
4748+++ b/arch/avr32/include/asm/elf.h
4749@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4750 the loader. We need to make sure that it is out of the way of the program
4751 that it will "exec", and that there is sufficient room for the brk. */
4752
4753-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4754+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4755
4756+#ifdef CONFIG_PAX_ASLR
4757+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4758+
4759+#define PAX_DELTA_MMAP_LEN 15
4760+#define PAX_DELTA_STACK_LEN 15
4761+#endif
4762
4763 /* This yields a mask that user programs can use to figure out what
4764 instruction set this CPU supports. This could be done in user space,
4765diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4766index 479330b..53717a8 100644
4767--- a/arch/avr32/include/asm/kmap_types.h
4768+++ b/arch/avr32/include/asm/kmap_types.h
4769@@ -2,9 +2,9 @@
4770 #define __ASM_AVR32_KMAP_TYPES_H
4771
4772 #ifdef CONFIG_DEBUG_HIGHMEM
4773-# define KM_TYPE_NR 29
4774+# define KM_TYPE_NR 30
4775 #else
4776-# define KM_TYPE_NR 14
4777+# define KM_TYPE_NR 15
4778 #endif
4779
4780 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4781diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4782index 0eca933..eb78c7b 100644
4783--- a/arch/avr32/mm/fault.c
4784+++ b/arch/avr32/mm/fault.c
4785@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4786
4787 int exception_trace = 1;
4788
4789+#ifdef CONFIG_PAX_PAGEEXEC
4790+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4791+{
4792+ unsigned long i;
4793+
4794+ printk(KERN_ERR "PAX: bytes at PC: ");
4795+ for (i = 0; i < 20; i++) {
4796+ unsigned char c;
4797+ if (get_user(c, (unsigned char *)pc+i))
4798+ printk(KERN_CONT "???????? ");
4799+ else
4800+ printk(KERN_CONT "%02x ", c);
4801+ }
4802+ printk("\n");
4803+}
4804+#endif
4805+
4806 /*
4807 * This routine handles page faults. It determines the address and the
4808 * problem, and then passes it off to one of the appropriate routines.
4809@@ -176,6 +193,16 @@ bad_area:
4810 up_read(&mm->mmap_sem);
4811
4812 if (user_mode(regs)) {
4813+
4814+#ifdef CONFIG_PAX_PAGEEXEC
4815+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4816+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4817+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4818+ do_group_exit(SIGKILL);
4819+ }
4820+ }
4821+#endif
4822+
4823 if (exception_trace && printk_ratelimit())
4824 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4825 "sp %08lx ecr %lu\n",
4826diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4827index 568885a..f8008df 100644
4828--- a/arch/blackfin/include/asm/cache.h
4829+++ b/arch/blackfin/include/asm/cache.h
4830@@ -7,6 +7,7 @@
4831 #ifndef __ARCH_BLACKFIN_CACHE_H
4832 #define __ARCH_BLACKFIN_CACHE_H
4833
4834+#include <linux/const.h>
4835 #include <linux/linkage.h> /* for asmlinkage */
4836
4837 /*
4838@@ -14,7 +15,7 @@
4839 * Blackfin loads 32 bytes for cache
4840 */
4841 #define L1_CACHE_SHIFT 5
4842-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4843+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4844 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4845
4846 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4847diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4848index aea2718..3639a60 100644
4849--- a/arch/cris/include/arch-v10/arch/cache.h
4850+++ b/arch/cris/include/arch-v10/arch/cache.h
4851@@ -1,8 +1,9 @@
4852 #ifndef _ASM_ARCH_CACHE_H
4853 #define _ASM_ARCH_CACHE_H
4854
4855+#include <linux/const.h>
4856 /* Etrax 100LX have 32-byte cache-lines. */
4857-#define L1_CACHE_BYTES 32
4858 #define L1_CACHE_SHIFT 5
4859+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4860
4861 #endif /* _ASM_ARCH_CACHE_H */
4862diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4863index 7caf25d..ee65ac5 100644
4864--- a/arch/cris/include/arch-v32/arch/cache.h
4865+++ b/arch/cris/include/arch-v32/arch/cache.h
4866@@ -1,11 +1,12 @@
4867 #ifndef _ASM_CRIS_ARCH_CACHE_H
4868 #define _ASM_CRIS_ARCH_CACHE_H
4869
4870+#include <linux/const.h>
4871 #include <arch/hwregs/dma.h>
4872
4873 /* A cache-line is 32 bytes. */
4874-#define L1_CACHE_BYTES 32
4875 #define L1_CACHE_SHIFT 5
4876+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4877
4878 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4879
4880diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4881index b86329d..6709906 100644
4882--- a/arch/frv/include/asm/atomic.h
4883+++ b/arch/frv/include/asm/atomic.h
4884@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4885 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4886 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4887
4888+#define atomic64_read_unchecked(v) atomic64_read(v)
4889+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4890+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4891+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4892+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4893+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4894+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4895+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4896+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4897+
4898 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4899 {
4900 int c, old;
4901diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4902index 2797163..c2a401d 100644
4903--- a/arch/frv/include/asm/cache.h
4904+++ b/arch/frv/include/asm/cache.h
4905@@ -12,10 +12,11 @@
4906 #ifndef __ASM_CACHE_H
4907 #define __ASM_CACHE_H
4908
4909+#include <linux/const.h>
4910
4911 /* bytes per L1 cache line */
4912 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4913-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4914+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4915
4916 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4917 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4918diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4919index 43901f2..0d8b865 100644
4920--- a/arch/frv/include/asm/kmap_types.h
4921+++ b/arch/frv/include/asm/kmap_types.h
4922@@ -2,6 +2,6 @@
4923 #ifndef _ASM_KMAP_TYPES_H
4924 #define _ASM_KMAP_TYPES_H
4925
4926-#define KM_TYPE_NR 17
4927+#define KM_TYPE_NR 18
4928
4929 #endif
4930diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4931index 836f147..4cf23f5 100644
4932--- a/arch/frv/mm/elf-fdpic.c
4933+++ b/arch/frv/mm/elf-fdpic.c
4934@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4935 {
4936 struct vm_area_struct *vma;
4937 struct vm_unmapped_area_info info;
4938+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4939
4940 if (len > TASK_SIZE)
4941 return -ENOMEM;
4942@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4943 if (addr) {
4944 addr = PAGE_ALIGN(addr);
4945 vma = find_vma(current->mm, addr);
4946- if (TASK_SIZE - len >= addr &&
4947- (!vma || addr + len <= vma->vm_start))
4948+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4949 goto success;
4950 }
4951
4952@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4953 info.high_limit = (current->mm->start_stack - 0x00200000);
4954 info.align_mask = 0;
4955 info.align_offset = 0;
4956+ info.threadstack_offset = offset;
4957 addr = vm_unmapped_area(&info);
4958 if (!(addr & ~PAGE_MASK))
4959 goto success;
4960diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4961index f4ca594..adc72fd6 100644
4962--- a/arch/hexagon/include/asm/cache.h
4963+++ b/arch/hexagon/include/asm/cache.h
4964@@ -21,9 +21,11 @@
4965 #ifndef __ASM_CACHE_H
4966 #define __ASM_CACHE_H
4967
4968+#include <linux/const.h>
4969+
4970 /* Bytes per L1 cache line */
4971-#define L1_CACHE_SHIFT (5)
4972-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4973+#define L1_CACHE_SHIFT 5
4974+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4975
4976 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4977 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4978diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4979index 0c8e553..112d734 100644
4980--- a/arch/ia64/Kconfig
4981+++ b/arch/ia64/Kconfig
4982@@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4983 config KEXEC
4984 bool "kexec system call"
4985 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4986+ depends on !GRKERNSEC_KMEM
4987 help
4988 kexec is a system call that implements the ability to shutdown your
4989 current kernel, and to start another kernel. It is like a reboot
4990diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4991index 6e6fe18..a6ae668 100644
4992--- a/arch/ia64/include/asm/atomic.h
4993+++ b/arch/ia64/include/asm/atomic.h
4994@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4995 #define atomic64_inc(v) atomic64_add(1, (v))
4996 #define atomic64_dec(v) atomic64_sub(1, (v))
4997
4998+#define atomic64_read_unchecked(v) atomic64_read(v)
4999+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5000+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5001+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5002+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5003+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5004+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5005+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5006+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5007+
5008 /* Atomic operations are already serializing */
5009 #define smp_mb__before_atomic_dec() barrier()
5010 #define smp_mb__after_atomic_dec() barrier()
5011diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5012index 988254a..e1ee885 100644
5013--- a/arch/ia64/include/asm/cache.h
5014+++ b/arch/ia64/include/asm/cache.h
5015@@ -1,6 +1,7 @@
5016 #ifndef _ASM_IA64_CACHE_H
5017 #define _ASM_IA64_CACHE_H
5018
5019+#include <linux/const.h>
5020
5021 /*
5022 * Copyright (C) 1998-2000 Hewlett-Packard Co
5023@@ -9,7 +10,7 @@
5024
5025 /* Bytes per L1 (data) cache line. */
5026 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5027-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5028+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5029
5030 #ifdef CONFIG_SMP
5031 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5032diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5033index 5a83c5c..4d7f553 100644
5034--- a/arch/ia64/include/asm/elf.h
5035+++ b/arch/ia64/include/asm/elf.h
5036@@ -42,6 +42,13 @@
5037 */
5038 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5039
5040+#ifdef CONFIG_PAX_ASLR
5041+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5042+
5043+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5044+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5045+#endif
5046+
5047 #define PT_IA_64_UNWIND 0x70000001
5048
5049 /* IA-64 relocations: */
5050diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5051index 5767cdf..7462574 100644
5052--- a/arch/ia64/include/asm/pgalloc.h
5053+++ b/arch/ia64/include/asm/pgalloc.h
5054@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5055 pgd_val(*pgd_entry) = __pa(pud);
5056 }
5057
5058+static inline void
5059+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5060+{
5061+ pgd_populate(mm, pgd_entry, pud);
5062+}
5063+
5064 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5065 {
5066 return quicklist_alloc(0, GFP_KERNEL, NULL);
5067@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5068 pud_val(*pud_entry) = __pa(pmd);
5069 }
5070
5071+static inline void
5072+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5073+{
5074+ pud_populate(mm, pud_entry, pmd);
5075+}
5076+
5077 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5078 {
5079 return quicklist_alloc(0, GFP_KERNEL, NULL);
5080diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5081index 7935115..c0eca6a 100644
5082--- a/arch/ia64/include/asm/pgtable.h
5083+++ b/arch/ia64/include/asm/pgtable.h
5084@@ -12,7 +12,7 @@
5085 * David Mosberger-Tang <davidm@hpl.hp.com>
5086 */
5087
5088-
5089+#include <linux/const.h>
5090 #include <asm/mman.h>
5091 #include <asm/page.h>
5092 #include <asm/processor.h>
5093@@ -142,6 +142,17 @@
5094 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5095 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5096 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5097+
5098+#ifdef CONFIG_PAX_PAGEEXEC
5099+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5100+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5101+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5102+#else
5103+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5104+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5105+# define PAGE_COPY_NOEXEC PAGE_COPY
5106+#endif
5107+
5108 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5109 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5110 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5111diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5112index 45698cd..e8e2dbc 100644
5113--- a/arch/ia64/include/asm/spinlock.h
5114+++ b/arch/ia64/include/asm/spinlock.h
5115@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5116 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5117
5118 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5119- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5120+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5121 }
5122
5123 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5124diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5125index 449c8c0..3d4b1e9 100644
5126--- a/arch/ia64/include/asm/uaccess.h
5127+++ b/arch/ia64/include/asm/uaccess.h
5128@@ -70,6 +70,7 @@
5129 && ((segment).seg == KERNEL_DS.seg \
5130 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5131 })
5132+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5133 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5134
5135 /*
5136@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5137 static inline unsigned long
5138 __copy_to_user (void __user *to, const void *from, unsigned long count)
5139 {
5140+ if (count > INT_MAX)
5141+ return count;
5142+
5143+ if (!__builtin_constant_p(count))
5144+ check_object_size(from, count, true);
5145+
5146 return __copy_user(to, (__force void __user *) from, count);
5147 }
5148
5149 static inline unsigned long
5150 __copy_from_user (void *to, const void __user *from, unsigned long count)
5151 {
5152+ if (count > INT_MAX)
5153+ return count;
5154+
5155+ if (!__builtin_constant_p(count))
5156+ check_object_size(to, count, false);
5157+
5158 return __copy_user((__force void __user *) to, from, count);
5159 }
5160
5161@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5162 ({ \
5163 void __user *__cu_to = (to); \
5164 const void *__cu_from = (from); \
5165- long __cu_len = (n); \
5166+ unsigned long __cu_len = (n); \
5167 \
5168- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5169+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5170+ if (!__builtin_constant_p(n)) \
5171+ check_object_size(__cu_from, __cu_len, true); \
5172 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5173+ } \
5174 __cu_len; \
5175 })
5176
5177@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5178 ({ \
5179 void *__cu_to = (to); \
5180 const void __user *__cu_from = (from); \
5181- long __cu_len = (n); \
5182+ unsigned long __cu_len = (n); \
5183 \
5184 __chk_user_ptr(__cu_from); \
5185- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5186+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5187+ if (!__builtin_constant_p(n)) \
5188+ check_object_size(__cu_to, __cu_len, false); \
5189 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5190+ } \
5191 __cu_len; \
5192 })
5193
5194diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5195index 24603be..948052d 100644
5196--- a/arch/ia64/kernel/module.c
5197+++ b/arch/ia64/kernel/module.c
5198@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5199 void
5200 module_free (struct module *mod, void *module_region)
5201 {
5202- if (mod && mod->arch.init_unw_table &&
5203- module_region == mod->module_init) {
5204+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5205 unw_remove_unwind_table(mod->arch.init_unw_table);
5206 mod->arch.init_unw_table = NULL;
5207 }
5208@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5209 }
5210
5211 static inline int
5212+in_init_rx (const struct module *mod, uint64_t addr)
5213+{
5214+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5215+}
5216+
5217+static inline int
5218+in_init_rw (const struct module *mod, uint64_t addr)
5219+{
5220+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5221+}
5222+
5223+static inline int
5224 in_init (const struct module *mod, uint64_t addr)
5225 {
5226- return addr - (uint64_t) mod->module_init < mod->init_size;
5227+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5228+}
5229+
5230+static inline int
5231+in_core_rx (const struct module *mod, uint64_t addr)
5232+{
5233+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5234+}
5235+
5236+static inline int
5237+in_core_rw (const struct module *mod, uint64_t addr)
5238+{
5239+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5240 }
5241
5242 static inline int
5243 in_core (const struct module *mod, uint64_t addr)
5244 {
5245- return addr - (uint64_t) mod->module_core < mod->core_size;
5246+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5247 }
5248
5249 static inline int
5250@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5251 break;
5252
5253 case RV_BDREL:
5254- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5255+ if (in_init_rx(mod, val))
5256+ val -= (uint64_t) mod->module_init_rx;
5257+ else if (in_init_rw(mod, val))
5258+ val -= (uint64_t) mod->module_init_rw;
5259+ else if (in_core_rx(mod, val))
5260+ val -= (uint64_t) mod->module_core_rx;
5261+ else if (in_core_rw(mod, val))
5262+ val -= (uint64_t) mod->module_core_rw;
5263 break;
5264
5265 case RV_LTV:
5266@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5267 * addresses have been selected...
5268 */
5269 uint64_t gp;
5270- if (mod->core_size > MAX_LTOFF)
5271+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5272 /*
5273 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5274 * at the end of the module.
5275 */
5276- gp = mod->core_size - MAX_LTOFF / 2;
5277+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5278 else
5279- gp = mod->core_size / 2;
5280- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5281+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5282+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5283 mod->arch.gp = gp;
5284 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5285 }
5286diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5287index ab33328..f39506c 100644
5288--- a/arch/ia64/kernel/palinfo.c
5289+++ b/arch/ia64/kernel/palinfo.c
5290@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5291 return NOTIFY_OK;
5292 }
5293
5294-static struct notifier_block __refdata palinfo_cpu_notifier =
5295+static struct notifier_block palinfo_cpu_notifier =
5296 {
5297 .notifier_call = palinfo_cpu_callback,
5298 .priority = 0,
5299diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5300index 41e33f8..65180b2a 100644
5301--- a/arch/ia64/kernel/sys_ia64.c
5302+++ b/arch/ia64/kernel/sys_ia64.c
5303@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5304 unsigned long align_mask = 0;
5305 struct mm_struct *mm = current->mm;
5306 struct vm_unmapped_area_info info;
5307+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5308
5309 if (len > RGN_MAP_LIMIT)
5310 return -ENOMEM;
5311@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5312 if (REGION_NUMBER(addr) == RGN_HPAGE)
5313 addr = 0;
5314 #endif
5315+
5316+#ifdef CONFIG_PAX_RANDMMAP
5317+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5318+ addr = mm->free_area_cache;
5319+ else
5320+#endif
5321+
5322 if (!addr)
5323 addr = TASK_UNMAPPED_BASE;
5324
5325@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5326 info.high_limit = TASK_SIZE;
5327 info.align_mask = align_mask;
5328 info.align_offset = 0;
5329+ info.threadstack_offset = offset;
5330 return vm_unmapped_area(&info);
5331 }
5332
5333diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5334index 84f8a52..7c76178 100644
5335--- a/arch/ia64/kernel/vmlinux.lds.S
5336+++ b/arch/ia64/kernel/vmlinux.lds.S
5337@@ -192,7 +192,7 @@ SECTIONS {
5338 /* Per-cpu data: */
5339 . = ALIGN(PERCPU_PAGE_SIZE);
5340 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5341- __phys_per_cpu_start = __per_cpu_load;
5342+ __phys_per_cpu_start = per_cpu_load;
5343 /*
5344 * ensure percpu data fits
5345 * into percpu page size
5346diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5347index 7225dad..2a7c8256 100644
5348--- a/arch/ia64/mm/fault.c
5349+++ b/arch/ia64/mm/fault.c
5350@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5351 return pte_present(pte);
5352 }
5353
5354+#ifdef CONFIG_PAX_PAGEEXEC
5355+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5356+{
5357+ unsigned long i;
5358+
5359+ printk(KERN_ERR "PAX: bytes at PC: ");
5360+ for (i = 0; i < 8; i++) {
5361+ unsigned int c;
5362+ if (get_user(c, (unsigned int *)pc+i))
5363+ printk(KERN_CONT "???????? ");
5364+ else
5365+ printk(KERN_CONT "%08x ", c);
5366+ }
5367+ printk("\n");
5368+}
5369+#endif
5370+
5371 # define VM_READ_BIT 0
5372 # define VM_WRITE_BIT 1
5373 # define VM_EXEC_BIT 2
5374@@ -151,8 +168,21 @@ retry:
5375 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5376 goto bad_area;
5377
5378- if ((vma->vm_flags & mask) != mask)
5379+ if ((vma->vm_flags & mask) != mask) {
5380+
5381+#ifdef CONFIG_PAX_PAGEEXEC
5382+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5383+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5384+ goto bad_area;
5385+
5386+ up_read(&mm->mmap_sem);
5387+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5388+ do_group_exit(SIGKILL);
5389+ }
5390+#endif
5391+
5392 goto bad_area;
5393+ }
5394
5395 /*
5396 * If for any reason at all we couldn't handle the fault, make
5397diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5398index 68232db..6ca80af 100644
5399--- a/arch/ia64/mm/hugetlbpage.c
5400+++ b/arch/ia64/mm/hugetlbpage.c
5401@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5402 unsigned long pgoff, unsigned long flags)
5403 {
5404 struct vm_unmapped_area_info info;
5405+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5406
5407 if (len > RGN_MAP_LIMIT)
5408 return -ENOMEM;
5409@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5410 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5411 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5412 info.align_offset = 0;
5413+ info.threadstack_offset = offset;
5414 return vm_unmapped_area(&info);
5415 }
5416
5417diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5418index 25c3502..560dae7 100644
5419--- a/arch/ia64/mm/init.c
5420+++ b/arch/ia64/mm/init.c
5421@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5422 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5423 vma->vm_end = vma->vm_start + PAGE_SIZE;
5424 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5425+
5426+#ifdef CONFIG_PAX_PAGEEXEC
5427+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5428+ vma->vm_flags &= ~VM_EXEC;
5429+
5430+#ifdef CONFIG_PAX_MPROTECT
5431+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5432+ vma->vm_flags &= ~VM_MAYEXEC;
5433+#endif
5434+
5435+ }
5436+#endif
5437+
5438 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5439 down_write(&current->mm->mmap_sem);
5440 if (insert_vm_struct(current->mm, vma)) {
5441diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5442index 40b3ee9..8c2c112 100644
5443--- a/arch/m32r/include/asm/cache.h
5444+++ b/arch/m32r/include/asm/cache.h
5445@@ -1,8 +1,10 @@
5446 #ifndef _ASM_M32R_CACHE_H
5447 #define _ASM_M32R_CACHE_H
5448
5449+#include <linux/const.h>
5450+
5451 /* L1 cache line size */
5452 #define L1_CACHE_SHIFT 4
5453-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5454+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5455
5456 #endif /* _ASM_M32R_CACHE_H */
5457diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5458index 82abd15..d95ae5d 100644
5459--- a/arch/m32r/lib/usercopy.c
5460+++ b/arch/m32r/lib/usercopy.c
5461@@ -14,6 +14,9 @@
5462 unsigned long
5463 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5464 {
5465+ if ((long)n < 0)
5466+ return n;
5467+
5468 prefetch(from);
5469 if (access_ok(VERIFY_WRITE, to, n))
5470 __copy_user(to,from,n);
5471@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5472 unsigned long
5473 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5474 {
5475+ if ((long)n < 0)
5476+ return n;
5477+
5478 prefetchw(to);
5479 if (access_ok(VERIFY_READ, from, n))
5480 __copy_user_zeroing(to,from,n);
5481diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5482index 0395c51..5f26031 100644
5483--- a/arch/m68k/include/asm/cache.h
5484+++ b/arch/m68k/include/asm/cache.h
5485@@ -4,9 +4,11 @@
5486 #ifndef __ARCH_M68K_CACHE_H
5487 #define __ARCH_M68K_CACHE_H
5488
5489+#include <linux/const.h>
5490+
5491 /* bytes per L1 cache line */
5492 #define L1_CACHE_SHIFT 4
5493-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5494+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5495
5496 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5497
5498diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5499index 0424315..defcca9 100644
5500--- a/arch/metag/mm/hugetlbpage.c
5501+++ b/arch/metag/mm/hugetlbpage.c
5502@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5503 info.high_limit = TASK_SIZE;
5504 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5505 info.align_offset = 0;
5506+ info.threadstack_offset = 0;
5507 return vm_unmapped_area(&info);
5508 }
5509
5510diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5511index 4efe96a..60e8699 100644
5512--- a/arch/microblaze/include/asm/cache.h
5513+++ b/arch/microblaze/include/asm/cache.h
5514@@ -13,11 +13,12 @@
5515 #ifndef _ASM_MICROBLAZE_CACHE_H
5516 #define _ASM_MICROBLAZE_CACHE_H
5517
5518+#include <linux/const.h>
5519 #include <asm/registers.h>
5520
5521 #define L1_CACHE_SHIFT 5
5522 /* word-granular cache in microblaze */
5523-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5525
5526 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5527
5528diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5529index 95fa1f1..56a6fa2 100644
5530--- a/arch/mips/Kconfig
5531+++ b/arch/mips/Kconfig
5532@@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5533
5534 config KEXEC
5535 bool "Kexec system call"
5536+ depends on !GRKERNSEC_KMEM
5537 help
5538 kexec is a system call that implements the ability to shutdown your
5539 current kernel, and to start another kernel. It is like a reboot
5540diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5541index 02f2444..506969c 100644
5542--- a/arch/mips/cavium-octeon/dma-octeon.c
5543+++ b/arch/mips/cavium-octeon/dma-octeon.c
5544@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5545 if (dma_release_from_coherent(dev, order, vaddr))
5546 return;
5547
5548- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5549+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5550 }
5551
5552 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5553diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5554index 7eed2f2..c4e385d 100644
5555--- a/arch/mips/include/asm/atomic.h
5556+++ b/arch/mips/include/asm/atomic.h
5557@@ -21,15 +21,39 @@
5558 #include <asm/cmpxchg.h>
5559 #include <asm/war.h>
5560
5561+#ifdef CONFIG_GENERIC_ATOMIC64
5562+#include <asm-generic/atomic64.h>
5563+#endif
5564+
5565 #define ATOMIC_INIT(i) { (i) }
5566
5567+#ifdef CONFIG_64BIT
5568+#define _ASM_EXTABLE(from, to) \
5569+" .section __ex_table,\"a\"\n" \
5570+" .dword " #from ", " #to"\n" \
5571+" .previous\n"
5572+#else
5573+#define _ASM_EXTABLE(from, to) \
5574+" .section __ex_table,\"a\"\n" \
5575+" .word " #from ", " #to"\n" \
5576+" .previous\n"
5577+#endif
5578+
5579 /*
5580 * atomic_read - read atomic variable
5581 * @v: pointer of type atomic_t
5582 *
5583 * Atomically reads the value of @v.
5584 */
5585-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5586+static inline int atomic_read(const atomic_t *v)
5587+{
5588+ return (*(volatile const int *) &v->counter);
5589+}
5590+
5591+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5592+{
5593+ return (*(volatile const int *) &v->counter);
5594+}
5595
5596 /*
5597 * atomic_set - set atomic variable
5598@@ -38,7 +62,15 @@
5599 *
5600 * Atomically sets the value of @v to @i.
5601 */
5602-#define atomic_set(v, i) ((v)->counter = (i))
5603+static inline void atomic_set(atomic_t *v, int i)
5604+{
5605+ v->counter = i;
5606+}
5607+
5608+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5609+{
5610+ v->counter = i;
5611+}
5612
5613 /*
5614 * atomic_add - add integer to atomic variable
5615@@ -47,7 +79,67 @@
5616 *
5617 * Atomically adds @i to @v.
5618 */
5619-static __inline__ void atomic_add(int i, atomic_t * v)
5620+static __inline__ void atomic_add(int i, atomic_t *v)
5621+{
5622+ int temp;
5623+
5624+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5625+ __asm__ __volatile__(
5626+ " .set mips3 \n"
5627+ "1: ll %0, %1 # atomic_add \n"
5628+#ifdef CONFIG_PAX_REFCOUNT
5629+ /* Exception on overflow. */
5630+ "2: add %0, %2 \n"
5631+#else
5632+ " addu %0, %2 \n"
5633+#endif
5634+ " sc %0, %1 \n"
5635+ " beqzl %0, 1b \n"
5636+#ifdef CONFIG_PAX_REFCOUNT
5637+ "3: \n"
5638+ _ASM_EXTABLE(2b, 3b)
5639+#endif
5640+ " .set mips0 \n"
5641+ : "=&r" (temp), "+m" (v->counter)
5642+ : "Ir" (i));
5643+ } else if (kernel_uses_llsc) {
5644+ __asm__ __volatile__(
5645+ " .set mips3 \n"
5646+ "1: ll %0, %1 # atomic_add \n"
5647+#ifdef CONFIG_PAX_REFCOUNT
5648+ /* Exception on overflow. */
5649+ "2: add %0, %2 \n"
5650+#else
5651+ " addu %0, %2 \n"
5652+#endif
5653+ " sc %0, %1 \n"
5654+ " beqz %0, 1b \n"
5655+#ifdef CONFIG_PAX_REFCOUNT
5656+ "3: \n"
5657+ _ASM_EXTABLE(2b, 3b)
5658+#endif
5659+ " .set mips0 \n"
5660+ : "=&r" (temp), "+m" (v->counter)
5661+ : "Ir" (i));
5662+ } else {
5663+ unsigned long flags;
5664+
5665+ raw_local_irq_save(flags);
5666+ __asm__ __volatile__(
5667+#ifdef CONFIG_PAX_REFCOUNT
5668+ /* Exception on overflow. */
5669+ "1: add %0, %1 \n"
5670+ "2: \n"
5671+ _ASM_EXTABLE(1b, 2b)
5672+#else
5673+ " addu %0, %1 \n"
5674+#endif
5675+ : "+r" (v->counter) : "Ir" (i));
5676+ raw_local_irq_restore(flags);
5677+ }
5678+}
5679+
5680+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5681 {
5682 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5683 int temp;
5684@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5685 *
5686 * Atomically subtracts @i from @v.
5687 */
5688-static __inline__ void atomic_sub(int i, atomic_t * v)
5689+static __inline__ void atomic_sub(int i, atomic_t *v)
5690+{
5691+ int temp;
5692+
5693+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5694+ __asm__ __volatile__(
5695+ " .set mips3 \n"
5696+ "1: ll %0, %1 # atomic64_sub \n"
5697+#ifdef CONFIG_PAX_REFCOUNT
5698+ /* Exception on overflow. */
5699+ "2: sub %0, %2 \n"
5700+#else
5701+ " subu %0, %2 \n"
5702+#endif
5703+ " sc %0, %1 \n"
5704+ " beqzl %0, 1b \n"
5705+#ifdef CONFIG_PAX_REFCOUNT
5706+ "3: \n"
5707+ _ASM_EXTABLE(2b, 3b)
5708+#endif
5709+ " .set mips0 \n"
5710+ : "=&r" (temp), "+m" (v->counter)
5711+ : "Ir" (i));
5712+ } else if (kernel_uses_llsc) {
5713+ __asm__ __volatile__(
5714+ " .set mips3 \n"
5715+ "1: ll %0, %1 # atomic64_sub \n"
5716+#ifdef CONFIG_PAX_REFCOUNT
5717+ /* Exception on overflow. */
5718+ "2: sub %0, %2 \n"
5719+#else
5720+ " subu %0, %2 \n"
5721+#endif
5722+ " sc %0, %1 \n"
5723+ " beqz %0, 1b \n"
5724+#ifdef CONFIG_PAX_REFCOUNT
5725+ "3: \n"
5726+ _ASM_EXTABLE(2b, 3b)
5727+#endif
5728+ " .set mips0 \n"
5729+ : "=&r" (temp), "+m" (v->counter)
5730+ : "Ir" (i));
5731+ } else {
5732+ unsigned long flags;
5733+
5734+ raw_local_irq_save(flags);
5735+ __asm__ __volatile__(
5736+#ifdef CONFIG_PAX_REFCOUNT
5737+ /* Exception on overflow. */
5738+ "1: sub %0, %1 \n"
5739+ "2: \n"
5740+ _ASM_EXTABLE(1b, 2b)
5741+#else
5742+ " subu %0, %1 \n"
5743+#endif
5744+ : "+r" (v->counter) : "Ir" (i));
5745+ raw_local_irq_restore(flags);
5746+ }
5747+}
5748+
5749+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5750 {
5751 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5752 int temp;
5753@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5754 /*
5755 * Same as above, but return the result value
5756 */
5757-static __inline__ int atomic_add_return(int i, atomic_t * v)
5758+static __inline__ int atomic_add_return(int i, atomic_t *v)
5759+{
5760+ int result;
5761+ int temp;
5762+
5763+ smp_mb__before_llsc();
5764+
5765+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5766+ __asm__ __volatile__(
5767+ " .set mips3 \n"
5768+ "1: ll %1, %2 # atomic_add_return \n"
5769+#ifdef CONFIG_PAX_REFCOUNT
5770+ "2: add %0, %1, %3 \n"
5771+#else
5772+ " addu %0, %1, %3 \n"
5773+#endif
5774+ " sc %0, %2 \n"
5775+ " beqzl %0, 1b \n"
5776+#ifdef CONFIG_PAX_REFCOUNT
5777+ " b 4f \n"
5778+ " .set noreorder \n"
5779+ "3: b 5f \n"
5780+ " move %0, %1 \n"
5781+ " .set reorder \n"
5782+ _ASM_EXTABLE(2b, 3b)
5783+#endif
5784+ "4: addu %0, %1, %3 \n"
5785+#ifdef CONFIG_PAX_REFCOUNT
5786+ "5: \n"
5787+#endif
5788+ " .set mips0 \n"
5789+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5790+ : "Ir" (i));
5791+ } else if (kernel_uses_llsc) {
5792+ __asm__ __volatile__(
5793+ " .set mips3 \n"
5794+ "1: ll %1, %2 # atomic_add_return \n"
5795+#ifdef CONFIG_PAX_REFCOUNT
5796+ "2: add %0, %1, %3 \n"
5797+#else
5798+ " addu %0, %1, %3 \n"
5799+#endif
5800+ " sc %0, %2 \n"
5801+ " bnez %0, 4f \n"
5802+ " b 1b \n"
5803+#ifdef CONFIG_PAX_REFCOUNT
5804+ " .set noreorder \n"
5805+ "3: b 5f \n"
5806+ " move %0, %1 \n"
5807+ " .set reorder \n"
5808+ _ASM_EXTABLE(2b, 3b)
5809+#endif
5810+ "4: addu %0, %1, %3 \n"
5811+#ifdef CONFIG_PAX_REFCOUNT
5812+ "5: \n"
5813+#endif
5814+ " .set mips0 \n"
5815+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5816+ : "Ir" (i));
5817+ } else {
5818+ unsigned long flags;
5819+
5820+ raw_local_irq_save(flags);
5821+ __asm__ __volatile__(
5822+ " lw %0, %1 \n"
5823+#ifdef CONFIG_PAX_REFCOUNT
5824+ /* Exception on overflow. */
5825+ "1: add %0, %2 \n"
5826+#else
5827+ " addu %0, %2 \n"
5828+#endif
5829+ " sw %0, %1 \n"
5830+#ifdef CONFIG_PAX_REFCOUNT
5831+ /* Note: Dest reg is not modified on overflow */
5832+ "2: \n"
5833+ _ASM_EXTABLE(1b, 2b)
5834+#endif
5835+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5836+ raw_local_irq_restore(flags);
5837+ }
5838+
5839+ smp_llsc_mb();
5840+
5841+ return result;
5842+}
5843+
5844+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5845 {
5846 int result;
5847
5848@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5849 return result;
5850 }
5851
5852-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5853+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5854+{
5855+ int result;
5856+ int temp;
5857+
5858+ smp_mb__before_llsc();
5859+
5860+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5861+ __asm__ __volatile__(
5862+ " .set mips3 \n"
5863+ "1: ll %1, %2 # atomic_sub_return \n"
5864+#ifdef CONFIG_PAX_REFCOUNT
5865+ "2: sub %0, %1, %3 \n"
5866+#else
5867+ " subu %0, %1, %3 \n"
5868+#endif
5869+ " sc %0, %2 \n"
5870+ " beqzl %0, 1b \n"
5871+#ifdef CONFIG_PAX_REFCOUNT
5872+ " b 4f \n"
5873+ " .set noreorder \n"
5874+ "3: b 5f \n"
5875+ " move %0, %1 \n"
5876+ " .set reorder \n"
5877+ _ASM_EXTABLE(2b, 3b)
5878+#endif
5879+ "4: subu %0, %1, %3 \n"
5880+#ifdef CONFIG_PAX_REFCOUNT
5881+ "5: \n"
5882+#endif
5883+ " .set mips0 \n"
5884+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5885+ : "Ir" (i), "m" (v->counter)
5886+ : "memory");
5887+ } else if (kernel_uses_llsc) {
5888+ __asm__ __volatile__(
5889+ " .set mips3 \n"
5890+ "1: ll %1, %2 # atomic_sub_return \n"
5891+#ifdef CONFIG_PAX_REFCOUNT
5892+ "2: sub %0, %1, %3 \n"
5893+#else
5894+ " subu %0, %1, %3 \n"
5895+#endif
5896+ " sc %0, %2 \n"
5897+ " bnez %0, 4f \n"
5898+ " b 1b \n"
5899+#ifdef CONFIG_PAX_REFCOUNT
5900+ " .set noreorder \n"
5901+ "3: b 5f \n"
5902+ " move %0, %1 \n"
5903+ " .set reorder \n"
5904+ _ASM_EXTABLE(2b, 3b)
5905+#endif
5906+ "4: subu %0, %1, %3 \n"
5907+#ifdef CONFIG_PAX_REFCOUNT
5908+ "5: \n"
5909+#endif
5910+ " .set mips0 \n"
5911+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5912+ : "Ir" (i));
5913+ } else {
5914+ unsigned long flags;
5915+
5916+ raw_local_irq_save(flags);
5917+ __asm__ __volatile__(
5918+ " lw %0, %1 \n"
5919+#ifdef CONFIG_PAX_REFCOUNT
5920+ /* Exception on overflow. */
5921+ "1: sub %0, %2 \n"
5922+#else
5923+ " subu %0, %2 \n"
5924+#endif
5925+ " sw %0, %1 \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ /* Note: Dest reg is not modified on overflow */
5928+ "2: \n"
5929+ _ASM_EXTABLE(1b, 2b)
5930+#endif
5931+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5932+ raw_local_irq_restore(flags);
5933+ }
5934+
5935+ smp_llsc_mb();
5936+
5937+ return result;
5938+}
5939+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5940 {
5941 int result;
5942
5943@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5944 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5945 * The function returns the old value of @v minus @i.
5946 */
5947-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5948+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5949 {
5950 int result;
5951
5952@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5953 return result;
5954 }
5955
5956-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5957-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5958+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5959+{
5960+ return cmpxchg(&v->counter, old, new);
5961+}
5962+
5963+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5964+ int new)
5965+{
5966+ return cmpxchg(&(v->counter), old, new);
5967+}
5968+
5969+static inline int atomic_xchg(atomic_t *v, int new)
5970+{
5971+ return xchg(&v->counter, new);
5972+}
5973+
5974+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5975+{
5976+ return xchg(&(v->counter), new);
5977+}
5978
5979 /**
5980 * __atomic_add_unless - add unless the number is a given value
5981@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5982
5983 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5984 #define atomic_inc_return(v) atomic_add_return(1, (v))
5985+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5986+{
5987+ return atomic_add_return_unchecked(1, v);
5988+}
5989
5990 /*
5991 * atomic_sub_and_test - subtract value from variable and test result
5992@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5993 * other cases.
5994 */
5995 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5996+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5997+{
5998+ return atomic_add_return_unchecked(1, v) == 0;
5999+}
6000
6001 /*
6002 * atomic_dec_and_test - decrement by 1 and test
6003@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6004 * Atomically increments @v by 1.
6005 */
6006 #define atomic_inc(v) atomic_add(1, (v))
6007+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6008+{
6009+ atomic_add_unchecked(1, v);
6010+}
6011
6012 /*
6013 * atomic_dec - decrement and test
6014@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6015 * Atomically decrements @v by 1.
6016 */
6017 #define atomic_dec(v) atomic_sub(1, (v))
6018+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6019+{
6020+ atomic_sub_unchecked(1, v);
6021+}
6022
6023 /*
6024 * atomic_add_negative - add and test if negative
6025@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6026 * @v: pointer of type atomic64_t
6027 *
6028 */
6029-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6030+static inline long atomic64_read(const atomic64_t *v)
6031+{
6032+ return (*(volatile const long *) &v->counter);
6033+}
6034+
6035+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6036+{
6037+ return (*(volatile const long *) &v->counter);
6038+}
6039
6040 /*
6041 * atomic64_set - set atomic variable
6042 * @v: pointer of type atomic64_t
6043 * @i: required value
6044 */
6045-#define atomic64_set(v, i) ((v)->counter = (i))
6046+static inline void atomic64_set(atomic64_t *v, long i)
6047+{
6048+ v->counter = i;
6049+}
6050+
6051+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6052+{
6053+ v->counter = i;
6054+}
6055
6056 /*
6057 * atomic64_add - add integer to atomic variable
6058@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6059 *
6060 * Atomically adds @i to @v.
6061 */
6062-static __inline__ void atomic64_add(long i, atomic64_t * v)
6063+static __inline__ void atomic64_add(long i, atomic64_t *v)
6064+{
6065+ long temp;
6066+
6067+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6068+ __asm__ __volatile__(
6069+ " .set mips3 \n"
6070+ "1: lld %0, %1 # atomic64_add \n"
6071+#ifdef CONFIG_PAX_REFCOUNT
6072+ /* Exception on overflow. */
6073+ "2: dadd %0, %2 \n"
6074+#else
6075+ " daddu %0, %2 \n"
6076+#endif
6077+ " scd %0, %1 \n"
6078+ " beqzl %0, 1b \n"
6079+#ifdef CONFIG_PAX_REFCOUNT
6080+ "3: \n"
6081+ _ASM_EXTABLE(2b, 3b)
6082+#endif
6083+ " .set mips0 \n"
6084+ : "=&r" (temp), "+m" (v->counter)
6085+ : "Ir" (i));
6086+ } else if (kernel_uses_llsc) {
6087+ __asm__ __volatile__(
6088+ " .set mips3 \n"
6089+ "1: lld %0, %1 # atomic64_add \n"
6090+#ifdef CONFIG_PAX_REFCOUNT
6091+ /* Exception on overflow. */
6092+ "2: dadd %0, %2 \n"
6093+#else
6094+ " daddu %0, %2 \n"
6095+#endif
6096+ " scd %0, %1 \n"
6097+ " beqz %0, 1b \n"
6098+#ifdef CONFIG_PAX_REFCOUNT
6099+ "3: \n"
6100+ _ASM_EXTABLE(2b, 3b)
6101+#endif
6102+ " .set mips0 \n"
6103+ : "=&r" (temp), "+m" (v->counter)
6104+ : "Ir" (i));
6105+ } else {
6106+ unsigned long flags;
6107+
6108+ raw_local_irq_save(flags);
6109+ __asm__ __volatile__(
6110+#ifdef CONFIG_PAX_REFCOUNT
6111+ /* Exception on overflow. */
6112+ "1: dadd %0, %1 \n"
6113+ "2: \n"
6114+ _ASM_EXTABLE(1b, 2b)
6115+#else
6116+ " daddu %0, %1 \n"
6117+#endif
6118+ : "+r" (v->counter) : "Ir" (i));
6119+ raw_local_irq_restore(flags);
6120+ }
6121+}
6122+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6123 {
6124 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6125 long temp;
6126@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6127 *
6128 * Atomically subtracts @i from @v.
6129 */
6130-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6131+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6132+{
6133+ long temp;
6134+
6135+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6136+ __asm__ __volatile__(
6137+ " .set mips3 \n"
6138+ "1: lld %0, %1 # atomic64_sub \n"
6139+#ifdef CONFIG_PAX_REFCOUNT
6140+ /* Exception on overflow. */
6141+ "2: dsub %0, %2 \n"
6142+#else
6143+ " dsubu %0, %2 \n"
6144+#endif
6145+ " scd %0, %1 \n"
6146+ " beqzl %0, 1b \n"
6147+#ifdef CONFIG_PAX_REFCOUNT
6148+ "3: \n"
6149+ _ASM_EXTABLE(2b, 3b)
6150+#endif
6151+ " .set mips0 \n"
6152+ : "=&r" (temp), "+m" (v->counter)
6153+ : "Ir" (i));
6154+ } else if (kernel_uses_llsc) {
6155+ __asm__ __volatile__(
6156+ " .set mips3 \n"
6157+ "1: lld %0, %1 # atomic64_sub \n"
6158+#ifdef CONFIG_PAX_REFCOUNT
6159+ /* Exception on overflow. */
6160+ "2: dsub %0, %2 \n"
6161+#else
6162+ " dsubu %0, %2 \n"
6163+#endif
6164+ " scd %0, %1 \n"
6165+ " beqz %0, 1b \n"
6166+#ifdef CONFIG_PAX_REFCOUNT
6167+ "3: \n"
6168+ _ASM_EXTABLE(2b, 3b)
6169+#endif
6170+ " .set mips0 \n"
6171+ : "=&r" (temp), "+m" (v->counter)
6172+ : "Ir" (i));
6173+ } else {
6174+ unsigned long flags;
6175+
6176+ raw_local_irq_save(flags);
6177+ __asm__ __volatile__(
6178+#ifdef CONFIG_PAX_REFCOUNT
6179+ /* Exception on overflow. */
6180+ "1: dsub %0, %1 \n"
6181+ "2: \n"
6182+ _ASM_EXTABLE(1b, 2b)
6183+#else
6184+ " dsubu %0, %1 \n"
6185+#endif
6186+ : "+r" (v->counter) : "Ir" (i));
6187+ raw_local_irq_restore(flags);
6188+ }
6189+}
6190+
6191+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6192 {
6193 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6194 long temp;
6195@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6196 /*
6197 * Same as above, but return the result value
6198 */
6199-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6200+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6201+{
6202+ long result;
6203+ long temp;
6204+
6205+ smp_mb__before_llsc();
6206+
6207+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6208+ __asm__ __volatile__(
6209+ " .set mips3 \n"
6210+ "1: lld %1, %2 # atomic64_add_return \n"
6211+#ifdef CONFIG_PAX_REFCOUNT
6212+ "2: dadd %0, %1, %3 \n"
6213+#else
6214+ " daddu %0, %1, %3 \n"
6215+#endif
6216+ " scd %0, %2 \n"
6217+ " beqzl %0, 1b \n"
6218+#ifdef CONFIG_PAX_REFCOUNT
6219+ " b 4f \n"
6220+ " .set noreorder \n"
6221+ "3: b 5f \n"
6222+ " move %0, %1 \n"
6223+ " .set reorder \n"
6224+ _ASM_EXTABLE(2b, 3b)
6225+#endif
6226+ "4: daddu %0, %1, %3 \n"
6227+#ifdef CONFIG_PAX_REFCOUNT
6228+ "5: \n"
6229+#endif
6230+ " .set mips0 \n"
6231+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6232+ : "Ir" (i));
6233+ } else if (kernel_uses_llsc) {
6234+ __asm__ __volatile__(
6235+ " .set mips3 \n"
6236+ "1: lld %1, %2 # atomic64_add_return \n"
6237+#ifdef CONFIG_PAX_REFCOUNT
6238+ "2: dadd %0, %1, %3 \n"
6239+#else
6240+ " daddu %0, %1, %3 \n"
6241+#endif
6242+ " scd %0, %2 \n"
6243+ " bnez %0, 4f \n"
6244+ " b 1b \n"
6245+#ifdef CONFIG_PAX_REFCOUNT
6246+ " .set noreorder \n"
6247+ "3: b 5f \n"
6248+ " move %0, %1 \n"
6249+ " .set reorder \n"
6250+ _ASM_EXTABLE(2b, 3b)
6251+#endif
6252+ "4: daddu %0, %1, %3 \n"
6253+#ifdef CONFIG_PAX_REFCOUNT
6254+ "5: \n"
6255+#endif
6256+ " .set mips0 \n"
6257+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6258+ : "Ir" (i), "m" (v->counter)
6259+ : "memory");
6260+ } else {
6261+ unsigned long flags;
6262+
6263+ raw_local_irq_save(flags);
6264+ __asm__ __volatile__(
6265+ " ld %0, %1 \n"
6266+#ifdef CONFIG_PAX_REFCOUNT
6267+ /* Exception on overflow. */
6268+ "1: dadd %0, %2 \n"
6269+#else
6270+ " daddu %0, %2 \n"
6271+#endif
6272+ " sd %0, %1 \n"
6273+#ifdef CONFIG_PAX_REFCOUNT
6274+ /* Note: Dest reg is not modified on overflow */
6275+ "2: \n"
6276+ _ASM_EXTABLE(1b, 2b)
6277+#endif
6278+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6279+ raw_local_irq_restore(flags);
6280+ }
6281+
6282+ smp_llsc_mb();
6283+
6284+ return result;
6285+}
6286+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6287 {
6288 long result;
6289
6290@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6291 return result;
6292 }
6293
6294-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6295+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6296+{
6297+ long result;
6298+ long temp;
6299+
6300+ smp_mb__before_llsc();
6301+
6302+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6303+ long temp;
6304+
6305+ __asm__ __volatile__(
6306+ " .set mips3 \n"
6307+ "1: lld %1, %2 # atomic64_sub_return \n"
6308+#ifdef CONFIG_PAX_REFCOUNT
6309+ "2: dsub %0, %1, %3 \n"
6310+#else
6311+ " dsubu %0, %1, %3 \n"
6312+#endif
6313+ " scd %0, %2 \n"
6314+ " beqzl %0, 1b \n"
6315+#ifdef CONFIG_PAX_REFCOUNT
6316+ " b 4f \n"
6317+ " .set noreorder \n"
6318+ "3: b 5f \n"
6319+ " move %0, %1 \n"
6320+ " .set reorder \n"
6321+ _ASM_EXTABLE(2b, 3b)
6322+#endif
6323+ "4: dsubu %0, %1, %3 \n"
6324+#ifdef CONFIG_PAX_REFCOUNT
6325+ "5: \n"
6326+#endif
6327+ " .set mips0 \n"
6328+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6329+ : "Ir" (i), "m" (v->counter)
6330+ : "memory");
6331+ } else if (kernel_uses_llsc) {
6332+ __asm__ __volatile__(
6333+ " .set mips3 \n"
6334+ "1: lld %1, %2 # atomic64_sub_return \n"
6335+#ifdef CONFIG_PAX_REFCOUNT
6336+ "2: dsub %0, %1, %3 \n"
6337+#else
6338+ " dsubu %0, %1, %3 \n"
6339+#endif
6340+ " scd %0, %2 \n"
6341+ " bnez %0, 4f \n"
6342+ " b 1b \n"
6343+#ifdef CONFIG_PAX_REFCOUNT
6344+ " .set noreorder \n"
6345+ "3: b 5f \n"
6346+ " move %0, %1 \n"
6347+ " .set reorder \n"
6348+ _ASM_EXTABLE(2b, 3b)
6349+#endif
6350+ "4: dsubu %0, %1, %3 \n"
6351+#ifdef CONFIG_PAX_REFCOUNT
6352+ "5: \n"
6353+#endif
6354+ " .set mips0 \n"
6355+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6356+ : "Ir" (i), "m" (v->counter)
6357+ : "memory");
6358+ } else {
6359+ unsigned long flags;
6360+
6361+ raw_local_irq_save(flags);
6362+ __asm__ __volatile__(
6363+ " ld %0, %1 \n"
6364+#ifdef CONFIG_PAX_REFCOUNT
6365+ /* Exception on overflow. */
6366+ "1: dsub %0, %2 \n"
6367+#else
6368+ " dsubu %0, %2 \n"
6369+#endif
6370+ " sd %0, %1 \n"
6371+#ifdef CONFIG_PAX_REFCOUNT
6372+ /* Note: Dest reg is not modified on overflow */
6373+ "2: \n"
6374+ _ASM_EXTABLE(1b, 2b)
6375+#endif
6376+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6377+ raw_local_irq_restore(flags);
6378+ }
6379+
6380+ smp_llsc_mb();
6381+
6382+ return result;
6383+}
6384+
6385+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6386 {
6387 long result;
6388
6389@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6390 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6391 * The function returns the old value of @v minus @i.
6392 */
6393-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6394+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6395 {
6396 long result;
6397
6398@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6399 return result;
6400 }
6401
6402-#define atomic64_cmpxchg(v, o, n) \
6403- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6404-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6405+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6406+{
6407+ return cmpxchg(&v->counter, old, new);
6408+}
6409+
6410+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6411+ long new)
6412+{
6413+ return cmpxchg(&(v->counter), old, new);
6414+}
6415+
6416+static inline long atomic64_xchg(atomic64_t *v, long new)
6417+{
6418+ return xchg(&v->counter, new);
6419+}
6420+
6421+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6422+{
6423+ return xchg(&(v->counter), new);
6424+}
6425
6426 /**
6427 * atomic64_add_unless - add unless the number is a given value
6428@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6429
6430 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6431 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6432+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6433
6434 /*
6435 * atomic64_sub_and_test - subtract value from variable and test result
6436@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6437 * other cases.
6438 */
6439 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6440+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6441
6442 /*
6443 * atomic64_dec_and_test - decrement by 1 and test
6444@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6445 * Atomically increments @v by 1.
6446 */
6447 #define atomic64_inc(v) atomic64_add(1, (v))
6448+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6449
6450 /*
6451 * atomic64_dec - decrement and test
6452@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6453 * Atomically decrements @v by 1.
6454 */
6455 #define atomic64_dec(v) atomic64_sub(1, (v))
6456+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6457
6458 /*
6459 * atomic64_add_negative - add and test if negative
6460diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6461index b4db69f..8f3b093 100644
6462--- a/arch/mips/include/asm/cache.h
6463+++ b/arch/mips/include/asm/cache.h
6464@@ -9,10 +9,11 @@
6465 #ifndef _ASM_CACHE_H
6466 #define _ASM_CACHE_H
6467
6468+#include <linux/const.h>
6469 #include <kmalloc.h>
6470
6471 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6472-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6473+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6474
6475 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6476 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6477diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6478index d414405..6bb4ba2 100644
6479--- a/arch/mips/include/asm/elf.h
6480+++ b/arch/mips/include/asm/elf.h
6481@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6482 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6483 #endif
6484
6485+#ifdef CONFIG_PAX_ASLR
6486+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6487+
6488+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6489+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6490+#endif
6491+
6492 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6493 struct linux_binprm;
6494 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6495 int uses_interp);
6496
6497-struct mm_struct;
6498-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6499-#define arch_randomize_brk arch_randomize_brk
6500-
6501 #endif /* _ASM_ELF_H */
6502diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6503index c1f6afa..38cc6e9 100644
6504--- a/arch/mips/include/asm/exec.h
6505+++ b/arch/mips/include/asm/exec.h
6506@@ -12,6 +12,6 @@
6507 #ifndef _ASM_EXEC_H
6508 #define _ASM_EXEC_H
6509
6510-extern unsigned long arch_align_stack(unsigned long sp);
6511+#define arch_align_stack(x) ((x) & ~0xfUL)
6512
6513 #endif /* _ASM_EXEC_H */
6514diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6515index 9e8ef59..1139d6b 100644
6516--- a/arch/mips/include/asm/hw_irq.h
6517+++ b/arch/mips/include/asm/hw_irq.h
6518@@ -10,7 +10,7 @@
6519
6520 #include <linux/atomic.h>
6521
6522-extern atomic_t irq_err_count;
6523+extern atomic_unchecked_t irq_err_count;
6524
6525 /*
6526 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6527diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6528index d44622c..64990d2 100644
6529--- a/arch/mips/include/asm/local.h
6530+++ b/arch/mips/include/asm/local.h
6531@@ -12,15 +12,25 @@ typedef struct
6532 atomic_long_t a;
6533 } local_t;
6534
6535+typedef struct {
6536+ atomic_long_unchecked_t a;
6537+} local_unchecked_t;
6538+
6539 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6540
6541 #define local_read(l) atomic_long_read(&(l)->a)
6542+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6543 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6544+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6545
6546 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6547+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6548 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6549+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6550 #define local_inc(l) atomic_long_inc(&(l)->a)
6551+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6552 #define local_dec(l) atomic_long_dec(&(l)->a)
6553+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6554
6555 /*
6556 * Same as above, but return the result value
6557@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6558 return result;
6559 }
6560
6561+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6562+{
6563+ unsigned long result;
6564+
6565+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6566+ unsigned long temp;
6567+
6568+ __asm__ __volatile__(
6569+ " .set mips3 \n"
6570+ "1:" __LL "%1, %2 # local_add_return \n"
6571+ " addu %0, %1, %3 \n"
6572+ __SC "%0, %2 \n"
6573+ " beqzl %0, 1b \n"
6574+ " addu %0, %1, %3 \n"
6575+ " .set mips0 \n"
6576+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6577+ : "Ir" (i), "m" (l->a.counter)
6578+ : "memory");
6579+ } else if (kernel_uses_llsc) {
6580+ unsigned long temp;
6581+
6582+ __asm__ __volatile__(
6583+ " .set mips3 \n"
6584+ "1:" __LL "%1, %2 # local_add_return \n"
6585+ " addu %0, %1, %3 \n"
6586+ __SC "%0, %2 \n"
6587+ " beqz %0, 1b \n"
6588+ " addu %0, %1, %3 \n"
6589+ " .set mips0 \n"
6590+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6591+ : "Ir" (i), "m" (l->a.counter)
6592+ : "memory");
6593+ } else {
6594+ unsigned long flags;
6595+
6596+ local_irq_save(flags);
6597+ result = l->a.counter;
6598+ result += i;
6599+ l->a.counter = result;
6600+ local_irq_restore(flags);
6601+ }
6602+
6603+ return result;
6604+}
6605+
6606 static __inline__ long local_sub_return(long i, local_t * l)
6607 {
6608 unsigned long result;
6609@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6610
6611 #define local_cmpxchg(l, o, n) \
6612 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6613+#define local_cmpxchg_unchecked(l, o, n) \
6614+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6615 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6616
6617 /**
6618diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6619index 5e08bcc..cfedefc 100644
6620--- a/arch/mips/include/asm/page.h
6621+++ b/arch/mips/include/asm/page.h
6622@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6623 #ifdef CONFIG_CPU_MIPS32
6624 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6625 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6626- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6627+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6628 #else
6629 typedef struct { unsigned long long pte; } pte_t;
6630 #define pte_val(x) ((x).pte)
6631diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6632index b336037..5b874cc 100644
6633--- a/arch/mips/include/asm/pgalloc.h
6634+++ b/arch/mips/include/asm/pgalloc.h
6635@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6636 {
6637 set_pud(pud, __pud((unsigned long)pmd));
6638 }
6639+
6640+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6641+{
6642+ pud_populate(mm, pud, pmd);
6643+}
6644 #endif
6645
6646 /*
6647diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6648index 008324d..f67c239 100644
6649--- a/arch/mips/include/asm/pgtable.h
6650+++ b/arch/mips/include/asm/pgtable.h
6651@@ -20,6 +20,9 @@
6652 #include <asm/io.h>
6653 #include <asm/pgtable-bits.h>
6654
6655+#define ktla_ktva(addr) (addr)
6656+#define ktva_ktla(addr) (addr)
6657+
6658 struct mm_struct;
6659 struct vm_area_struct;
6660
6661diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6662index 25da651..ae2a259 100644
6663--- a/arch/mips/include/asm/smtc_proc.h
6664+++ b/arch/mips/include/asm/smtc_proc.h
6665@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6666
6667 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6668
6669-extern atomic_t smtc_fpu_recoveries;
6670+extern atomic_unchecked_t smtc_fpu_recoveries;
6671
6672 #endif /* __ASM_SMTC_PROC_H */
6673diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6674index 24846f9..61c49f0 100644
6675--- a/arch/mips/include/asm/thread_info.h
6676+++ b/arch/mips/include/asm/thread_info.h
6677@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6678 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6679 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6680 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6681+/* li takes a 32bit immediate */
6682+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6683 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6684
6685 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6686@@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6687 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6688 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6689 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6690+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6691
6692 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6693- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6694+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6695
6696 /* work to do in syscall_trace_leave() */
6697 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6698- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6699+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6700
6701 /* work to do on interrupt/exception return */
6702 #define _TIF_WORK_MASK \
6703@@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6704 /* work to do on any return to u-space */
6705 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6706 _TIF_WORK_SYSCALL_EXIT | \
6707- _TIF_SYSCALL_TRACEPOINT)
6708+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6709
6710 /*
6711 * We stash processor id into a COP0 register to retrieve it fast
6712diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6713index f3fa375..3af6637 100644
6714--- a/arch/mips/include/asm/uaccess.h
6715+++ b/arch/mips/include/asm/uaccess.h
6716@@ -128,6 +128,7 @@ extern u64 __ua_limit;
6717 __ok == 0; \
6718 })
6719
6720+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6721 #define access_ok(type, addr, size) \
6722 likely(__access_ok((addr), (size), __access_mask))
6723
6724diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6725index 1188e00..41cf144 100644
6726--- a/arch/mips/kernel/binfmt_elfn32.c
6727+++ b/arch/mips/kernel/binfmt_elfn32.c
6728@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6729 #undef ELF_ET_DYN_BASE
6730 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6731
6732+#ifdef CONFIG_PAX_ASLR
6733+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6734+
6735+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6736+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6737+#endif
6738+
6739 #include <asm/processor.h>
6740 #include <linux/module.h>
6741 #include <linux/elfcore.h>
6742diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6743index 7faf5f2..f3d3cf4 100644
6744--- a/arch/mips/kernel/binfmt_elfo32.c
6745+++ b/arch/mips/kernel/binfmt_elfo32.c
6746@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6747 #undef ELF_ET_DYN_BASE
6748 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6749
6750+#ifdef CONFIG_PAX_ASLR
6751+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6752+
6753+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6754+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6755+#endif
6756+
6757 #include <asm/processor.h>
6758
6759 /*
6760diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6761index 2b91fe8..fe4f6b4 100644
6762--- a/arch/mips/kernel/i8259.c
6763+++ b/arch/mips/kernel/i8259.c
6764@@ -205,7 +205,7 @@ spurious_8259A_irq:
6765 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6766 spurious_irq_mask |= irqmask;
6767 }
6768- atomic_inc(&irq_err_count);
6769+ atomic_inc_unchecked(&irq_err_count);
6770 /*
6771 * Theoretically we do not have to handle this IRQ,
6772 * but in Linux this does not cause problems and is
6773diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6774index 44a1f79..2bd6aa3 100644
6775--- a/arch/mips/kernel/irq-gt641xx.c
6776+++ b/arch/mips/kernel/irq-gt641xx.c
6777@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6778 }
6779 }
6780
6781- atomic_inc(&irq_err_count);
6782+ atomic_inc_unchecked(&irq_err_count);
6783 }
6784
6785 void __init gt641xx_irq_init(void)
6786diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6787index d1fea7a..2e591b0 100644
6788--- a/arch/mips/kernel/irq.c
6789+++ b/arch/mips/kernel/irq.c
6790@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6791 printk("unexpected IRQ # %d\n", irq);
6792 }
6793
6794-atomic_t irq_err_count;
6795+atomic_unchecked_t irq_err_count;
6796
6797 int arch_show_interrupts(struct seq_file *p, int prec)
6798 {
6799- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6800+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6801 return 0;
6802 }
6803
6804 asmlinkage void spurious_interrupt(void)
6805 {
6806- atomic_inc(&irq_err_count);
6807+ atomic_inc_unchecked(&irq_err_count);
6808 }
6809
6810 void __init init_IRQ(void)
6811@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6812 #endif
6813 }
6814
6815+
6816 #ifdef DEBUG_STACKOVERFLOW
6817+extern void gr_handle_kernel_exploit(void);
6818+
6819 static inline void check_stack_overflow(void)
6820 {
6821 unsigned long sp;
6822@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6823 printk("do_IRQ: stack overflow: %ld\n",
6824 sp - sizeof(struct thread_info));
6825 dump_stack();
6826+ gr_handle_kernel_exploit();
6827 }
6828 }
6829 #else
6830diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6831index 6ae540e..b7396dc 100644
6832--- a/arch/mips/kernel/process.c
6833+++ b/arch/mips/kernel/process.c
6834@@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6835 out:
6836 return pc;
6837 }
6838-
6839-/*
6840- * Don't forget that the stack pointer must be aligned on a 8 bytes
6841- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6842- */
6843-unsigned long arch_align_stack(unsigned long sp)
6844-{
6845- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6846- sp -= get_random_int() & ~PAGE_MASK;
6847-
6848- return sp & ALMASK;
6849-}
6850diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6851index 7da9b76..21578be 100644
6852--- a/arch/mips/kernel/ptrace.c
6853+++ b/arch/mips/kernel/ptrace.c
6854@@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6855 return ret;
6856 }
6857
6858+#ifdef CONFIG_GRKERNSEC_SETXID
6859+extern void gr_delayed_cred_worker(void);
6860+#endif
6861+
6862 /*
6863 * Notification of system call entry/exit
6864 * - triggered by current->work.syscall_trace
6865@@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6866 tracehook_report_syscall_entry(regs))
6867 ret = -1;
6868
6869+#ifdef CONFIG_GRKERNSEC_SETXID
6870+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6871+ gr_delayed_cred_worker();
6872+#endif
6873+
6874 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6875 trace_sys_enter(regs, regs->regs[2]);
6876
6877diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6878index 07fc524..b9d7f28 100644
6879--- a/arch/mips/kernel/reset.c
6880+++ b/arch/mips/kernel/reset.c
6881@@ -13,6 +13,7 @@
6882 #include <linux/reboot.h>
6883
6884 #include <asm/reboot.h>
6885+#include <asm/bug.h>
6886
6887 /*
6888 * Urgs ... Too many MIPS machines to handle this in a generic way.
6889@@ -29,16 +30,19 @@ void machine_restart(char *command)
6890 {
6891 if (_machine_restart)
6892 _machine_restart(command);
6893+ BUG();
6894 }
6895
6896 void machine_halt(void)
6897 {
6898 if (_machine_halt)
6899 _machine_halt();
6900+ BUG();
6901 }
6902
6903 void machine_power_off(void)
6904 {
6905 if (pm_power_off)
6906 pm_power_off();
6907+ BUG();
6908 }
6909diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6910index c10aa84..9ec2e60 100644
6911--- a/arch/mips/kernel/smtc-proc.c
6912+++ b/arch/mips/kernel/smtc-proc.c
6913@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6914
6915 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6916
6917-atomic_t smtc_fpu_recoveries;
6918+atomic_unchecked_t smtc_fpu_recoveries;
6919
6920 static int smtc_proc_show(struct seq_file *m, void *v)
6921 {
6922@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6923 for(i = 0; i < NR_CPUS; i++)
6924 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6925 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6926- atomic_read(&smtc_fpu_recoveries));
6927+ atomic_read_unchecked(&smtc_fpu_recoveries));
6928 return 0;
6929 }
6930
6931@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6932 smtc_cpu_stats[i].selfipis = 0;
6933 }
6934
6935- atomic_set(&smtc_fpu_recoveries, 0);
6936+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6937
6938 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6939 }
6940diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6941index dfc1b91..11a2c07 100644
6942--- a/arch/mips/kernel/smtc.c
6943+++ b/arch/mips/kernel/smtc.c
6944@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6945 }
6946 smtc_ipi_qdump();
6947 printk("%d Recoveries of \"stolen\" FPU\n",
6948- atomic_read(&smtc_fpu_recoveries));
6949+ atomic_read_unchecked(&smtc_fpu_recoveries));
6950 }
6951
6952
6953diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6954index c24ad5f..9983ab2 100644
6955--- a/arch/mips/kernel/sync-r4k.c
6956+++ b/arch/mips/kernel/sync-r4k.c
6957@@ -20,8 +20,8 @@
6958 #include <asm/mipsregs.h>
6959
6960 static atomic_t count_start_flag = ATOMIC_INIT(0);
6961-static atomic_t count_count_start = ATOMIC_INIT(0);
6962-static atomic_t count_count_stop = ATOMIC_INIT(0);
6963+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6964+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6965 static atomic_t count_reference = ATOMIC_INIT(0);
6966
6967 #define COUNTON 100
6968@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6969
6970 for (i = 0; i < NR_LOOPS; i++) {
6971 /* slaves loop on '!= 2' */
6972- while (atomic_read(&count_count_start) != 1)
6973+ while (atomic_read_unchecked(&count_count_start) != 1)
6974 mb();
6975- atomic_set(&count_count_stop, 0);
6976+ atomic_set_unchecked(&count_count_stop, 0);
6977 smp_wmb();
6978
6979 /* this lets the slaves write their count register */
6980- atomic_inc(&count_count_start);
6981+ atomic_inc_unchecked(&count_count_start);
6982
6983 /*
6984 * Everyone initialises count in the last loop:
6985@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6986 /*
6987 * Wait for all slaves to leave the synchronization point:
6988 */
6989- while (atomic_read(&count_count_stop) != 1)
6990+ while (atomic_read_unchecked(&count_count_stop) != 1)
6991 mb();
6992- atomic_set(&count_count_start, 0);
6993+ atomic_set_unchecked(&count_count_start, 0);
6994 smp_wmb();
6995- atomic_inc(&count_count_stop);
6996+ atomic_inc_unchecked(&count_count_stop);
6997 }
6998 /* Arrange for an interrupt in a short while */
6999 write_c0_compare(read_c0_count() + COUNTON);
7000@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7001 initcount = atomic_read(&count_reference);
7002
7003 for (i = 0; i < NR_LOOPS; i++) {
7004- atomic_inc(&count_count_start);
7005- while (atomic_read(&count_count_start) != 2)
7006+ atomic_inc_unchecked(&count_count_start);
7007+ while (atomic_read_unchecked(&count_count_start) != 2)
7008 mb();
7009
7010 /*
7011@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7012 if (i == NR_LOOPS-1)
7013 write_c0_count(initcount);
7014
7015- atomic_inc(&count_count_stop);
7016- while (atomic_read(&count_count_stop) != 2)
7017+ atomic_inc_unchecked(&count_count_stop);
7018+ while (atomic_read_unchecked(&count_count_stop) != 2)
7019 mb();
7020 }
7021 /* Arrange for an interrupt in a short while */
7022diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7023index e0b4996..6b43ce7 100644
7024--- a/arch/mips/kernel/traps.c
7025+++ b/arch/mips/kernel/traps.c
7026@@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7027 siginfo_t info;
7028
7029 prev_state = exception_enter();
7030- die_if_kernel("Integer overflow", regs);
7031+ if (unlikely(!user_mode(regs))) {
7032+
7033+#ifdef CONFIG_PAX_REFCOUNT
7034+ if (fixup_exception(regs)) {
7035+ pax_report_refcount_overflow(regs);
7036+ exception_exit(prev_state);
7037+ return;
7038+ }
7039+#endif
7040+
7041+ die("Integer overflow", regs);
7042+ }
7043
7044 info.si_code = FPE_INTOVF;
7045 info.si_signo = SIGFPE;
7046diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7047index becc42b..9e43d4b 100644
7048--- a/arch/mips/mm/fault.c
7049+++ b/arch/mips/mm/fault.c
7050@@ -28,6 +28,23 @@
7051 #include <asm/highmem.h> /* For VMALLOC_END */
7052 #include <linux/kdebug.h>
7053
7054+#ifdef CONFIG_PAX_PAGEEXEC
7055+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7056+{
7057+ unsigned long i;
7058+
7059+ printk(KERN_ERR "PAX: bytes at PC: ");
7060+ for (i = 0; i < 5; i++) {
7061+ unsigned int c;
7062+ if (get_user(c, (unsigned int *)pc+i))
7063+ printk(KERN_CONT "???????? ");
7064+ else
7065+ printk(KERN_CONT "%08x ", c);
7066+ }
7067+ printk("\n");
7068+}
7069+#endif
7070+
7071 /*
7072 * This routine handles page faults. It determines the address,
7073 * and the problem, and then passes it off to one of the appropriate
7074@@ -199,6 +216,14 @@ bad_area:
7075 bad_area_nosemaphore:
7076 /* User mode accesses just cause a SIGSEGV */
7077 if (user_mode(regs)) {
7078+
7079+#ifdef CONFIG_PAX_PAGEEXEC
7080+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7081+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7082+ do_group_exit(SIGKILL);
7083+ }
7084+#endif
7085+
7086 tsk->thread.cp0_badvaddr = address;
7087 tsk->thread.error_code = write;
7088 #if 0
7089diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7090index f1baadd..5472dca 100644
7091--- a/arch/mips/mm/mmap.c
7092+++ b/arch/mips/mm/mmap.c
7093@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7094 struct vm_area_struct *vma;
7095 unsigned long addr = addr0;
7096 int do_color_align;
7097+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7098 struct vm_unmapped_area_info info;
7099
7100 if (unlikely(len > TASK_SIZE))
7101@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7102 do_color_align = 1;
7103
7104 /* requesting a specific address */
7105+
7106+#ifdef CONFIG_PAX_RANDMMAP
7107+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7108+#endif
7109+
7110 if (addr) {
7111 if (do_color_align)
7112 addr = COLOUR_ALIGN(addr, pgoff);
7113@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7114 addr = PAGE_ALIGN(addr);
7115
7116 vma = find_vma(mm, addr);
7117- if (TASK_SIZE - len >= addr &&
7118- (!vma || addr + len <= vma->vm_start))
7119+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7120 return addr;
7121 }
7122
7123 info.length = len;
7124 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7125 info.align_offset = pgoff << PAGE_SHIFT;
7126+ info.threadstack_offset = offset;
7127
7128 if (dir == DOWN) {
7129 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7130@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7131 {
7132 unsigned long random_factor = 0UL;
7133
7134+#ifdef CONFIG_PAX_RANDMMAP
7135+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7136+#endif
7137+
7138 if (current->flags & PF_RANDOMIZE) {
7139 random_factor = get_random_int();
7140 random_factor = random_factor << PAGE_SHIFT;
7141@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7142
7143 if (mmap_is_legacy()) {
7144 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7145+
7146+#ifdef CONFIG_PAX_RANDMMAP
7147+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7148+ mm->mmap_base += mm->delta_mmap;
7149+#endif
7150+
7151 mm->get_unmapped_area = arch_get_unmapped_area;
7152 } else {
7153 mm->mmap_base = mmap_base(random_factor);
7154+
7155+#ifdef CONFIG_PAX_RANDMMAP
7156+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7157+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7158+#endif
7159+
7160 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7161 }
7162 }
7163
7164-static inline unsigned long brk_rnd(void)
7165-{
7166- unsigned long rnd = get_random_int();
7167-
7168- rnd = rnd << PAGE_SHIFT;
7169- /* 8MB for 32bit, 256MB for 64bit */
7170- if (TASK_IS_32BIT_ADDR)
7171- rnd = rnd & 0x7ffffful;
7172- else
7173- rnd = rnd & 0xffffffful;
7174-
7175- return rnd;
7176-}
7177-
7178-unsigned long arch_randomize_brk(struct mm_struct *mm)
7179-{
7180- unsigned long base = mm->brk;
7181- unsigned long ret;
7182-
7183- ret = PAGE_ALIGN(base + brk_rnd());
7184-
7185- if (ret < mm->brk)
7186- return mm->brk;
7187-
7188- return ret;
7189-}
7190-
7191 int __virt_addr_valid(const volatile void *kaddr)
7192 {
7193 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7194diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7195index 59cccd9..f39ac2f 100644
7196--- a/arch/mips/pci/pci-octeon.c
7197+++ b/arch/mips/pci/pci-octeon.c
7198@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7199
7200
7201 static struct pci_ops octeon_pci_ops = {
7202- octeon_read_config,
7203- octeon_write_config,
7204+ .read = octeon_read_config,
7205+ .write = octeon_write_config,
7206 };
7207
7208 static struct resource octeon_pci_mem_resource = {
7209diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7210index 5e36c33..eb4a17b 100644
7211--- a/arch/mips/pci/pcie-octeon.c
7212+++ b/arch/mips/pci/pcie-octeon.c
7213@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7214 }
7215
7216 static struct pci_ops octeon_pcie0_ops = {
7217- octeon_pcie0_read_config,
7218- octeon_pcie0_write_config,
7219+ .read = octeon_pcie0_read_config,
7220+ .write = octeon_pcie0_write_config,
7221 };
7222
7223 static struct resource octeon_pcie0_mem_resource = {
7224@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7225 };
7226
7227 static struct pci_ops octeon_pcie1_ops = {
7228- octeon_pcie1_read_config,
7229- octeon_pcie1_write_config,
7230+ .read = octeon_pcie1_read_config,
7231+ .write = octeon_pcie1_write_config,
7232 };
7233
7234 static struct resource octeon_pcie1_mem_resource = {
7235@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7236 };
7237
7238 static struct pci_ops octeon_dummy_ops = {
7239- octeon_dummy_read_config,
7240- octeon_dummy_write_config,
7241+ .read = octeon_dummy_read_config,
7242+ .write = octeon_dummy_write_config,
7243 };
7244
7245 static struct resource octeon_dummy_mem_resource = {
7246diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7247index a2358b4..7cead4f 100644
7248--- a/arch/mips/sgi-ip27/ip27-nmi.c
7249+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7250@@ -187,9 +187,9 @@ void
7251 cont_nmi_dump(void)
7252 {
7253 #ifndef REAL_NMI_SIGNAL
7254- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7255+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7256
7257- atomic_inc(&nmied_cpus);
7258+ atomic_inc_unchecked(&nmied_cpus);
7259 #endif
7260 /*
7261 * Only allow 1 cpu to proceed
7262@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7263 udelay(10000);
7264 }
7265 #else
7266- while (atomic_read(&nmied_cpus) != num_online_cpus());
7267+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7268 #endif
7269
7270 /*
7271diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7272index a046b30..6799527 100644
7273--- a/arch/mips/sni/rm200.c
7274+++ b/arch/mips/sni/rm200.c
7275@@ -270,7 +270,7 @@ spurious_8259A_irq:
7276 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7277 spurious_irq_mask |= irqmask;
7278 }
7279- atomic_inc(&irq_err_count);
7280+ atomic_inc_unchecked(&irq_err_count);
7281 /*
7282 * Theoretically we do not have to handle this IRQ,
7283 * but in Linux this does not cause problems and is
7284diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7285index 41e873b..34d33a7 100644
7286--- a/arch/mips/vr41xx/common/icu.c
7287+++ b/arch/mips/vr41xx/common/icu.c
7288@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7289
7290 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7291
7292- atomic_inc(&irq_err_count);
7293+ atomic_inc_unchecked(&irq_err_count);
7294
7295 return -1;
7296 }
7297diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7298index ae0e4ee..e8f0692 100644
7299--- a/arch/mips/vr41xx/common/irq.c
7300+++ b/arch/mips/vr41xx/common/irq.c
7301@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7302 irq_cascade_t *cascade;
7303
7304 if (irq >= NR_IRQS) {
7305- atomic_inc(&irq_err_count);
7306+ atomic_inc_unchecked(&irq_err_count);
7307 return;
7308 }
7309
7310@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7311 ret = cascade->get_irq(irq);
7312 irq = ret;
7313 if (ret < 0)
7314- atomic_inc(&irq_err_count);
7315+ atomic_inc_unchecked(&irq_err_count);
7316 else
7317 irq_dispatch(irq);
7318 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7319diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7320index 967d144..db12197 100644
7321--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7322+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7323@@ -11,12 +11,14 @@
7324 #ifndef _ASM_PROC_CACHE_H
7325 #define _ASM_PROC_CACHE_H
7326
7327+#include <linux/const.h>
7328+
7329 /* L1 cache */
7330
7331 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7332 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7333-#define L1_CACHE_BYTES 16 /* bytes per entry */
7334 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7335+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7336 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7337
7338 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7339diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7340index bcb5df2..84fabd2 100644
7341--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7342+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7343@@ -16,13 +16,15 @@
7344 #ifndef _ASM_PROC_CACHE_H
7345 #define _ASM_PROC_CACHE_H
7346
7347+#include <linux/const.h>
7348+
7349 /*
7350 * L1 cache
7351 */
7352 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7353 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7354-#define L1_CACHE_BYTES 32 /* bytes per entry */
7355 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7356+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7357 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7358
7359 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7360diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7361index 4ce7a01..449202a 100644
7362--- a/arch/openrisc/include/asm/cache.h
7363+++ b/arch/openrisc/include/asm/cache.h
7364@@ -19,11 +19,13 @@
7365 #ifndef __ASM_OPENRISC_CACHE_H
7366 #define __ASM_OPENRISC_CACHE_H
7367
7368+#include <linux/const.h>
7369+
7370 /* FIXME: How can we replace these with values from the CPU...
7371 * they shouldn't be hard-coded!
7372 */
7373
7374-#define L1_CACHE_BYTES 16
7375 #define L1_CACHE_SHIFT 4
7376+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7377
7378 #endif /* __ASM_OPENRISC_CACHE_H */
7379diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7380index 472886c..00e7df9 100644
7381--- a/arch/parisc/include/asm/atomic.h
7382+++ b/arch/parisc/include/asm/atomic.h
7383@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7384 return dec;
7385 }
7386
7387+#define atomic64_read_unchecked(v) atomic64_read(v)
7388+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7389+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7390+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7391+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7392+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7393+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7394+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7395+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7396+
7397 #endif /* !CONFIG_64BIT */
7398
7399
7400diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7401index 47f11c7..3420df2 100644
7402--- a/arch/parisc/include/asm/cache.h
7403+++ b/arch/parisc/include/asm/cache.h
7404@@ -5,6 +5,7 @@
7405 #ifndef __ARCH_PARISC_CACHE_H
7406 #define __ARCH_PARISC_CACHE_H
7407
7408+#include <linux/const.h>
7409
7410 /*
7411 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7412@@ -15,13 +16,13 @@
7413 * just ruin performance.
7414 */
7415 #ifdef CONFIG_PA20
7416-#define L1_CACHE_BYTES 64
7417 #define L1_CACHE_SHIFT 6
7418 #else
7419-#define L1_CACHE_BYTES 32
7420 #define L1_CACHE_SHIFT 5
7421 #endif
7422
7423+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7424+
7425 #ifndef __ASSEMBLY__
7426
7427 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7428diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7429index 3391d06..c23a2cc 100644
7430--- a/arch/parisc/include/asm/elf.h
7431+++ b/arch/parisc/include/asm/elf.h
7432@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7433
7434 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7435
7436+#ifdef CONFIG_PAX_ASLR
7437+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7438+
7439+#define PAX_DELTA_MMAP_LEN 16
7440+#define PAX_DELTA_STACK_LEN 16
7441+#endif
7442+
7443 /* This yields a mask that user programs can use to figure out what
7444 instruction set this CPU supports. This could be done in user space,
7445 but it's not easy, and we've already done it here. */
7446diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7447index f213f5b..0af3e8e 100644
7448--- a/arch/parisc/include/asm/pgalloc.h
7449+++ b/arch/parisc/include/asm/pgalloc.h
7450@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7451 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7452 }
7453
7454+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7455+{
7456+ pgd_populate(mm, pgd, pmd);
7457+}
7458+
7459 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7460 {
7461 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7462@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7463 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7464 #define pmd_free(mm, x) do { } while (0)
7465 #define pgd_populate(mm, pmd, pte) BUG()
7466+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7467
7468 #endif
7469
7470diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7471index 22b89d1..ce34230 100644
7472--- a/arch/parisc/include/asm/pgtable.h
7473+++ b/arch/parisc/include/asm/pgtable.h
7474@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7475 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7476 #define PAGE_COPY PAGE_EXECREAD
7477 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7478+
7479+#ifdef CONFIG_PAX_PAGEEXEC
7480+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7481+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7482+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7483+#else
7484+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7485+# define PAGE_COPY_NOEXEC PAGE_COPY
7486+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7487+#endif
7488+
7489 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7490 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7491 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7492diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7493index 4006964..fcb3cc2 100644
7494--- a/arch/parisc/include/asm/uaccess.h
7495+++ b/arch/parisc/include/asm/uaccess.h
7496@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7497 const void __user *from,
7498 unsigned long n)
7499 {
7500- int sz = __compiletime_object_size(to);
7501+ size_t sz = __compiletime_object_size(to);
7502 int ret = -EFAULT;
7503
7504- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7505+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7506 ret = __copy_from_user(to, from, n);
7507 else
7508 copy_from_user_overflow();
7509diff --git a/arch/parisc/include/uapi/asm/resource.h b/arch/parisc/include/uapi/asm/resource.h
7510index 8b06343..090483c 100644
7511--- a/arch/parisc/include/uapi/asm/resource.h
7512+++ b/arch/parisc/include/uapi/asm/resource.h
7513@@ -1,7 +1,6 @@
7514 #ifndef _ASM_PARISC_RESOURCE_H
7515 #define _ASM_PARISC_RESOURCE_H
7516
7517-#define _STK_LIM_MAX 10 * _STK_LIM
7518 #include <asm-generic/resource.h>
7519
7520 #endif
7521diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7522index 50dfafc..b9fc230 100644
7523--- a/arch/parisc/kernel/module.c
7524+++ b/arch/parisc/kernel/module.c
7525@@ -98,16 +98,38 @@
7526
7527 /* three functions to determine where in the module core
7528 * or init pieces the location is */
7529+static inline int in_init_rx(struct module *me, void *loc)
7530+{
7531+ return (loc >= me->module_init_rx &&
7532+ loc < (me->module_init_rx + me->init_size_rx));
7533+}
7534+
7535+static inline int in_init_rw(struct module *me, void *loc)
7536+{
7537+ return (loc >= me->module_init_rw &&
7538+ loc < (me->module_init_rw + me->init_size_rw));
7539+}
7540+
7541 static inline int in_init(struct module *me, void *loc)
7542 {
7543- return (loc >= me->module_init &&
7544- loc <= (me->module_init + me->init_size));
7545+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7546+}
7547+
7548+static inline int in_core_rx(struct module *me, void *loc)
7549+{
7550+ return (loc >= me->module_core_rx &&
7551+ loc < (me->module_core_rx + me->core_size_rx));
7552+}
7553+
7554+static inline int in_core_rw(struct module *me, void *loc)
7555+{
7556+ return (loc >= me->module_core_rw &&
7557+ loc < (me->module_core_rw + me->core_size_rw));
7558 }
7559
7560 static inline int in_core(struct module *me, void *loc)
7561 {
7562- return (loc >= me->module_core &&
7563- loc <= (me->module_core + me->core_size));
7564+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7565 }
7566
7567 static inline int in_local(struct module *me, void *loc)
7568@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7569 }
7570
7571 /* align things a bit */
7572- me->core_size = ALIGN(me->core_size, 16);
7573- me->arch.got_offset = me->core_size;
7574- me->core_size += gots * sizeof(struct got_entry);
7575+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7576+ me->arch.got_offset = me->core_size_rw;
7577+ me->core_size_rw += gots * sizeof(struct got_entry);
7578
7579- me->core_size = ALIGN(me->core_size, 16);
7580- me->arch.fdesc_offset = me->core_size;
7581- me->core_size += fdescs * sizeof(Elf_Fdesc);
7582+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7583+ me->arch.fdesc_offset = me->core_size_rw;
7584+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7585
7586 me->arch.got_max = gots;
7587 me->arch.fdesc_max = fdescs;
7588@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7589
7590 BUG_ON(value == 0);
7591
7592- got = me->module_core + me->arch.got_offset;
7593+ got = me->module_core_rw + me->arch.got_offset;
7594 for (i = 0; got[i].addr; i++)
7595 if (got[i].addr == value)
7596 goto out;
7597@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7598 #ifdef CONFIG_64BIT
7599 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7600 {
7601- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7602+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7603
7604 if (!value) {
7605 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7606@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7607
7608 /* Create new one */
7609 fdesc->addr = value;
7610- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7611+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7612 return (Elf_Addr)fdesc;
7613 }
7614 #endif /* CONFIG_64BIT */
7615@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7616
7617 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7618 end = table + sechdrs[me->arch.unwind_section].sh_size;
7619- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7620+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7621
7622 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7623 me->arch.unwind_section, table, end, gp);
7624diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7625index b7cadc4..bf4a32d 100644
7626--- a/arch/parisc/kernel/sys_parisc.c
7627+++ b/arch/parisc/kernel/sys_parisc.c
7628@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7629 unsigned long task_size = TASK_SIZE;
7630 int do_color_align, last_mmap;
7631 struct vm_unmapped_area_info info;
7632+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7633
7634 if (len > task_size)
7635 return -ENOMEM;
7636@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7637 goto found_addr;
7638 }
7639
7640+#ifdef CONFIG_PAX_RANDMMAP
7641+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7642+#endif
7643+
7644 if (addr) {
7645 if (do_color_align && last_mmap)
7646 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7647@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7648 info.high_limit = mmap_upper_limit();
7649 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7650 info.align_offset = shared_align_offset(last_mmap, pgoff);
7651+ info.threadstack_offset = offset;
7652 addr = vm_unmapped_area(&info);
7653
7654 found_addr:
7655@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7656 unsigned long addr = addr0;
7657 int do_color_align, last_mmap;
7658 struct vm_unmapped_area_info info;
7659+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7660
7661 #ifdef CONFIG_64BIT
7662 /* This should only ever run for 32-bit processes. */
7663@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7664 }
7665
7666 /* requesting a specific address */
7667+#ifdef CONFIG_PAX_RANDMMAP
7668+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7669+#endif
7670+
7671 if (addr) {
7672 if (do_color_align && last_mmap)
7673 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7674@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7675 info.high_limit = mm->mmap_base;
7676 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7677 info.align_offset = shared_align_offset(last_mmap, pgoff);
7678+ info.threadstack_offset = offset;
7679 addr = vm_unmapped_area(&info);
7680 if (!(addr & ~PAGE_MASK))
7681 goto found_addr;
7682@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7683 mm->mmap_legacy_base = mmap_legacy_base();
7684 mm->mmap_base = mmap_upper_limit();
7685
7686+#ifdef CONFIG_PAX_RANDMMAP
7687+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7688+ mm->mmap_legacy_base += mm->delta_mmap;
7689+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7690+ }
7691+#endif
7692+
7693 if (mmap_is_legacy()) {
7694 mm->mmap_base = mm->mmap_legacy_base;
7695 mm->get_unmapped_area = arch_get_unmapped_area;
7696diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7697index 1cd1d0c..44ec918 100644
7698--- a/arch/parisc/kernel/traps.c
7699+++ b/arch/parisc/kernel/traps.c
7700@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7701
7702 down_read(&current->mm->mmap_sem);
7703 vma = find_vma(current->mm,regs->iaoq[0]);
7704- if (vma && (regs->iaoq[0] >= vma->vm_start)
7705- && (vma->vm_flags & VM_EXEC)) {
7706-
7707+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7708 fault_address = regs->iaoq[0];
7709 fault_space = regs->iasq[0];
7710
7711diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7712index 9d08c71..e2b4d20 100644
7713--- a/arch/parisc/mm/fault.c
7714+++ b/arch/parisc/mm/fault.c
7715@@ -15,6 +15,7 @@
7716 #include <linux/sched.h>
7717 #include <linux/interrupt.h>
7718 #include <linux/module.h>
7719+#include <linux/unistd.h>
7720
7721 #include <asm/uaccess.h>
7722 #include <asm/traps.h>
7723@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7724 static unsigned long
7725 parisc_acctyp(unsigned long code, unsigned int inst)
7726 {
7727- if (code == 6 || code == 16)
7728+ if (code == 6 || code == 7 || code == 16)
7729 return VM_EXEC;
7730
7731 switch (inst & 0xf0000000) {
7732@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7733 }
7734 #endif
7735
7736+#ifdef CONFIG_PAX_PAGEEXEC
7737+/*
7738+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7739+ *
7740+ * returns 1 when task should be killed
7741+ * 2 when rt_sigreturn trampoline was detected
7742+ * 3 when unpatched PLT trampoline was detected
7743+ */
7744+static int pax_handle_fetch_fault(struct pt_regs *regs)
7745+{
7746+
7747+#ifdef CONFIG_PAX_EMUPLT
7748+ int err;
7749+
7750+ do { /* PaX: unpatched PLT emulation */
7751+ unsigned int bl, depwi;
7752+
7753+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7754+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7755+
7756+ if (err)
7757+ break;
7758+
7759+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7760+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7761+
7762+ err = get_user(ldw, (unsigned int *)addr);
7763+ err |= get_user(bv, (unsigned int *)(addr+4));
7764+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7765+
7766+ if (err)
7767+ break;
7768+
7769+ if (ldw == 0x0E801096U &&
7770+ bv == 0xEAC0C000U &&
7771+ ldw2 == 0x0E881095U)
7772+ {
7773+ unsigned int resolver, map;
7774+
7775+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7776+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7777+ if (err)
7778+ break;
7779+
7780+ regs->gr[20] = instruction_pointer(regs)+8;
7781+ regs->gr[21] = map;
7782+ regs->gr[22] = resolver;
7783+ regs->iaoq[0] = resolver | 3UL;
7784+ regs->iaoq[1] = regs->iaoq[0] + 4;
7785+ return 3;
7786+ }
7787+ }
7788+ } while (0);
7789+#endif
7790+
7791+#ifdef CONFIG_PAX_EMUTRAMP
7792+
7793+#ifndef CONFIG_PAX_EMUSIGRT
7794+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7795+ return 1;
7796+#endif
7797+
7798+ do { /* PaX: rt_sigreturn emulation */
7799+ unsigned int ldi1, ldi2, bel, nop;
7800+
7801+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7802+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7803+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7804+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7805+
7806+ if (err)
7807+ break;
7808+
7809+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7810+ ldi2 == 0x3414015AU &&
7811+ bel == 0xE4008200U &&
7812+ nop == 0x08000240U)
7813+ {
7814+ regs->gr[25] = (ldi1 & 2) >> 1;
7815+ regs->gr[20] = __NR_rt_sigreturn;
7816+ regs->gr[31] = regs->iaoq[1] + 16;
7817+ regs->sr[0] = regs->iasq[1];
7818+ regs->iaoq[0] = 0x100UL;
7819+ regs->iaoq[1] = regs->iaoq[0] + 4;
7820+ regs->iasq[0] = regs->sr[2];
7821+ regs->iasq[1] = regs->sr[2];
7822+ return 2;
7823+ }
7824+ } while (0);
7825+#endif
7826+
7827+ return 1;
7828+}
7829+
7830+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7831+{
7832+ unsigned long i;
7833+
7834+ printk(KERN_ERR "PAX: bytes at PC: ");
7835+ for (i = 0; i < 5; i++) {
7836+ unsigned int c;
7837+ if (get_user(c, (unsigned int *)pc+i))
7838+ printk(KERN_CONT "???????? ");
7839+ else
7840+ printk(KERN_CONT "%08x ", c);
7841+ }
7842+ printk("\n");
7843+}
7844+#endif
7845+
7846 int fixup_exception(struct pt_regs *regs)
7847 {
7848 const struct exception_table_entry *fix;
7849@@ -210,8 +321,33 @@ retry:
7850
7851 good_area:
7852
7853- if ((vma->vm_flags & acc_type) != acc_type)
7854+ if ((vma->vm_flags & acc_type) != acc_type) {
7855+
7856+#ifdef CONFIG_PAX_PAGEEXEC
7857+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7858+ (address & ~3UL) == instruction_pointer(regs))
7859+ {
7860+ up_read(&mm->mmap_sem);
7861+ switch (pax_handle_fetch_fault(regs)) {
7862+
7863+#ifdef CONFIG_PAX_EMUPLT
7864+ case 3:
7865+ return;
7866+#endif
7867+
7868+#ifdef CONFIG_PAX_EMUTRAMP
7869+ case 2:
7870+ return;
7871+#endif
7872+
7873+ }
7874+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7875+ do_group_exit(SIGKILL);
7876+ }
7877+#endif
7878+
7879 goto bad_area;
7880+ }
7881
7882 /*
7883 * If for any reason at all we couldn't handle the fault, make
7884diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7885index 957bf34..3430cc8 100644
7886--- a/arch/powerpc/Kconfig
7887+++ b/arch/powerpc/Kconfig
7888@@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7889 config KEXEC
7890 bool "kexec system call"
7891 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7892+ depends on !GRKERNSEC_KMEM
7893 help
7894 kexec is a system call that implements the ability to shutdown your
7895 current kernel, and to start another kernel. It is like a reboot
7896diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7897index e3b1d41..8e81edf 100644
7898--- a/arch/powerpc/include/asm/atomic.h
7899+++ b/arch/powerpc/include/asm/atomic.h
7900@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7901 return t1;
7902 }
7903
7904+#define atomic64_read_unchecked(v) atomic64_read(v)
7905+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7906+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7907+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7908+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7909+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7910+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7911+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7912+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7913+
7914 #endif /* __powerpc64__ */
7915
7916 #endif /* __KERNEL__ */
7917diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7918index ed0afc1..0332825 100644
7919--- a/arch/powerpc/include/asm/cache.h
7920+++ b/arch/powerpc/include/asm/cache.h
7921@@ -3,6 +3,7 @@
7922
7923 #ifdef __KERNEL__
7924
7925+#include <linux/const.h>
7926
7927 /* bytes per L1 cache line */
7928 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7929@@ -22,7 +23,7 @@
7930 #define L1_CACHE_SHIFT 7
7931 #endif
7932
7933-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7934+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7935
7936 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7937
7938diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7939index 935b5e7..7001d2d 100644
7940--- a/arch/powerpc/include/asm/elf.h
7941+++ b/arch/powerpc/include/asm/elf.h
7942@@ -28,8 +28,19 @@
7943 the loader. We need to make sure that it is out of the way of the program
7944 that it will "exec", and that there is sufficient room for the brk. */
7945
7946-extern unsigned long randomize_et_dyn(unsigned long base);
7947-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7948+#define ELF_ET_DYN_BASE (0x20000000)
7949+
7950+#ifdef CONFIG_PAX_ASLR
7951+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7952+
7953+#ifdef __powerpc64__
7954+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7955+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7956+#else
7957+#define PAX_DELTA_MMAP_LEN 15
7958+#define PAX_DELTA_STACK_LEN 15
7959+#endif
7960+#endif
7961
7962 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7963
7964@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7965 (0x7ff >> (PAGE_SHIFT - 12)) : \
7966 (0x3ffff >> (PAGE_SHIFT - 12)))
7967
7968-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7969-#define arch_randomize_brk arch_randomize_brk
7970-
7971-
7972 #ifdef CONFIG_SPU_BASE
7973 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7974 #define NT_SPU 1
7975diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7976index 8196e9c..d83a9f3 100644
7977--- a/arch/powerpc/include/asm/exec.h
7978+++ b/arch/powerpc/include/asm/exec.h
7979@@ -4,6 +4,6 @@
7980 #ifndef _ASM_POWERPC_EXEC_H
7981 #define _ASM_POWERPC_EXEC_H
7982
7983-extern unsigned long arch_align_stack(unsigned long sp);
7984+#define arch_align_stack(x) ((x) & ~0xfUL)
7985
7986 #endif /* _ASM_POWERPC_EXEC_H */
7987diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7988index 5acabbd..7ea14fa 100644
7989--- a/arch/powerpc/include/asm/kmap_types.h
7990+++ b/arch/powerpc/include/asm/kmap_types.h
7991@@ -10,7 +10,7 @@
7992 * 2 of the License, or (at your option) any later version.
7993 */
7994
7995-#define KM_TYPE_NR 16
7996+#define KM_TYPE_NR 17
7997
7998 #endif /* __KERNEL__ */
7999 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8000diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8001index b8da913..60b608a 100644
8002--- a/arch/powerpc/include/asm/local.h
8003+++ b/arch/powerpc/include/asm/local.h
8004@@ -9,15 +9,26 @@ typedef struct
8005 atomic_long_t a;
8006 } local_t;
8007
8008+typedef struct
8009+{
8010+ atomic_long_unchecked_t a;
8011+} local_unchecked_t;
8012+
8013 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8014
8015 #define local_read(l) atomic_long_read(&(l)->a)
8016+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8017 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8018+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8019
8020 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8021+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8022 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8023+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8024 #define local_inc(l) atomic_long_inc(&(l)->a)
8025+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8026 #define local_dec(l) atomic_long_dec(&(l)->a)
8027+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8028
8029 static __inline__ long local_add_return(long a, local_t *l)
8030 {
8031@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8032
8033 return t;
8034 }
8035+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8036
8037 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8038
8039@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8040
8041 return t;
8042 }
8043+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8044
8045 static __inline__ long local_inc_return(local_t *l)
8046 {
8047@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8048
8049 #define local_cmpxchg(l, o, n) \
8050 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8051+#define local_cmpxchg_unchecked(l, o, n) \
8052+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8053 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8054
8055 /**
8056diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8057index 8565c25..2865190 100644
8058--- a/arch/powerpc/include/asm/mman.h
8059+++ b/arch/powerpc/include/asm/mman.h
8060@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8061 }
8062 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8063
8064-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8065+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8066 {
8067 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8068 }
8069diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8070index 32e4e21..62afb12 100644
8071--- a/arch/powerpc/include/asm/page.h
8072+++ b/arch/powerpc/include/asm/page.h
8073@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8074 * and needs to be executable. This means the whole heap ends
8075 * up being executable.
8076 */
8077-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8078- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8079+#define VM_DATA_DEFAULT_FLAGS32 \
8080+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8081+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8082
8083 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8084 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8085@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8086 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8087 #endif
8088
8089+#define ktla_ktva(addr) (addr)
8090+#define ktva_ktla(addr) (addr)
8091+
8092 #ifndef CONFIG_PPC_BOOK3S_64
8093 /*
8094 * Use the top bit of the higher-level page table entries to indicate whether
8095diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8096index 88693ce..ac6f9ab 100644
8097--- a/arch/powerpc/include/asm/page_64.h
8098+++ b/arch/powerpc/include/asm/page_64.h
8099@@ -153,15 +153,18 @@ do { \
8100 * stack by default, so in the absence of a PT_GNU_STACK program header
8101 * we turn execute permission off.
8102 */
8103-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8104- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8105+#define VM_STACK_DEFAULT_FLAGS32 \
8106+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8107+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8108
8109 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8110 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8111
8112+#ifndef CONFIG_PAX_PAGEEXEC
8113 #define VM_STACK_DEFAULT_FLAGS \
8114 (is_32bit_task() ? \
8115 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8116+#endif
8117
8118 #include <asm-generic/getorder.h>
8119
8120diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8121index 4b0be20..c15a27d 100644
8122--- a/arch/powerpc/include/asm/pgalloc-64.h
8123+++ b/arch/powerpc/include/asm/pgalloc-64.h
8124@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8125 #ifndef CONFIG_PPC_64K_PAGES
8126
8127 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8128+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8129
8130 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8131 {
8132@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8133 pud_set(pud, (unsigned long)pmd);
8134 }
8135
8136+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8137+{
8138+ pud_populate(mm, pud, pmd);
8139+}
8140+
8141 #define pmd_populate(mm, pmd, pte_page) \
8142 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8143 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8144@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8145 #endif
8146
8147 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8148+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8149
8150 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8151 pte_t *pte)
8152diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8153index 3ebb188..e17dddf 100644
8154--- a/arch/powerpc/include/asm/pgtable.h
8155+++ b/arch/powerpc/include/asm/pgtable.h
8156@@ -2,6 +2,7 @@
8157 #define _ASM_POWERPC_PGTABLE_H
8158 #ifdef __KERNEL__
8159
8160+#include <linux/const.h>
8161 #ifndef __ASSEMBLY__
8162 #include <linux/mmdebug.h>
8163 #include <asm/processor.h> /* For TASK_SIZE */
8164diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8165index 4aad413..85d86bf 100644
8166--- a/arch/powerpc/include/asm/pte-hash32.h
8167+++ b/arch/powerpc/include/asm/pte-hash32.h
8168@@ -21,6 +21,7 @@
8169 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8170 #define _PAGE_USER 0x004 /* usermode access allowed */
8171 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8172+#define _PAGE_EXEC _PAGE_GUARDED
8173 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8174 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8175 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8176diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8177index 90c06ec..3517221 100644
8178--- a/arch/powerpc/include/asm/reg.h
8179+++ b/arch/powerpc/include/asm/reg.h
8180@@ -248,6 +248,7 @@
8181 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8182 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8183 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8184+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8185 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8186 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8187 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8188diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8189index 084e080..9415a3d 100644
8190--- a/arch/powerpc/include/asm/smp.h
8191+++ b/arch/powerpc/include/asm/smp.h
8192@@ -51,7 +51,7 @@ struct smp_ops_t {
8193 int (*cpu_disable)(void);
8194 void (*cpu_die)(unsigned int nr);
8195 int (*cpu_bootable)(unsigned int nr);
8196-};
8197+} __no_const;
8198
8199 extern void smp_send_debugger_break(void);
8200 extern void start_secondary_resume(void);
8201diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8202index b034ecd..af7e31f 100644
8203--- a/arch/powerpc/include/asm/thread_info.h
8204+++ b/arch/powerpc/include/asm/thread_info.h
8205@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8206 #if defined(CONFIG_PPC64)
8207 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8208 #endif
8209+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8210+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8211
8212 /* as above, but as bit values */
8213 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8214@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8215 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8216 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8217 #define _TIF_NOHZ (1<<TIF_NOHZ)
8218+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8219 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8220 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8221- _TIF_NOHZ)
8222+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8223
8224 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8225 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8226diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8227index 9485b43..3bd3c16 100644
8228--- a/arch/powerpc/include/asm/uaccess.h
8229+++ b/arch/powerpc/include/asm/uaccess.h
8230@@ -58,6 +58,7 @@
8231
8232 #endif
8233
8234+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8235 #define access_ok(type, addr, size) \
8236 (__chk_user_ptr(addr), \
8237 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8238@@ -318,52 +319,6 @@ do { \
8239 extern unsigned long __copy_tofrom_user(void __user *to,
8240 const void __user *from, unsigned long size);
8241
8242-#ifndef __powerpc64__
8243-
8244-static inline unsigned long copy_from_user(void *to,
8245- const void __user *from, unsigned long n)
8246-{
8247- unsigned long over;
8248-
8249- if (access_ok(VERIFY_READ, from, n))
8250- return __copy_tofrom_user((__force void __user *)to, from, n);
8251- if ((unsigned long)from < TASK_SIZE) {
8252- over = (unsigned long)from + n - TASK_SIZE;
8253- return __copy_tofrom_user((__force void __user *)to, from,
8254- n - over) + over;
8255- }
8256- return n;
8257-}
8258-
8259-static inline unsigned long copy_to_user(void __user *to,
8260- const void *from, unsigned long n)
8261-{
8262- unsigned long over;
8263-
8264- if (access_ok(VERIFY_WRITE, to, n))
8265- return __copy_tofrom_user(to, (__force void __user *)from, n);
8266- if ((unsigned long)to < TASK_SIZE) {
8267- over = (unsigned long)to + n - TASK_SIZE;
8268- return __copy_tofrom_user(to, (__force void __user *)from,
8269- n - over) + over;
8270- }
8271- return n;
8272-}
8273-
8274-#else /* __powerpc64__ */
8275-
8276-#define __copy_in_user(to, from, size) \
8277- __copy_tofrom_user((to), (from), (size))
8278-
8279-extern unsigned long copy_from_user(void *to, const void __user *from,
8280- unsigned long n);
8281-extern unsigned long copy_to_user(void __user *to, const void *from,
8282- unsigned long n);
8283-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8284- unsigned long n);
8285-
8286-#endif /* __powerpc64__ */
8287-
8288 static inline unsigned long __copy_from_user_inatomic(void *to,
8289 const void __user *from, unsigned long n)
8290 {
8291@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8292 if (ret == 0)
8293 return 0;
8294 }
8295+
8296+ if (!__builtin_constant_p(n))
8297+ check_object_size(to, n, false);
8298+
8299 return __copy_tofrom_user((__force void __user *)to, from, n);
8300 }
8301
8302@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8303 if (ret == 0)
8304 return 0;
8305 }
8306+
8307+ if (!__builtin_constant_p(n))
8308+ check_object_size(from, n, true);
8309+
8310 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8311 }
8312
8313@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8314 return __copy_to_user_inatomic(to, from, size);
8315 }
8316
8317+#ifndef __powerpc64__
8318+
8319+static inline unsigned long __must_check copy_from_user(void *to,
8320+ const void __user *from, unsigned long n)
8321+{
8322+ unsigned long over;
8323+
8324+ if ((long)n < 0)
8325+ return n;
8326+
8327+ if (access_ok(VERIFY_READ, from, n)) {
8328+ if (!__builtin_constant_p(n))
8329+ check_object_size(to, n, false);
8330+ return __copy_tofrom_user((__force void __user *)to, from, n);
8331+ }
8332+ if ((unsigned long)from < TASK_SIZE) {
8333+ over = (unsigned long)from + n - TASK_SIZE;
8334+ if (!__builtin_constant_p(n - over))
8335+ check_object_size(to, n - over, false);
8336+ return __copy_tofrom_user((__force void __user *)to, from,
8337+ n - over) + over;
8338+ }
8339+ return n;
8340+}
8341+
8342+static inline unsigned long __must_check copy_to_user(void __user *to,
8343+ const void *from, unsigned long n)
8344+{
8345+ unsigned long over;
8346+
8347+ if ((long)n < 0)
8348+ return n;
8349+
8350+ if (access_ok(VERIFY_WRITE, to, n)) {
8351+ if (!__builtin_constant_p(n))
8352+ check_object_size(from, n, true);
8353+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8354+ }
8355+ if ((unsigned long)to < TASK_SIZE) {
8356+ over = (unsigned long)to + n - TASK_SIZE;
8357+ if (!__builtin_constant_p(n))
8358+ check_object_size(from, n - over, true);
8359+ return __copy_tofrom_user(to, (__force void __user *)from,
8360+ n - over) + over;
8361+ }
8362+ return n;
8363+}
8364+
8365+#else /* __powerpc64__ */
8366+
8367+#define __copy_in_user(to, from, size) \
8368+ __copy_tofrom_user((to), (from), (size))
8369+
8370+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8371+{
8372+ if ((long)n < 0 || n > INT_MAX)
8373+ return n;
8374+
8375+ if (!__builtin_constant_p(n))
8376+ check_object_size(to, n, false);
8377+
8378+ if (likely(access_ok(VERIFY_READ, from, n)))
8379+ n = __copy_from_user(to, from, n);
8380+ else
8381+ memset(to, 0, n);
8382+ return n;
8383+}
8384+
8385+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8386+{
8387+ if ((long)n < 0 || n > INT_MAX)
8388+ return n;
8389+
8390+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8391+ if (!__builtin_constant_p(n))
8392+ check_object_size(from, n, true);
8393+ n = __copy_to_user(to, from, n);
8394+ }
8395+ return n;
8396+}
8397+
8398+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8399+ unsigned long n);
8400+
8401+#endif /* __powerpc64__ */
8402+
8403 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8404
8405 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8406diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8407index fcc9a89..07be2bb 100644
8408--- a/arch/powerpc/kernel/Makefile
8409+++ b/arch/powerpc/kernel/Makefile
8410@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8411 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8412 endif
8413
8414+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8415+
8416 obj-y := cputable.o ptrace.o syscalls.o \
8417 irq.o align.o signal_32.o pmc.o vdso.o \
8418 process.o systbl.o idle.o \
8419diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8420index 063b65d..7a26e9d 100644
8421--- a/arch/powerpc/kernel/exceptions-64e.S
8422+++ b/arch/powerpc/kernel/exceptions-64e.S
8423@@ -771,6 +771,7 @@ storage_fault_common:
8424 std r14,_DAR(r1)
8425 std r15,_DSISR(r1)
8426 addi r3,r1,STACK_FRAME_OVERHEAD
8427+ bl .save_nvgprs
8428 mr r4,r14
8429 mr r5,r15
8430 ld r14,PACA_EXGEN+EX_R14(r13)
8431@@ -779,8 +780,7 @@ storage_fault_common:
8432 cmpdi r3,0
8433 bne- 1f
8434 b .ret_from_except_lite
8435-1: bl .save_nvgprs
8436- mr r5,r3
8437+1: mr r5,r3
8438 addi r3,r1,STACK_FRAME_OVERHEAD
8439 ld r4,_DAR(r1)
8440 bl .bad_page_fault
8441diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8442index 38d5073..f00af8d 100644
8443--- a/arch/powerpc/kernel/exceptions-64s.S
8444+++ b/arch/powerpc/kernel/exceptions-64s.S
8445@@ -1584,10 +1584,10 @@ handle_page_fault:
8446 11: ld r4,_DAR(r1)
8447 ld r5,_DSISR(r1)
8448 addi r3,r1,STACK_FRAME_OVERHEAD
8449+ bl .save_nvgprs
8450 bl .do_page_fault
8451 cmpdi r3,0
8452 beq+ 12f
8453- bl .save_nvgprs
8454 mr r5,r3
8455 addi r3,r1,STACK_FRAME_OVERHEAD
8456 lwz r4,_DAR(r1)
8457diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8458index 1d0848b..d74685f 100644
8459--- a/arch/powerpc/kernel/irq.c
8460+++ b/arch/powerpc/kernel/irq.c
8461@@ -447,6 +447,8 @@ void migrate_irqs(void)
8462 }
8463 #endif
8464
8465+extern void gr_handle_kernel_exploit(void);
8466+
8467 static inline void check_stack_overflow(void)
8468 {
8469 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8470@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8471 printk("do_IRQ: stack overflow: %ld\n",
8472 sp - sizeof(struct thread_info));
8473 dump_stack();
8474+ gr_handle_kernel_exploit();
8475 }
8476 #endif
8477 }
8478diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8479index 6cff040..74ac5d1 100644
8480--- a/arch/powerpc/kernel/module_32.c
8481+++ b/arch/powerpc/kernel/module_32.c
8482@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8483 me->arch.core_plt_section = i;
8484 }
8485 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8486- printk("Module doesn't contain .plt or .init.plt sections.\n");
8487+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8488 return -ENOEXEC;
8489 }
8490
8491@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8492
8493 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8494 /* Init, or core PLT? */
8495- if (location >= mod->module_core
8496- && location < mod->module_core + mod->core_size)
8497+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8498+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8499 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8500- else
8501+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8502+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8503 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8504+ else {
8505+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8506+ return ~0UL;
8507+ }
8508
8509 /* Find this entry, or if that fails, the next avail. entry */
8510 while (entry->jump[0]) {
8511@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8512 }
8513 #ifdef CONFIG_DYNAMIC_FTRACE
8514 module->arch.tramp =
8515- do_plt_call(module->module_core,
8516+ do_plt_call(module->module_core_rx,
8517 (unsigned long)ftrace_caller,
8518 sechdrs, module);
8519 #endif
8520diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8521index af064d2..ce56147 100644
8522--- a/arch/powerpc/kernel/process.c
8523+++ b/arch/powerpc/kernel/process.c
8524@@ -1009,8 +1009,8 @@ void show_regs(struct pt_regs * regs)
8525 * Lookup NIP late so we have the best change of getting the
8526 * above info out without failing
8527 */
8528- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8529- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8530+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8531+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8532 #endif
8533 show_stack(current, (unsigned long *) regs->gpr[1]);
8534 if (!user_mode(regs))
8535@@ -1532,10 +1532,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8536 newsp = stack[0];
8537 ip = stack[STACK_FRAME_LR_SAVE];
8538 if (!firstframe || ip != lr) {
8539- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8540+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8541 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8542 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8543- printk(" (%pS)",
8544+ printk(" (%pA)",
8545 (void *)current->ret_stack[curr_frame].ret);
8546 curr_frame--;
8547 }
8548@@ -1555,7 +1555,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8549 struct pt_regs *regs = (struct pt_regs *)
8550 (sp + STACK_FRAME_OVERHEAD);
8551 lr = regs->link;
8552- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8553+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8554 regs->trap, (void *)regs->nip, (void *)lr);
8555 firstframe = 1;
8556 }
8557@@ -1591,58 +1591,3 @@ void notrace __ppc64_runlatch_off(void)
8558 mtspr(SPRN_CTRLT, ctrl);
8559 }
8560 #endif /* CONFIG_PPC64 */
8561-
8562-unsigned long arch_align_stack(unsigned long sp)
8563-{
8564- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8565- sp -= get_random_int() & ~PAGE_MASK;
8566- return sp & ~0xf;
8567-}
8568-
8569-static inline unsigned long brk_rnd(void)
8570-{
8571- unsigned long rnd = 0;
8572-
8573- /* 8MB for 32bit, 1GB for 64bit */
8574- if (is_32bit_task())
8575- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8576- else
8577- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8578-
8579- return rnd << PAGE_SHIFT;
8580-}
8581-
8582-unsigned long arch_randomize_brk(struct mm_struct *mm)
8583-{
8584- unsigned long base = mm->brk;
8585- unsigned long ret;
8586-
8587-#ifdef CONFIG_PPC_STD_MMU_64
8588- /*
8589- * If we are using 1TB segments and we are allowed to randomise
8590- * the heap, we can put it above 1TB so it is backed by a 1TB
8591- * segment. Otherwise the heap will be in the bottom 1TB
8592- * which always uses 256MB segments and this may result in a
8593- * performance penalty.
8594- */
8595- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8596- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8597-#endif
8598-
8599- ret = PAGE_ALIGN(base + brk_rnd());
8600-
8601- if (ret < mm->brk)
8602- return mm->brk;
8603-
8604- return ret;
8605-}
8606-
8607-unsigned long randomize_et_dyn(unsigned long base)
8608-{
8609- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8610-
8611- if (ret < base)
8612- return base;
8613-
8614- return ret;
8615-}
8616diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8617index 2e3d2bf..35df241 100644
8618--- a/arch/powerpc/kernel/ptrace.c
8619+++ b/arch/powerpc/kernel/ptrace.c
8620@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8621 return ret;
8622 }
8623
8624+#ifdef CONFIG_GRKERNSEC_SETXID
8625+extern void gr_delayed_cred_worker(void);
8626+#endif
8627+
8628 /*
8629 * We must return the syscall number to actually look up in the table.
8630 * This can be -1L to skip running any syscall at all.
8631@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8632
8633 secure_computing_strict(regs->gpr[0]);
8634
8635+#ifdef CONFIG_GRKERNSEC_SETXID
8636+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8637+ gr_delayed_cred_worker();
8638+#endif
8639+
8640 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8641 tracehook_report_syscall_entry(regs))
8642 /*
8643@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8644 {
8645 int step;
8646
8647+#ifdef CONFIG_GRKERNSEC_SETXID
8648+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8649+ gr_delayed_cred_worker();
8650+#endif
8651+
8652 audit_syscall_exit(regs);
8653
8654 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8655diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8656index a67e00a..f71d8c7 100644
8657--- a/arch/powerpc/kernel/signal_32.c
8658+++ b/arch/powerpc/kernel/signal_32.c
8659@@ -1011,7 +1011,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8660 /* Save user registers on the stack */
8661 frame = &rt_sf->uc.uc_mcontext;
8662 addr = frame;
8663- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8664+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8665 sigret = 0;
8666 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8667 } else {
8668diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8669index 8d253c2..405b337 100644
8670--- a/arch/powerpc/kernel/signal_64.c
8671+++ b/arch/powerpc/kernel/signal_64.c
8672@@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8673 current->thread.fp_state.fpscr = 0;
8674
8675 /* Set up to return from userspace. */
8676- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8677+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8678 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8679 } else {
8680 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8681diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8682index 33cd7a0..d615344 100644
8683--- a/arch/powerpc/kernel/traps.c
8684+++ b/arch/powerpc/kernel/traps.c
8685@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8686 return flags;
8687 }
8688
8689+extern void gr_handle_kernel_exploit(void);
8690+
8691 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8692 int signr)
8693 {
8694@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8695 panic("Fatal exception in interrupt");
8696 if (panic_on_oops)
8697 panic("Fatal exception");
8698+
8699+ gr_handle_kernel_exploit();
8700+
8701 do_exit(signr);
8702 }
8703
8704diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8705index 094e45c..d82b848 100644
8706--- a/arch/powerpc/kernel/vdso.c
8707+++ b/arch/powerpc/kernel/vdso.c
8708@@ -35,6 +35,7 @@
8709 #include <asm/vdso.h>
8710 #include <asm/vdso_datapage.h>
8711 #include <asm/setup.h>
8712+#include <asm/mman.h>
8713
8714 #undef DEBUG
8715
8716@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8717 vdso_base = VDSO32_MBASE;
8718 #endif
8719
8720- current->mm->context.vdso_base = 0;
8721+ current->mm->context.vdso_base = ~0UL;
8722
8723 /* vDSO has a problem and was disabled, just don't "enable" it for the
8724 * process
8725@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8726 vdso_base = get_unmapped_area(NULL, vdso_base,
8727 (vdso_pages << PAGE_SHIFT) +
8728 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8729- 0, 0);
8730+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8731 if (IS_ERR_VALUE(vdso_base)) {
8732 rc = vdso_base;
8733 goto fail_mmapsem;
8734diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8735index 3cf541a..ab2d825 100644
8736--- a/arch/powerpc/kvm/powerpc.c
8737+++ b/arch/powerpc/kvm/powerpc.c
8738@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8739 }
8740 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8741
8742-int kvm_arch_init(void *opaque)
8743+int kvm_arch_init(const void *opaque)
8744 {
8745 return 0;
8746 }
8747diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8748index 5eea6f3..5d10396 100644
8749--- a/arch/powerpc/lib/usercopy_64.c
8750+++ b/arch/powerpc/lib/usercopy_64.c
8751@@ -9,22 +9,6 @@
8752 #include <linux/module.h>
8753 #include <asm/uaccess.h>
8754
8755-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8756-{
8757- if (likely(access_ok(VERIFY_READ, from, n)))
8758- n = __copy_from_user(to, from, n);
8759- else
8760- memset(to, 0, n);
8761- return n;
8762-}
8763-
8764-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8765-{
8766- if (likely(access_ok(VERIFY_WRITE, to, n)))
8767- n = __copy_to_user(to, from, n);
8768- return n;
8769-}
8770-
8771 unsigned long copy_in_user(void __user *to, const void __user *from,
8772 unsigned long n)
8773 {
8774@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8775 return n;
8776 }
8777
8778-EXPORT_SYMBOL(copy_from_user);
8779-EXPORT_SYMBOL(copy_to_user);
8780 EXPORT_SYMBOL(copy_in_user);
8781
8782diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8783index 51ab9e7..7d3c78b 100644
8784--- a/arch/powerpc/mm/fault.c
8785+++ b/arch/powerpc/mm/fault.c
8786@@ -33,6 +33,10 @@
8787 #include <linux/magic.h>
8788 #include <linux/ratelimit.h>
8789 #include <linux/context_tracking.h>
8790+#include <linux/slab.h>
8791+#include <linux/pagemap.h>
8792+#include <linux/compiler.h>
8793+#include <linux/unistd.h>
8794
8795 #include <asm/firmware.h>
8796 #include <asm/page.h>
8797@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8798 }
8799 #endif
8800
8801+#ifdef CONFIG_PAX_PAGEEXEC
8802+/*
8803+ * PaX: decide what to do with offenders (regs->nip = fault address)
8804+ *
8805+ * returns 1 when task should be killed
8806+ */
8807+static int pax_handle_fetch_fault(struct pt_regs *regs)
8808+{
8809+ return 1;
8810+}
8811+
8812+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8813+{
8814+ unsigned long i;
8815+
8816+ printk(KERN_ERR "PAX: bytes at PC: ");
8817+ for (i = 0; i < 5; i++) {
8818+ unsigned int c;
8819+ if (get_user(c, (unsigned int __user *)pc+i))
8820+ printk(KERN_CONT "???????? ");
8821+ else
8822+ printk(KERN_CONT "%08x ", c);
8823+ }
8824+ printk("\n");
8825+}
8826+#endif
8827+
8828 /*
8829 * Check whether the instruction at regs->nip is a store using
8830 * an update addressing form which will update r1.
8831@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8832 * indicate errors in DSISR but can validly be set in SRR1.
8833 */
8834 if (trap == 0x400)
8835- error_code &= 0x48200000;
8836+ error_code &= 0x58200000;
8837 else
8838 is_write = error_code & DSISR_ISSTORE;
8839 #else
8840@@ -378,7 +409,7 @@ good_area:
8841 * "undefined". Of those that can be set, this is the only
8842 * one which seems bad.
8843 */
8844- if (error_code & 0x10000000)
8845+ if (error_code & DSISR_GUARDED)
8846 /* Guarded storage error. */
8847 goto bad_area;
8848 #endif /* CONFIG_8xx */
8849@@ -393,7 +424,7 @@ good_area:
8850 * processors use the same I/D cache coherency mechanism
8851 * as embedded.
8852 */
8853- if (error_code & DSISR_PROTFAULT)
8854+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8855 goto bad_area;
8856 #endif /* CONFIG_PPC_STD_MMU */
8857
8858@@ -483,6 +514,23 @@ bad_area:
8859 bad_area_nosemaphore:
8860 /* User mode accesses cause a SIGSEGV */
8861 if (user_mode(regs)) {
8862+
8863+#ifdef CONFIG_PAX_PAGEEXEC
8864+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8865+#ifdef CONFIG_PPC_STD_MMU
8866+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8867+#else
8868+ if (is_exec && regs->nip == address) {
8869+#endif
8870+ switch (pax_handle_fetch_fault(regs)) {
8871+ }
8872+
8873+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8874+ do_group_exit(SIGKILL);
8875+ }
8876+ }
8877+#endif
8878+
8879 _exception(SIGSEGV, regs, code, address);
8880 goto bail;
8881 }
8882diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8883index cb8bdbe..cde4bc7 100644
8884--- a/arch/powerpc/mm/mmap.c
8885+++ b/arch/powerpc/mm/mmap.c
8886@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8887 return sysctl_legacy_va_layout;
8888 }
8889
8890-static unsigned long mmap_rnd(void)
8891+static unsigned long mmap_rnd(struct mm_struct *mm)
8892 {
8893 unsigned long rnd = 0;
8894
8895+#ifdef CONFIG_PAX_RANDMMAP
8896+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8897+#endif
8898+
8899 if (current->flags & PF_RANDOMIZE) {
8900 /* 8MB for 32bit, 1GB for 64bit */
8901 if (is_32bit_task())
8902@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8903 return rnd << PAGE_SHIFT;
8904 }
8905
8906-static inline unsigned long mmap_base(void)
8907+static inline unsigned long mmap_base(struct mm_struct *mm)
8908 {
8909 unsigned long gap = rlimit(RLIMIT_STACK);
8910
8911@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8912 else if (gap > MAX_GAP)
8913 gap = MAX_GAP;
8914
8915- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8916+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8917 }
8918
8919 /*
8920@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8921 */
8922 if (mmap_is_legacy()) {
8923 mm->mmap_base = TASK_UNMAPPED_BASE;
8924+
8925+#ifdef CONFIG_PAX_RANDMMAP
8926+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8927+ mm->mmap_base += mm->delta_mmap;
8928+#endif
8929+
8930 mm->get_unmapped_area = arch_get_unmapped_area;
8931 } else {
8932- mm->mmap_base = mmap_base();
8933+ mm->mmap_base = mmap_base(mm);
8934+
8935+#ifdef CONFIG_PAX_RANDMMAP
8936+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8937+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8938+#endif
8939+
8940 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8941 }
8942 }
8943diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8944index b0c75cc..ef7fb93 100644
8945--- a/arch/powerpc/mm/slice.c
8946+++ b/arch/powerpc/mm/slice.c
8947@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8948 if ((mm->task_size - len) < addr)
8949 return 0;
8950 vma = find_vma(mm, addr);
8951- return (!vma || (addr + len) <= vma->vm_start);
8952+ return check_heap_stack_gap(vma, addr, len, 0);
8953 }
8954
8955 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8956@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8957 info.align_offset = 0;
8958
8959 addr = TASK_UNMAPPED_BASE;
8960+
8961+#ifdef CONFIG_PAX_RANDMMAP
8962+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8963+ addr += mm->delta_mmap;
8964+#endif
8965+
8966 while (addr < TASK_SIZE) {
8967 info.low_limit = addr;
8968 if (!slice_scan_available(addr, available, 1, &addr))
8969@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8970 if (fixed && addr > (mm->task_size - len))
8971 return -ENOMEM;
8972
8973+#ifdef CONFIG_PAX_RANDMMAP
8974+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8975+ addr = 0;
8976+#endif
8977+
8978 /* If hint, make sure it matches our alignment restrictions */
8979 if (!fixed && addr) {
8980 addr = _ALIGN_UP(addr, 1ul << pshift);
8981diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8982index 4278acf..67fd0e6 100644
8983--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8984+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8985@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8986 }
8987
8988 static struct pci_ops scc_pciex_pci_ops = {
8989- scc_pciex_read_config,
8990- scc_pciex_write_config,
8991+ .read = scc_pciex_read_config,
8992+ .write = scc_pciex_write_config,
8993 };
8994
8995 static void pciex_clear_intr_all(unsigned int __iomem *base)
8996diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8997index 9098692..3d54cd1 100644
8998--- a/arch/powerpc/platforms/cell/spufs/file.c
8999+++ b/arch/powerpc/platforms/cell/spufs/file.c
9000@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9001 return VM_FAULT_NOPAGE;
9002 }
9003
9004-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9005+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9006 unsigned long address,
9007- void *buf, int len, int write)
9008+ void *buf, size_t len, int write)
9009 {
9010 struct spu_context *ctx = vma->vm_file->private_data;
9011 unsigned long offset = address - vma->vm_start;
9012diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9013index 1d47061..0714963 100644
9014--- a/arch/s390/include/asm/atomic.h
9015+++ b/arch/s390/include/asm/atomic.h
9016@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9017 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9018 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9019
9020+#define atomic64_read_unchecked(v) atomic64_read(v)
9021+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9022+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9023+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9024+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9025+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9026+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9027+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9028+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9029+
9030 #define smp_mb__before_atomic_dec() smp_mb()
9031 #define smp_mb__after_atomic_dec() smp_mb()
9032 #define smp_mb__before_atomic_inc() smp_mb()
9033diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9034index 4d7ccac..d03d0ad 100644
9035--- a/arch/s390/include/asm/cache.h
9036+++ b/arch/s390/include/asm/cache.h
9037@@ -9,8 +9,10 @@
9038 #ifndef __ARCH_S390_CACHE_H
9039 #define __ARCH_S390_CACHE_H
9040
9041-#define L1_CACHE_BYTES 256
9042+#include <linux/const.h>
9043+
9044 #define L1_CACHE_SHIFT 8
9045+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9046 #define NET_SKB_PAD 32
9047
9048 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9049diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9050index 78f4f87..598ce39 100644
9051--- a/arch/s390/include/asm/elf.h
9052+++ b/arch/s390/include/asm/elf.h
9053@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9054 the loader. We need to make sure that it is out of the way of the program
9055 that it will "exec", and that there is sufficient room for the brk. */
9056
9057-extern unsigned long randomize_et_dyn(unsigned long base);
9058-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9059+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9060+
9061+#ifdef CONFIG_PAX_ASLR
9062+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9063+
9064+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9065+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9066+#endif
9067
9068 /* This yields a mask that user programs can use to figure out what
9069 instruction set this CPU supports. */
9070@@ -222,9 +228,6 @@ struct linux_binprm;
9071 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9072 int arch_setup_additional_pages(struct linux_binprm *, int);
9073
9074-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9075-#define arch_randomize_brk arch_randomize_brk
9076-
9077 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9078
9079 #endif
9080diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9081index c4a93d6..4d2a9b4 100644
9082--- a/arch/s390/include/asm/exec.h
9083+++ b/arch/s390/include/asm/exec.h
9084@@ -7,6 +7,6 @@
9085 #ifndef __ASM_EXEC_H
9086 #define __ASM_EXEC_H
9087
9088-extern unsigned long arch_align_stack(unsigned long sp);
9089+#define arch_align_stack(x) ((x) & ~0xfUL)
9090
9091 #endif /* __ASM_EXEC_H */
9092diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9093index 79330af..254cf37 100644
9094--- a/arch/s390/include/asm/uaccess.h
9095+++ b/arch/s390/include/asm/uaccess.h
9096@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9097 __range_ok((unsigned long)(addr), (size)); \
9098 })
9099
9100+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9101 #define access_ok(type, addr, size) __access_ok(addr, size)
9102
9103 /*
9104@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9105 copy_to_user(void __user *to, const void *from, unsigned long n)
9106 {
9107 might_fault();
9108+
9109+ if ((long)n < 0)
9110+ return n;
9111+
9112 return __copy_to_user(to, from, n);
9113 }
9114
9115@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9116 static inline unsigned long __must_check
9117 __copy_from_user(void *to, const void __user *from, unsigned long n)
9118 {
9119+ if ((long)n < 0)
9120+ return n;
9121+
9122 return uaccess.copy_from_user(n, from, to);
9123 }
9124
9125@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9126 static inline unsigned long __must_check
9127 copy_from_user(void *to, const void __user *from, unsigned long n)
9128 {
9129- unsigned int sz = __compiletime_object_size(to);
9130+ size_t sz = __compiletime_object_size(to);
9131
9132 might_fault();
9133- if (unlikely(sz != -1 && sz < n)) {
9134+
9135+ if ((long)n < 0)
9136+ return n;
9137+
9138+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9139 copy_from_user_overflow();
9140 return n;
9141 }
9142diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9143index b89b591..fd9609d 100644
9144--- a/arch/s390/kernel/module.c
9145+++ b/arch/s390/kernel/module.c
9146@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9147
9148 /* Increase core size by size of got & plt and set start
9149 offsets for got and plt. */
9150- me->core_size = ALIGN(me->core_size, 4);
9151- me->arch.got_offset = me->core_size;
9152- me->core_size += me->arch.got_size;
9153- me->arch.plt_offset = me->core_size;
9154- me->core_size += me->arch.plt_size;
9155+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9156+ me->arch.got_offset = me->core_size_rw;
9157+ me->core_size_rw += me->arch.got_size;
9158+ me->arch.plt_offset = me->core_size_rx;
9159+ me->core_size_rx += me->arch.plt_size;
9160 return 0;
9161 }
9162
9163@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9164 if (info->got_initialized == 0) {
9165 Elf_Addr *gotent;
9166
9167- gotent = me->module_core + me->arch.got_offset +
9168+ gotent = me->module_core_rw + me->arch.got_offset +
9169 info->got_offset;
9170 *gotent = val;
9171 info->got_initialized = 1;
9172@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9173 rc = apply_rela_bits(loc, val, 0, 64, 0);
9174 else if (r_type == R_390_GOTENT ||
9175 r_type == R_390_GOTPLTENT) {
9176- val += (Elf_Addr) me->module_core - loc;
9177+ val += (Elf_Addr) me->module_core_rw - loc;
9178 rc = apply_rela_bits(loc, val, 1, 32, 1);
9179 }
9180 break;
9181@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9182 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9183 if (info->plt_initialized == 0) {
9184 unsigned int *ip;
9185- ip = me->module_core + me->arch.plt_offset +
9186+ ip = me->module_core_rx + me->arch.plt_offset +
9187 info->plt_offset;
9188 #ifndef CONFIG_64BIT
9189 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9190@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9191 val - loc + 0xffffUL < 0x1ffffeUL) ||
9192 (r_type == R_390_PLT32DBL &&
9193 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9194- val = (Elf_Addr) me->module_core +
9195+ val = (Elf_Addr) me->module_core_rx +
9196 me->arch.plt_offset +
9197 info->plt_offset;
9198 val += rela->r_addend - loc;
9199@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9200 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9201 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9202 val = val + rela->r_addend -
9203- ((Elf_Addr) me->module_core + me->arch.got_offset);
9204+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9205 if (r_type == R_390_GOTOFF16)
9206 rc = apply_rela_bits(loc, val, 0, 16, 0);
9207 else if (r_type == R_390_GOTOFF32)
9208@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9209 break;
9210 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9211 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9212- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9213+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9214 rela->r_addend - loc;
9215 if (r_type == R_390_GOTPC)
9216 rc = apply_rela_bits(loc, val, 1, 32, 0);
9217diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9218index dd14532..1dfc145 100644
9219--- a/arch/s390/kernel/process.c
9220+++ b/arch/s390/kernel/process.c
9221@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9222 }
9223 return 0;
9224 }
9225-
9226-unsigned long arch_align_stack(unsigned long sp)
9227-{
9228- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9229- sp -= get_random_int() & ~PAGE_MASK;
9230- return sp & ~0xf;
9231-}
9232-
9233-static inline unsigned long brk_rnd(void)
9234-{
9235- /* 8MB for 32bit, 1GB for 64bit */
9236- if (is_32bit_task())
9237- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9238- else
9239- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9240-}
9241-
9242-unsigned long arch_randomize_brk(struct mm_struct *mm)
9243-{
9244- unsigned long ret;
9245-
9246- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9247- return (ret > mm->brk) ? ret : mm->brk;
9248-}
9249-
9250-unsigned long randomize_et_dyn(unsigned long base)
9251-{
9252- unsigned long ret;
9253-
9254- if (!(current->flags & PF_RANDOMIZE))
9255- return base;
9256- ret = PAGE_ALIGN(base + brk_rnd());
9257- return (ret > base) ? ret : base;
9258-}
9259diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9260index 9b436c2..54fbf0a 100644
9261--- a/arch/s390/mm/mmap.c
9262+++ b/arch/s390/mm/mmap.c
9263@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9264 */
9265 if (mmap_is_legacy()) {
9266 mm->mmap_base = mmap_base_legacy();
9267+
9268+#ifdef CONFIG_PAX_RANDMMAP
9269+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9270+ mm->mmap_base += mm->delta_mmap;
9271+#endif
9272+
9273 mm->get_unmapped_area = arch_get_unmapped_area;
9274 } else {
9275 mm->mmap_base = mmap_base();
9276+
9277+#ifdef CONFIG_PAX_RANDMMAP
9278+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9279+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9280+#endif
9281+
9282 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9283 }
9284 }
9285@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9286 */
9287 if (mmap_is_legacy()) {
9288 mm->mmap_base = mmap_base_legacy();
9289+
9290+#ifdef CONFIG_PAX_RANDMMAP
9291+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9292+ mm->mmap_base += mm->delta_mmap;
9293+#endif
9294+
9295 mm->get_unmapped_area = s390_get_unmapped_area;
9296 } else {
9297 mm->mmap_base = mmap_base();
9298+
9299+#ifdef CONFIG_PAX_RANDMMAP
9300+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9301+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9302+#endif
9303+
9304 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9305 }
9306 }
9307diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9308index ae3d59f..f65f075 100644
9309--- a/arch/score/include/asm/cache.h
9310+++ b/arch/score/include/asm/cache.h
9311@@ -1,7 +1,9 @@
9312 #ifndef _ASM_SCORE_CACHE_H
9313 #define _ASM_SCORE_CACHE_H
9314
9315+#include <linux/const.h>
9316+
9317 #define L1_CACHE_SHIFT 4
9318-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9319+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9320
9321 #endif /* _ASM_SCORE_CACHE_H */
9322diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9323index f9f3cd5..58ff438 100644
9324--- a/arch/score/include/asm/exec.h
9325+++ b/arch/score/include/asm/exec.h
9326@@ -1,6 +1,6 @@
9327 #ifndef _ASM_SCORE_EXEC_H
9328 #define _ASM_SCORE_EXEC_H
9329
9330-extern unsigned long arch_align_stack(unsigned long sp);
9331+#define arch_align_stack(x) (x)
9332
9333 #endif /* _ASM_SCORE_EXEC_H */
9334diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9335index a1519ad3..e8ac1ff 100644
9336--- a/arch/score/kernel/process.c
9337+++ b/arch/score/kernel/process.c
9338@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9339
9340 return task_pt_regs(task)->cp0_epc;
9341 }
9342-
9343-unsigned long arch_align_stack(unsigned long sp)
9344-{
9345- return sp;
9346-}
9347diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9348index ef9e555..331bd29 100644
9349--- a/arch/sh/include/asm/cache.h
9350+++ b/arch/sh/include/asm/cache.h
9351@@ -9,10 +9,11 @@
9352 #define __ASM_SH_CACHE_H
9353 #ifdef __KERNEL__
9354
9355+#include <linux/const.h>
9356 #include <linux/init.h>
9357 #include <cpu/cache.h>
9358
9359-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9360+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9361
9362 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9363
9364diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9365index 6777177..cb5e44f 100644
9366--- a/arch/sh/mm/mmap.c
9367+++ b/arch/sh/mm/mmap.c
9368@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9369 struct mm_struct *mm = current->mm;
9370 struct vm_area_struct *vma;
9371 int do_colour_align;
9372+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9373 struct vm_unmapped_area_info info;
9374
9375 if (flags & MAP_FIXED) {
9376@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9377 if (filp || (flags & MAP_SHARED))
9378 do_colour_align = 1;
9379
9380+#ifdef CONFIG_PAX_RANDMMAP
9381+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9382+#endif
9383+
9384 if (addr) {
9385 if (do_colour_align)
9386 addr = COLOUR_ALIGN(addr, pgoff);
9387@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9388 addr = PAGE_ALIGN(addr);
9389
9390 vma = find_vma(mm, addr);
9391- if (TASK_SIZE - len >= addr &&
9392- (!vma || addr + len <= vma->vm_start))
9393+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9394 return addr;
9395 }
9396
9397 info.flags = 0;
9398 info.length = len;
9399- info.low_limit = TASK_UNMAPPED_BASE;
9400+ info.low_limit = mm->mmap_base;
9401 info.high_limit = TASK_SIZE;
9402 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9403 info.align_offset = pgoff << PAGE_SHIFT;
9404@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9405 struct mm_struct *mm = current->mm;
9406 unsigned long addr = addr0;
9407 int do_colour_align;
9408+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9409 struct vm_unmapped_area_info info;
9410
9411 if (flags & MAP_FIXED) {
9412@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9413 if (filp || (flags & MAP_SHARED))
9414 do_colour_align = 1;
9415
9416+#ifdef CONFIG_PAX_RANDMMAP
9417+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9418+#endif
9419+
9420 /* requesting a specific address */
9421 if (addr) {
9422 if (do_colour_align)
9423@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9424 addr = PAGE_ALIGN(addr);
9425
9426 vma = find_vma(mm, addr);
9427- if (TASK_SIZE - len >= addr &&
9428- (!vma || addr + len <= vma->vm_start))
9429+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9430 return addr;
9431 }
9432
9433@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9434 VM_BUG_ON(addr != -ENOMEM);
9435 info.flags = 0;
9436 info.low_limit = TASK_UNMAPPED_BASE;
9437+
9438+#ifdef CONFIG_PAX_RANDMMAP
9439+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9440+ info.low_limit += mm->delta_mmap;
9441+#endif
9442+
9443 info.high_limit = TASK_SIZE;
9444 addr = vm_unmapped_area(&info);
9445 }
9446diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9447index be56a24..443328f 100644
9448--- a/arch/sparc/include/asm/atomic_64.h
9449+++ b/arch/sparc/include/asm/atomic_64.h
9450@@ -14,18 +14,40 @@
9451 #define ATOMIC64_INIT(i) { (i) }
9452
9453 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9454+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9455+{
9456+ return v->counter;
9457+}
9458 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9459+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9460+{
9461+ return v->counter;
9462+}
9463
9464 #define atomic_set(v, i) (((v)->counter) = i)
9465+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9466+{
9467+ v->counter = i;
9468+}
9469 #define atomic64_set(v, i) (((v)->counter) = i)
9470+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9471+{
9472+ v->counter = i;
9473+}
9474
9475 extern void atomic_add(int, atomic_t *);
9476+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9477 extern void atomic64_add(long, atomic64_t *);
9478+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9479 extern void atomic_sub(int, atomic_t *);
9480+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9481 extern void atomic64_sub(long, atomic64_t *);
9482+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9483
9484 extern int atomic_add_ret(int, atomic_t *);
9485+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9486 extern long atomic64_add_ret(long, atomic64_t *);
9487+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9488 extern int atomic_sub_ret(int, atomic_t *);
9489 extern long atomic64_sub_ret(long, atomic64_t *);
9490
9491@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9492 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9493
9494 #define atomic_inc_return(v) atomic_add_ret(1, v)
9495+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9496+{
9497+ return atomic_add_ret_unchecked(1, v);
9498+}
9499 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9500+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9501+{
9502+ return atomic64_add_ret_unchecked(1, v);
9503+}
9504
9505 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9506 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9507
9508 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9509+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9510+{
9511+ return atomic_add_ret_unchecked(i, v);
9512+}
9513 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9514+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9515+{
9516+ return atomic64_add_ret_unchecked(i, v);
9517+}
9518
9519 /*
9520 * atomic_inc_and_test - increment and test
9521@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9522 * other cases.
9523 */
9524 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9525+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9526+{
9527+ return atomic_inc_return_unchecked(v) == 0;
9528+}
9529 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9530
9531 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9532@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9533 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9534
9535 #define atomic_inc(v) atomic_add(1, v)
9536+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9537+{
9538+ atomic_add_unchecked(1, v);
9539+}
9540 #define atomic64_inc(v) atomic64_add(1, v)
9541+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9542+{
9543+ atomic64_add_unchecked(1, v);
9544+}
9545
9546 #define atomic_dec(v) atomic_sub(1, v)
9547+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9548+{
9549+ atomic_sub_unchecked(1, v);
9550+}
9551 #define atomic64_dec(v) atomic64_sub(1, v)
9552+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9553+{
9554+ atomic64_sub_unchecked(1, v);
9555+}
9556
9557 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9558 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9559
9560 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9561+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9562+{
9563+ return cmpxchg(&v->counter, old, new);
9564+}
9565 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9566+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9567+{
9568+ return xchg(&v->counter, new);
9569+}
9570
9571 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9572 {
9573- int c, old;
9574+ int c, old, new;
9575 c = atomic_read(v);
9576 for (;;) {
9577- if (unlikely(c == (u)))
9578+ if (unlikely(c == u))
9579 break;
9580- old = atomic_cmpxchg((v), c, c + (a));
9581+
9582+ asm volatile("addcc %2, %0, %0\n"
9583+
9584+#ifdef CONFIG_PAX_REFCOUNT
9585+ "tvs %%icc, 6\n"
9586+#endif
9587+
9588+ : "=r" (new)
9589+ : "0" (c), "ir" (a)
9590+ : "cc");
9591+
9592+ old = atomic_cmpxchg(v, c, new);
9593 if (likely(old == c))
9594 break;
9595 c = old;
9596@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9597 #define atomic64_cmpxchg(v, o, n) \
9598 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9599 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9600+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9601+{
9602+ return xchg(&v->counter, new);
9603+}
9604
9605 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9606 {
9607- long c, old;
9608+ long c, old, new;
9609 c = atomic64_read(v);
9610 for (;;) {
9611- if (unlikely(c == (u)))
9612+ if (unlikely(c == u))
9613 break;
9614- old = atomic64_cmpxchg((v), c, c + (a));
9615+
9616+ asm volatile("addcc %2, %0, %0\n"
9617+
9618+#ifdef CONFIG_PAX_REFCOUNT
9619+ "tvs %%xcc, 6\n"
9620+#endif
9621+
9622+ : "=r" (new)
9623+ : "0" (c), "ir" (a)
9624+ : "cc");
9625+
9626+ old = atomic64_cmpxchg(v, c, new);
9627 if (likely(old == c))
9628 break;
9629 c = old;
9630 }
9631- return c != (u);
9632+ return c != u;
9633 }
9634
9635 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9636diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9637index 5bb6991..5c2132e 100644
9638--- a/arch/sparc/include/asm/cache.h
9639+++ b/arch/sparc/include/asm/cache.h
9640@@ -7,10 +7,12 @@
9641 #ifndef _SPARC_CACHE_H
9642 #define _SPARC_CACHE_H
9643
9644+#include <linux/const.h>
9645+
9646 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9647
9648 #define L1_CACHE_SHIFT 5
9649-#define L1_CACHE_BYTES 32
9650+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9651
9652 #ifdef CONFIG_SPARC32
9653 #define SMP_CACHE_BYTES_SHIFT 5
9654diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9655index a24e41f..47677ff 100644
9656--- a/arch/sparc/include/asm/elf_32.h
9657+++ b/arch/sparc/include/asm/elf_32.h
9658@@ -114,6 +114,13 @@ typedef struct {
9659
9660 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9661
9662+#ifdef CONFIG_PAX_ASLR
9663+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9664+
9665+#define PAX_DELTA_MMAP_LEN 16
9666+#define PAX_DELTA_STACK_LEN 16
9667+#endif
9668+
9669 /* This yields a mask that user programs can use to figure out what
9670 instruction set this cpu supports. This can NOT be done in userspace
9671 on Sparc. */
9672diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9673index 370ca1e..d4f4a98 100644
9674--- a/arch/sparc/include/asm/elf_64.h
9675+++ b/arch/sparc/include/asm/elf_64.h
9676@@ -189,6 +189,13 @@ typedef struct {
9677 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9678 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9679
9680+#ifdef CONFIG_PAX_ASLR
9681+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9682+
9683+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9684+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9685+#endif
9686+
9687 extern unsigned long sparc64_elf_hwcap;
9688 #define ELF_HWCAP sparc64_elf_hwcap
9689
9690diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9691index 9b1c36d..209298b 100644
9692--- a/arch/sparc/include/asm/pgalloc_32.h
9693+++ b/arch/sparc/include/asm/pgalloc_32.h
9694@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9695 }
9696
9697 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9698+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9699
9700 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9701 unsigned long address)
9702diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9703index bcfe063..b333142 100644
9704--- a/arch/sparc/include/asm/pgalloc_64.h
9705+++ b/arch/sparc/include/asm/pgalloc_64.h
9706@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9707 }
9708
9709 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9710+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9711
9712 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9713 {
9714diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9715index 59ba6f6..4518128 100644
9716--- a/arch/sparc/include/asm/pgtable.h
9717+++ b/arch/sparc/include/asm/pgtable.h
9718@@ -5,4 +5,8 @@
9719 #else
9720 #include <asm/pgtable_32.h>
9721 #endif
9722+
9723+#define ktla_ktva(addr) (addr)
9724+#define ktva_ktla(addr) (addr)
9725+
9726 #endif
9727diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9728index 502f632..da1917f 100644
9729--- a/arch/sparc/include/asm/pgtable_32.h
9730+++ b/arch/sparc/include/asm/pgtable_32.h
9731@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9732 #define PAGE_SHARED SRMMU_PAGE_SHARED
9733 #define PAGE_COPY SRMMU_PAGE_COPY
9734 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9735+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9736+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9737+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9738 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9739
9740 /* Top-level page directory - dummy used by init-mm.
9741@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9742
9743 /* xwr */
9744 #define __P000 PAGE_NONE
9745-#define __P001 PAGE_READONLY
9746-#define __P010 PAGE_COPY
9747-#define __P011 PAGE_COPY
9748+#define __P001 PAGE_READONLY_NOEXEC
9749+#define __P010 PAGE_COPY_NOEXEC
9750+#define __P011 PAGE_COPY_NOEXEC
9751 #define __P100 PAGE_READONLY
9752 #define __P101 PAGE_READONLY
9753 #define __P110 PAGE_COPY
9754 #define __P111 PAGE_COPY
9755
9756 #define __S000 PAGE_NONE
9757-#define __S001 PAGE_READONLY
9758-#define __S010 PAGE_SHARED
9759-#define __S011 PAGE_SHARED
9760+#define __S001 PAGE_READONLY_NOEXEC
9761+#define __S010 PAGE_SHARED_NOEXEC
9762+#define __S011 PAGE_SHARED_NOEXEC
9763 #define __S100 PAGE_READONLY
9764 #define __S101 PAGE_READONLY
9765 #define __S110 PAGE_SHARED
9766diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9767index 79da178..c2eede8 100644
9768--- a/arch/sparc/include/asm/pgtsrmmu.h
9769+++ b/arch/sparc/include/asm/pgtsrmmu.h
9770@@ -115,6 +115,11 @@
9771 SRMMU_EXEC | SRMMU_REF)
9772 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9773 SRMMU_EXEC | SRMMU_REF)
9774+
9775+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9776+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9777+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9778+
9779 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9780 SRMMU_DIRTY | SRMMU_REF)
9781
9782diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9783index 9689176..63c18ea 100644
9784--- a/arch/sparc/include/asm/spinlock_64.h
9785+++ b/arch/sparc/include/asm/spinlock_64.h
9786@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9787
9788 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9789
9790-static void inline arch_read_lock(arch_rwlock_t *lock)
9791+static inline void arch_read_lock(arch_rwlock_t *lock)
9792 {
9793 unsigned long tmp1, tmp2;
9794
9795 __asm__ __volatile__ (
9796 "1: ldsw [%2], %0\n"
9797 " brlz,pn %0, 2f\n"
9798-"4: add %0, 1, %1\n"
9799+"4: addcc %0, 1, %1\n"
9800+
9801+#ifdef CONFIG_PAX_REFCOUNT
9802+" tvs %%icc, 6\n"
9803+#endif
9804+
9805 " cas [%2], %0, %1\n"
9806 " cmp %0, %1\n"
9807 " bne,pn %%icc, 1b\n"
9808@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9809 " .previous"
9810 : "=&r" (tmp1), "=&r" (tmp2)
9811 : "r" (lock)
9812- : "memory");
9813+ : "memory", "cc");
9814 }
9815
9816-static int inline arch_read_trylock(arch_rwlock_t *lock)
9817+static inline int arch_read_trylock(arch_rwlock_t *lock)
9818 {
9819 int tmp1, tmp2;
9820
9821@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9822 "1: ldsw [%2], %0\n"
9823 " brlz,a,pn %0, 2f\n"
9824 " mov 0, %0\n"
9825-" add %0, 1, %1\n"
9826+" addcc %0, 1, %1\n"
9827+
9828+#ifdef CONFIG_PAX_REFCOUNT
9829+" tvs %%icc, 6\n"
9830+#endif
9831+
9832 " cas [%2], %0, %1\n"
9833 " cmp %0, %1\n"
9834 " bne,pn %%icc, 1b\n"
9835@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9836 return tmp1;
9837 }
9838
9839-static void inline arch_read_unlock(arch_rwlock_t *lock)
9840+static inline void arch_read_unlock(arch_rwlock_t *lock)
9841 {
9842 unsigned long tmp1, tmp2;
9843
9844 __asm__ __volatile__(
9845 "1: lduw [%2], %0\n"
9846-" sub %0, 1, %1\n"
9847+" subcc %0, 1, %1\n"
9848+
9849+#ifdef CONFIG_PAX_REFCOUNT
9850+" tvs %%icc, 6\n"
9851+#endif
9852+
9853 " cas [%2], %0, %1\n"
9854 " cmp %0, %1\n"
9855 " bne,pn %%xcc, 1b\n"
9856@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9857 : "memory");
9858 }
9859
9860-static void inline arch_write_lock(arch_rwlock_t *lock)
9861+static inline void arch_write_lock(arch_rwlock_t *lock)
9862 {
9863 unsigned long mask, tmp1, tmp2;
9864
9865@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9866 : "memory");
9867 }
9868
9869-static void inline arch_write_unlock(arch_rwlock_t *lock)
9870+static inline void arch_write_unlock(arch_rwlock_t *lock)
9871 {
9872 __asm__ __volatile__(
9873 " stw %%g0, [%0]"
9874@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9875 : "memory");
9876 }
9877
9878-static int inline arch_write_trylock(arch_rwlock_t *lock)
9879+static inline int arch_write_trylock(arch_rwlock_t *lock)
9880 {
9881 unsigned long mask, tmp1, tmp2, result;
9882
9883diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9884index 96efa7a..16858bf 100644
9885--- a/arch/sparc/include/asm/thread_info_32.h
9886+++ b/arch/sparc/include/asm/thread_info_32.h
9887@@ -49,6 +49,8 @@ struct thread_info {
9888 unsigned long w_saved;
9889
9890 struct restart_block restart_block;
9891+
9892+ unsigned long lowest_stack;
9893 };
9894
9895 /*
9896diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9897index a5f01ac..703b554 100644
9898--- a/arch/sparc/include/asm/thread_info_64.h
9899+++ b/arch/sparc/include/asm/thread_info_64.h
9900@@ -63,6 +63,8 @@ struct thread_info {
9901 struct pt_regs *kern_una_regs;
9902 unsigned int kern_una_insn;
9903
9904+ unsigned long lowest_stack;
9905+
9906 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9907 };
9908
9909@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9910 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9911 /* flag bit 4 is available */
9912 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9913-/* flag bit 6 is available */
9914+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9915 #define TIF_32BIT 7 /* 32-bit binary */
9916 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9917 #define TIF_SECCOMP 9 /* secure computing */
9918 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9919 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9920+
9921 /* NOTE: Thread flags >= 12 should be ones we have no interest
9922 * in using in assembly, else we can't use the mask as
9923 * an immediate value in instructions such as andcc.
9924@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9925 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9926 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9927 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9928+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9929
9930 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9931 _TIF_DO_NOTIFY_RESUME_MASK | \
9932 _TIF_NEED_RESCHED)
9933 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9934
9935+#define _TIF_WORK_SYSCALL \
9936+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9937+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9938+
9939+
9940 /*
9941 * Thread-synchronous status.
9942 *
9943diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9944index 0167d26..767bb0c 100644
9945--- a/arch/sparc/include/asm/uaccess.h
9946+++ b/arch/sparc/include/asm/uaccess.h
9947@@ -1,5 +1,6 @@
9948 #ifndef ___ASM_SPARC_UACCESS_H
9949 #define ___ASM_SPARC_UACCESS_H
9950+
9951 #if defined(__sparc__) && defined(__arch64__)
9952 #include <asm/uaccess_64.h>
9953 #else
9954diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9955index 53a28dd..50c38c3 100644
9956--- a/arch/sparc/include/asm/uaccess_32.h
9957+++ b/arch/sparc/include/asm/uaccess_32.h
9958@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9959
9960 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9961 {
9962- if (n && __access_ok((unsigned long) to, n))
9963+ if ((long)n < 0)
9964+ return n;
9965+
9966+ if (n && __access_ok((unsigned long) to, n)) {
9967+ if (!__builtin_constant_p(n))
9968+ check_object_size(from, n, true);
9969 return __copy_user(to, (__force void __user *) from, n);
9970- else
9971+ } else
9972 return n;
9973 }
9974
9975 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9976 {
9977+ if ((long)n < 0)
9978+ return n;
9979+
9980+ if (!__builtin_constant_p(n))
9981+ check_object_size(from, n, true);
9982+
9983 return __copy_user(to, (__force void __user *) from, n);
9984 }
9985
9986 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9987 {
9988- if (n && __access_ok((unsigned long) from, n))
9989+ if ((long)n < 0)
9990+ return n;
9991+
9992+ if (n && __access_ok((unsigned long) from, n)) {
9993+ if (!__builtin_constant_p(n))
9994+ check_object_size(to, n, false);
9995 return __copy_user((__force void __user *) to, from, n);
9996- else
9997+ } else
9998 return n;
9999 }
10000
10001 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10002 {
10003+ if ((long)n < 0)
10004+ return n;
10005+
10006 return __copy_user((__force void __user *) to, from, n);
10007 }
10008
10009diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10010index ad7e178..c9e7423 100644
10011--- a/arch/sparc/include/asm/uaccess_64.h
10012+++ b/arch/sparc/include/asm/uaccess_64.h
10013@@ -10,6 +10,7 @@
10014 #include <linux/compiler.h>
10015 #include <linux/string.h>
10016 #include <linux/thread_info.h>
10017+#include <linux/kernel.h>
10018 #include <asm/asi.h>
10019 #include <asm/spitfire.h>
10020 #include <asm-generic/uaccess-unaligned.h>
10021@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10022 static inline unsigned long __must_check
10023 copy_from_user(void *to, const void __user *from, unsigned long size)
10024 {
10025- unsigned long ret = ___copy_from_user(to, from, size);
10026+ unsigned long ret;
10027
10028+ if ((long)size < 0 || size > INT_MAX)
10029+ return size;
10030+
10031+ if (!__builtin_constant_p(size))
10032+ check_object_size(to, size, false);
10033+
10034+ ret = ___copy_from_user(to, from, size);
10035 if (unlikely(ret))
10036 ret = copy_from_user_fixup(to, from, size);
10037
10038@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10039 static inline unsigned long __must_check
10040 copy_to_user(void __user *to, const void *from, unsigned long size)
10041 {
10042- unsigned long ret = ___copy_to_user(to, from, size);
10043+ unsigned long ret;
10044
10045+ if ((long)size < 0 || size > INT_MAX)
10046+ return size;
10047+
10048+ if (!__builtin_constant_p(size))
10049+ check_object_size(from, size, true);
10050+
10051+ ret = ___copy_to_user(to, from, size);
10052 if (unlikely(ret))
10053 ret = copy_to_user_fixup(to, from, size);
10054 return ret;
10055diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10056index d15cc17..d0ae796 100644
10057--- a/arch/sparc/kernel/Makefile
10058+++ b/arch/sparc/kernel/Makefile
10059@@ -4,7 +4,7 @@
10060 #
10061
10062 asflags-y := -ansi
10063-ccflags-y := -Werror
10064+#ccflags-y := -Werror
10065
10066 extra-y := head_$(BITS).o
10067
10068diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10069index 510baec..9ff2607 100644
10070--- a/arch/sparc/kernel/process_32.c
10071+++ b/arch/sparc/kernel/process_32.c
10072@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10073
10074 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10075 r->psr, r->pc, r->npc, r->y, print_tainted());
10076- printk("PC: <%pS>\n", (void *) r->pc);
10077+ printk("PC: <%pA>\n", (void *) r->pc);
10078 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10079 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10080 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10081 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10082 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10083 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10084- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10085+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10086
10087 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10088 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10089@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10090 rw = (struct reg_window32 *) fp;
10091 pc = rw->ins[7];
10092 printk("[%08lx : ", pc);
10093- printk("%pS ] ", (void *) pc);
10094+ printk("%pA ] ", (void *) pc);
10095 fp = rw->ins[6];
10096 } while (++count < 16);
10097 printk("\n");
10098diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10099index d7b4967..2edf827 100644
10100--- a/arch/sparc/kernel/process_64.c
10101+++ b/arch/sparc/kernel/process_64.c
10102@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10103 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10104 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10105 if (regs->tstate & TSTATE_PRIV)
10106- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10107+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10108 }
10109
10110 void show_regs(struct pt_regs *regs)
10111@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10112
10113 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10114 regs->tpc, regs->tnpc, regs->y, print_tainted());
10115- printk("TPC: <%pS>\n", (void *) regs->tpc);
10116+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10117 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10118 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10119 regs->u_regs[3]);
10120@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10121 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10122 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10123 regs->u_regs[15]);
10124- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10125+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10126 show_regwindow(regs);
10127 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10128 }
10129@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10130 ((tp && tp->task) ? tp->task->pid : -1));
10131
10132 if (gp->tstate & TSTATE_PRIV) {
10133- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10134+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10135 (void *) gp->tpc,
10136 (void *) gp->o7,
10137 (void *) gp->i7,
10138diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10139index 79cc0d1..ec62734 100644
10140--- a/arch/sparc/kernel/prom_common.c
10141+++ b/arch/sparc/kernel/prom_common.c
10142@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10143
10144 unsigned int prom_early_allocated __initdata;
10145
10146-static struct of_pdt_ops prom_sparc_ops __initdata = {
10147+static struct of_pdt_ops prom_sparc_ops __initconst = {
10148 .nextprop = prom_common_nextprop,
10149 .getproplen = prom_getproplen,
10150 .getproperty = prom_getproperty,
10151diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10152index c13c9f2..d572c34 100644
10153--- a/arch/sparc/kernel/ptrace_64.c
10154+++ b/arch/sparc/kernel/ptrace_64.c
10155@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10156 return ret;
10157 }
10158
10159+#ifdef CONFIG_GRKERNSEC_SETXID
10160+extern void gr_delayed_cred_worker(void);
10161+#endif
10162+
10163 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10164 {
10165 int ret = 0;
10166@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10167 if (test_thread_flag(TIF_NOHZ))
10168 user_exit();
10169
10170+#ifdef CONFIG_GRKERNSEC_SETXID
10171+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10172+ gr_delayed_cred_worker();
10173+#endif
10174+
10175 if (test_thread_flag(TIF_SYSCALL_TRACE))
10176 ret = tracehook_report_syscall_entry(regs);
10177
10178@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10179 if (test_thread_flag(TIF_NOHZ))
10180 user_exit();
10181
10182+#ifdef CONFIG_GRKERNSEC_SETXID
10183+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10184+ gr_delayed_cred_worker();
10185+#endif
10186+
10187 audit_syscall_exit(regs);
10188
10189 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10190diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10191index b085311..6f885f7 100644
10192--- a/arch/sparc/kernel/smp_64.c
10193+++ b/arch/sparc/kernel/smp_64.c
10194@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10195 extern unsigned long xcall_flush_dcache_page_spitfire;
10196
10197 #ifdef CONFIG_DEBUG_DCFLUSH
10198-extern atomic_t dcpage_flushes;
10199-extern atomic_t dcpage_flushes_xcall;
10200+extern atomic_unchecked_t dcpage_flushes;
10201+extern atomic_unchecked_t dcpage_flushes_xcall;
10202 #endif
10203
10204 static inline void __local_flush_dcache_page(struct page *page)
10205@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10206 return;
10207
10208 #ifdef CONFIG_DEBUG_DCFLUSH
10209- atomic_inc(&dcpage_flushes);
10210+ atomic_inc_unchecked(&dcpage_flushes);
10211 #endif
10212
10213 this_cpu = get_cpu();
10214@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10215 xcall_deliver(data0, __pa(pg_addr),
10216 (u64) pg_addr, cpumask_of(cpu));
10217 #ifdef CONFIG_DEBUG_DCFLUSH
10218- atomic_inc(&dcpage_flushes_xcall);
10219+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10220 #endif
10221 }
10222 }
10223@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10224 preempt_disable();
10225
10226 #ifdef CONFIG_DEBUG_DCFLUSH
10227- atomic_inc(&dcpage_flushes);
10228+ atomic_inc_unchecked(&dcpage_flushes);
10229 #endif
10230 data0 = 0;
10231 pg_addr = page_address(page);
10232@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10233 xcall_deliver(data0, __pa(pg_addr),
10234 (u64) pg_addr, cpu_online_mask);
10235 #ifdef CONFIG_DEBUG_DCFLUSH
10236- atomic_inc(&dcpage_flushes_xcall);
10237+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10238 #endif
10239 }
10240 __local_flush_dcache_page(page);
10241diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10242index 3a8d184..49498a8 100644
10243--- a/arch/sparc/kernel/sys_sparc_32.c
10244+++ b/arch/sparc/kernel/sys_sparc_32.c
10245@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10246 if (len > TASK_SIZE - PAGE_SIZE)
10247 return -ENOMEM;
10248 if (!addr)
10249- addr = TASK_UNMAPPED_BASE;
10250+ addr = current->mm->mmap_base;
10251
10252 info.flags = 0;
10253 info.length = len;
10254diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10255index beb0b5a..5a153f7 100644
10256--- a/arch/sparc/kernel/sys_sparc_64.c
10257+++ b/arch/sparc/kernel/sys_sparc_64.c
10258@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10259 struct vm_area_struct * vma;
10260 unsigned long task_size = TASK_SIZE;
10261 int do_color_align;
10262+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10263 struct vm_unmapped_area_info info;
10264
10265 if (flags & MAP_FIXED) {
10266 /* We do not accept a shared mapping if it would violate
10267 * cache aliasing constraints.
10268 */
10269- if ((flags & MAP_SHARED) &&
10270+ if ((filp || (flags & MAP_SHARED)) &&
10271 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10272 return -EINVAL;
10273 return addr;
10274@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10275 if (filp || (flags & MAP_SHARED))
10276 do_color_align = 1;
10277
10278+#ifdef CONFIG_PAX_RANDMMAP
10279+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10280+#endif
10281+
10282 if (addr) {
10283 if (do_color_align)
10284 addr = COLOR_ALIGN(addr, pgoff);
10285@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10286 addr = PAGE_ALIGN(addr);
10287
10288 vma = find_vma(mm, addr);
10289- if (task_size - len >= addr &&
10290- (!vma || addr + len <= vma->vm_start))
10291+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10292 return addr;
10293 }
10294
10295 info.flags = 0;
10296 info.length = len;
10297- info.low_limit = TASK_UNMAPPED_BASE;
10298+ info.low_limit = mm->mmap_base;
10299 info.high_limit = min(task_size, VA_EXCLUDE_START);
10300 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10301 info.align_offset = pgoff << PAGE_SHIFT;
10302+ info.threadstack_offset = offset;
10303 addr = vm_unmapped_area(&info);
10304
10305 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10306 VM_BUG_ON(addr != -ENOMEM);
10307 info.low_limit = VA_EXCLUDE_END;
10308+
10309+#ifdef CONFIG_PAX_RANDMMAP
10310+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10311+ info.low_limit += mm->delta_mmap;
10312+#endif
10313+
10314 info.high_limit = task_size;
10315 addr = vm_unmapped_area(&info);
10316 }
10317@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10318 unsigned long task_size = STACK_TOP32;
10319 unsigned long addr = addr0;
10320 int do_color_align;
10321+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10322 struct vm_unmapped_area_info info;
10323
10324 /* This should only ever run for 32-bit processes. */
10325@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10326 /* We do not accept a shared mapping if it would violate
10327 * cache aliasing constraints.
10328 */
10329- if ((flags & MAP_SHARED) &&
10330+ if ((filp || (flags & MAP_SHARED)) &&
10331 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10332 return -EINVAL;
10333 return addr;
10334@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10335 if (filp || (flags & MAP_SHARED))
10336 do_color_align = 1;
10337
10338+#ifdef CONFIG_PAX_RANDMMAP
10339+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10340+#endif
10341+
10342 /* requesting a specific address */
10343 if (addr) {
10344 if (do_color_align)
10345@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10346 addr = PAGE_ALIGN(addr);
10347
10348 vma = find_vma(mm, addr);
10349- if (task_size - len >= addr &&
10350- (!vma || addr + len <= vma->vm_start))
10351+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10352 return addr;
10353 }
10354
10355@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10356 info.high_limit = mm->mmap_base;
10357 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10358 info.align_offset = pgoff << PAGE_SHIFT;
10359+ info.threadstack_offset = offset;
10360 addr = vm_unmapped_area(&info);
10361
10362 /*
10363@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10364 VM_BUG_ON(addr != -ENOMEM);
10365 info.flags = 0;
10366 info.low_limit = TASK_UNMAPPED_BASE;
10367+
10368+#ifdef CONFIG_PAX_RANDMMAP
10369+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10370+ info.low_limit += mm->delta_mmap;
10371+#endif
10372+
10373 info.high_limit = STACK_TOP32;
10374 addr = vm_unmapped_area(&info);
10375 }
10376@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10377 EXPORT_SYMBOL(get_fb_unmapped_area);
10378
10379 /* Essentially the same as PowerPC. */
10380-static unsigned long mmap_rnd(void)
10381+static unsigned long mmap_rnd(struct mm_struct *mm)
10382 {
10383 unsigned long rnd = 0UL;
10384
10385+#ifdef CONFIG_PAX_RANDMMAP
10386+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10387+#endif
10388+
10389 if (current->flags & PF_RANDOMIZE) {
10390 unsigned long val = get_random_int();
10391 if (test_thread_flag(TIF_32BIT))
10392@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10393
10394 void arch_pick_mmap_layout(struct mm_struct *mm)
10395 {
10396- unsigned long random_factor = mmap_rnd();
10397+ unsigned long random_factor = mmap_rnd(mm);
10398 unsigned long gap;
10399
10400 /*
10401@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10402 gap == RLIM_INFINITY ||
10403 sysctl_legacy_va_layout) {
10404 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10405+
10406+#ifdef CONFIG_PAX_RANDMMAP
10407+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10408+ mm->mmap_base += mm->delta_mmap;
10409+#endif
10410+
10411 mm->get_unmapped_area = arch_get_unmapped_area;
10412 } else {
10413 /* We know it's 32-bit */
10414@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10415 gap = (task_size / 6 * 5);
10416
10417 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10418+
10419+#ifdef CONFIG_PAX_RANDMMAP
10420+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10421+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10422+#endif
10423+
10424 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10425 }
10426 }
10427diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10428index 33a17e7..d87fb1f 100644
10429--- a/arch/sparc/kernel/syscalls.S
10430+++ b/arch/sparc/kernel/syscalls.S
10431@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10432 #endif
10433 .align 32
10434 1: ldx [%g6 + TI_FLAGS], %l5
10435- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10436+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10437 be,pt %icc, rtrap
10438 nop
10439 call syscall_trace_leave
10440@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10441
10442 srl %i3, 0, %o3 ! IEU0
10443 srl %i2, 0, %o2 ! IEU0 Group
10444- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10445+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10446 bne,pn %icc, linux_syscall_trace32 ! CTI
10447 mov %i0, %l5 ! IEU1
10448 5: call %l7 ! CTI Group brk forced
10449@@ -208,7 +208,7 @@ linux_sparc_syscall:
10450
10451 mov %i3, %o3 ! IEU1
10452 mov %i4, %o4 ! IEU0 Group
10453- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10454+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10455 bne,pn %icc, linux_syscall_trace ! CTI Group
10456 mov %i0, %l5 ! IEU0
10457 2: call %l7 ! CTI Group brk forced
10458@@ -223,7 +223,7 @@ ret_sys_call:
10459
10460 cmp %o0, -ERESTART_RESTARTBLOCK
10461 bgeu,pn %xcc, 1f
10462- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10463+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10464 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10465
10466 2:
10467diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10468index 6629829..036032d 100644
10469--- a/arch/sparc/kernel/traps_32.c
10470+++ b/arch/sparc/kernel/traps_32.c
10471@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10472 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10473 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10474
10475+extern void gr_handle_kernel_exploit(void);
10476+
10477 void die_if_kernel(char *str, struct pt_regs *regs)
10478 {
10479 static int die_counter;
10480@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10481 count++ < 30 &&
10482 (((unsigned long) rw) >= PAGE_OFFSET) &&
10483 !(((unsigned long) rw) & 0x7)) {
10484- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10485+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10486 (void *) rw->ins[7]);
10487 rw = (struct reg_window32 *)rw->ins[6];
10488 }
10489 }
10490 printk("Instruction DUMP:");
10491 instruction_dump ((unsigned long *) regs->pc);
10492- if(regs->psr & PSR_PS)
10493+ if(regs->psr & PSR_PS) {
10494+ gr_handle_kernel_exploit();
10495 do_exit(SIGKILL);
10496+ }
10497 do_exit(SIGSEGV);
10498 }
10499
10500diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10501index 4ced92f..965eeed 100644
10502--- a/arch/sparc/kernel/traps_64.c
10503+++ b/arch/sparc/kernel/traps_64.c
10504@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10505 i + 1,
10506 p->trapstack[i].tstate, p->trapstack[i].tpc,
10507 p->trapstack[i].tnpc, p->trapstack[i].tt);
10508- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10509+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10510 }
10511 }
10512
10513@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10514
10515 lvl -= 0x100;
10516 if (regs->tstate & TSTATE_PRIV) {
10517+
10518+#ifdef CONFIG_PAX_REFCOUNT
10519+ if (lvl == 6)
10520+ pax_report_refcount_overflow(regs);
10521+#endif
10522+
10523 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10524 die_if_kernel(buffer, regs);
10525 }
10526@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10527 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10528 {
10529 char buffer[32];
10530-
10531+
10532 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10533 0, lvl, SIGTRAP) == NOTIFY_STOP)
10534 return;
10535
10536+#ifdef CONFIG_PAX_REFCOUNT
10537+ if (lvl == 6)
10538+ pax_report_refcount_overflow(regs);
10539+#endif
10540+
10541 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10542
10543 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10544@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10545 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10546 printk("%s" "ERROR(%d): ",
10547 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10548- printk("TPC<%pS>\n", (void *) regs->tpc);
10549+ printk("TPC<%pA>\n", (void *) regs->tpc);
10550 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10551 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10552 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10553@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10554 smp_processor_id(),
10555 (type & 0x1) ? 'I' : 'D',
10556 regs->tpc);
10557- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10558+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10559 panic("Irrecoverable Cheetah+ parity error.");
10560 }
10561
10562@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10563 smp_processor_id(),
10564 (type & 0x1) ? 'I' : 'D',
10565 regs->tpc);
10566- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10567+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10568 }
10569
10570 struct sun4v_error_entry {
10571@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10572 /*0x38*/u64 reserved_5;
10573 };
10574
10575-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10576-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10577+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10578+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10579
10580 static const char *sun4v_err_type_to_str(u8 type)
10581 {
10582@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10583 }
10584
10585 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10586- int cpu, const char *pfx, atomic_t *ocnt)
10587+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10588 {
10589 u64 *raw_ptr = (u64 *) ent;
10590 u32 attrs;
10591@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10592
10593 show_regs(regs);
10594
10595- if ((cnt = atomic_read(ocnt)) != 0) {
10596- atomic_set(ocnt, 0);
10597+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10598+ atomic_set_unchecked(ocnt, 0);
10599 wmb();
10600 printk("%s: Queue overflowed %d times.\n",
10601 pfx, cnt);
10602@@ -2046,7 +2057,7 @@ out:
10603 */
10604 void sun4v_resum_overflow(struct pt_regs *regs)
10605 {
10606- atomic_inc(&sun4v_resum_oflow_cnt);
10607+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10608 }
10609
10610 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10611@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10612 /* XXX Actually even this can make not that much sense. Perhaps
10613 * XXX we should just pull the plug and panic directly from here?
10614 */
10615- atomic_inc(&sun4v_nonresum_oflow_cnt);
10616+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10617 }
10618
10619 unsigned long sun4v_err_itlb_vaddr;
10620@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10621
10622 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10623 regs->tpc, tl);
10624- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10625+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10626 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10627- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10628+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10629 (void *) regs->u_regs[UREG_I7]);
10630 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10631 "pte[%lx] error[%lx]\n",
10632@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10633
10634 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10635 regs->tpc, tl);
10636- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10637+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10638 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10639- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10640+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10641 (void *) regs->u_regs[UREG_I7]);
10642 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10643 "pte[%lx] error[%lx]\n",
10644@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10645 fp = (unsigned long)sf->fp + STACK_BIAS;
10646 }
10647
10648- printk(" [%016lx] %pS\n", pc, (void *) pc);
10649+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10650 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10651 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10652 int index = tsk->curr_ret_stack;
10653 if (tsk->ret_stack && index >= graph) {
10654 pc = tsk->ret_stack[index - graph].ret;
10655- printk(" [%016lx] %pS\n", pc, (void *) pc);
10656+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10657 graph++;
10658 }
10659 }
10660@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10661 return (struct reg_window *) (fp + STACK_BIAS);
10662 }
10663
10664+extern void gr_handle_kernel_exploit(void);
10665+
10666 void die_if_kernel(char *str, struct pt_regs *regs)
10667 {
10668 static int die_counter;
10669@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10670 while (rw &&
10671 count++ < 30 &&
10672 kstack_valid(tp, (unsigned long) rw)) {
10673- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10674+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10675 (void *) rw->ins[7]);
10676
10677 rw = kernel_stack_up(rw);
10678@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10679 }
10680 user_instruction_dump ((unsigned int __user *) regs->tpc);
10681 }
10682- if (regs->tstate & TSTATE_PRIV)
10683+ if (regs->tstate & TSTATE_PRIV) {
10684+ gr_handle_kernel_exploit();
10685 do_exit(SIGKILL);
10686+ }
10687 do_exit(SIGSEGV);
10688 }
10689 EXPORT_SYMBOL(die_if_kernel);
10690diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10691index 3c1a7cb..73e1923 100644
10692--- a/arch/sparc/kernel/unaligned_64.c
10693+++ b/arch/sparc/kernel/unaligned_64.c
10694@@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10695 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10696
10697 if (__ratelimit(&ratelimit)) {
10698- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10699+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10700 regs->tpc, (void *) regs->tpc);
10701 }
10702 }
10703diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10704index dbe119b..089c7c1 100644
10705--- a/arch/sparc/lib/Makefile
10706+++ b/arch/sparc/lib/Makefile
10707@@ -2,7 +2,7 @@
10708 #
10709
10710 asflags-y := -ansi -DST_DIV0=0x02
10711-ccflags-y := -Werror
10712+#ccflags-y := -Werror
10713
10714 lib-$(CONFIG_SPARC32) += ashrdi3.o
10715 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10716diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10717index 85c233d..68500e0 100644
10718--- a/arch/sparc/lib/atomic_64.S
10719+++ b/arch/sparc/lib/atomic_64.S
10720@@ -17,7 +17,12 @@
10721 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10722 BACKOFF_SETUP(%o2)
10723 1: lduw [%o1], %g1
10724- add %g1, %o0, %g7
10725+ addcc %g1, %o0, %g7
10726+
10727+#ifdef CONFIG_PAX_REFCOUNT
10728+ tvs %icc, 6
10729+#endif
10730+
10731 cas [%o1], %g1, %g7
10732 cmp %g1, %g7
10733 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10734@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10735 2: BACKOFF_SPIN(%o2, %o3, 1b)
10736 ENDPROC(atomic_add)
10737
10738+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10739+ BACKOFF_SETUP(%o2)
10740+1: lduw [%o1], %g1
10741+ add %g1, %o0, %g7
10742+ cas [%o1], %g1, %g7
10743+ cmp %g1, %g7
10744+ bne,pn %icc, 2f
10745+ nop
10746+ retl
10747+ nop
10748+2: BACKOFF_SPIN(%o2, %o3, 1b)
10749+ENDPROC(atomic_add_unchecked)
10750+
10751 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10752 BACKOFF_SETUP(%o2)
10753 1: lduw [%o1], %g1
10754- sub %g1, %o0, %g7
10755+ subcc %g1, %o0, %g7
10756+
10757+#ifdef CONFIG_PAX_REFCOUNT
10758+ tvs %icc, 6
10759+#endif
10760+
10761 cas [%o1], %g1, %g7
10762 cmp %g1, %g7
10763 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10764@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10765 2: BACKOFF_SPIN(%o2, %o3, 1b)
10766 ENDPROC(atomic_sub)
10767
10768+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10769+ BACKOFF_SETUP(%o2)
10770+1: lduw [%o1], %g1
10771+ sub %g1, %o0, %g7
10772+ cas [%o1], %g1, %g7
10773+ cmp %g1, %g7
10774+ bne,pn %icc, 2f
10775+ nop
10776+ retl
10777+ nop
10778+2: BACKOFF_SPIN(%o2, %o3, 1b)
10779+ENDPROC(atomic_sub_unchecked)
10780+
10781 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10782 BACKOFF_SETUP(%o2)
10783 1: lduw [%o1], %g1
10784- add %g1, %o0, %g7
10785+ addcc %g1, %o0, %g7
10786+
10787+#ifdef CONFIG_PAX_REFCOUNT
10788+ tvs %icc, 6
10789+#endif
10790+
10791 cas [%o1], %g1, %g7
10792 cmp %g1, %g7
10793 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10794@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10795 2: BACKOFF_SPIN(%o2, %o3, 1b)
10796 ENDPROC(atomic_add_ret)
10797
10798+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10799+ BACKOFF_SETUP(%o2)
10800+1: lduw [%o1], %g1
10801+ addcc %g1, %o0, %g7
10802+ cas [%o1], %g1, %g7
10803+ cmp %g1, %g7
10804+ bne,pn %icc, 2f
10805+ add %g7, %o0, %g7
10806+ sra %g7, 0, %o0
10807+ retl
10808+ nop
10809+2: BACKOFF_SPIN(%o2, %o3, 1b)
10810+ENDPROC(atomic_add_ret_unchecked)
10811+
10812 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10813 BACKOFF_SETUP(%o2)
10814 1: lduw [%o1], %g1
10815- sub %g1, %o0, %g7
10816+ subcc %g1, %o0, %g7
10817+
10818+#ifdef CONFIG_PAX_REFCOUNT
10819+ tvs %icc, 6
10820+#endif
10821+
10822 cas [%o1], %g1, %g7
10823 cmp %g1, %g7
10824 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10825@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10826 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10827 BACKOFF_SETUP(%o2)
10828 1: ldx [%o1], %g1
10829- add %g1, %o0, %g7
10830+ addcc %g1, %o0, %g7
10831+
10832+#ifdef CONFIG_PAX_REFCOUNT
10833+ tvs %xcc, 6
10834+#endif
10835+
10836 casx [%o1], %g1, %g7
10837 cmp %g1, %g7
10838 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10839@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10840 2: BACKOFF_SPIN(%o2, %o3, 1b)
10841 ENDPROC(atomic64_add)
10842
10843+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10844+ BACKOFF_SETUP(%o2)
10845+1: ldx [%o1], %g1
10846+ addcc %g1, %o0, %g7
10847+ casx [%o1], %g1, %g7
10848+ cmp %g1, %g7
10849+ bne,pn %xcc, 2f
10850+ nop
10851+ retl
10852+ nop
10853+2: BACKOFF_SPIN(%o2, %o3, 1b)
10854+ENDPROC(atomic64_add_unchecked)
10855+
10856 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10857 BACKOFF_SETUP(%o2)
10858 1: ldx [%o1], %g1
10859- sub %g1, %o0, %g7
10860+ subcc %g1, %o0, %g7
10861+
10862+#ifdef CONFIG_PAX_REFCOUNT
10863+ tvs %xcc, 6
10864+#endif
10865+
10866 casx [%o1], %g1, %g7
10867 cmp %g1, %g7
10868 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10869@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10870 2: BACKOFF_SPIN(%o2, %o3, 1b)
10871 ENDPROC(atomic64_sub)
10872
10873+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10874+ BACKOFF_SETUP(%o2)
10875+1: ldx [%o1], %g1
10876+ subcc %g1, %o0, %g7
10877+ casx [%o1], %g1, %g7
10878+ cmp %g1, %g7
10879+ bne,pn %xcc, 2f
10880+ nop
10881+ retl
10882+ nop
10883+2: BACKOFF_SPIN(%o2, %o3, 1b)
10884+ENDPROC(atomic64_sub_unchecked)
10885+
10886 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10887 BACKOFF_SETUP(%o2)
10888 1: ldx [%o1], %g1
10889- add %g1, %o0, %g7
10890+ addcc %g1, %o0, %g7
10891+
10892+#ifdef CONFIG_PAX_REFCOUNT
10893+ tvs %xcc, 6
10894+#endif
10895+
10896 casx [%o1], %g1, %g7
10897 cmp %g1, %g7
10898 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10899@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10900 2: BACKOFF_SPIN(%o2, %o3, 1b)
10901 ENDPROC(atomic64_add_ret)
10902
10903+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10904+ BACKOFF_SETUP(%o2)
10905+1: ldx [%o1], %g1
10906+ addcc %g1, %o0, %g7
10907+ casx [%o1], %g1, %g7
10908+ cmp %g1, %g7
10909+ bne,pn %xcc, 2f
10910+ add %g7, %o0, %g7
10911+ mov %g7, %o0
10912+ retl
10913+ nop
10914+2: BACKOFF_SPIN(%o2, %o3, 1b)
10915+ENDPROC(atomic64_add_ret_unchecked)
10916+
10917 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10918 BACKOFF_SETUP(%o2)
10919 1: ldx [%o1], %g1
10920- sub %g1, %o0, %g7
10921+ subcc %g1, %o0, %g7
10922+
10923+#ifdef CONFIG_PAX_REFCOUNT
10924+ tvs %xcc, 6
10925+#endif
10926+
10927 casx [%o1], %g1, %g7
10928 cmp %g1, %g7
10929 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10930diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10931index 323335b..ed85ea2 100644
10932--- a/arch/sparc/lib/ksyms.c
10933+++ b/arch/sparc/lib/ksyms.c
10934@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10935
10936 /* Atomic counter implementation. */
10937 EXPORT_SYMBOL(atomic_add);
10938+EXPORT_SYMBOL(atomic_add_unchecked);
10939 EXPORT_SYMBOL(atomic_add_ret);
10940+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10941 EXPORT_SYMBOL(atomic_sub);
10942+EXPORT_SYMBOL(atomic_sub_unchecked);
10943 EXPORT_SYMBOL(atomic_sub_ret);
10944 EXPORT_SYMBOL(atomic64_add);
10945+EXPORT_SYMBOL(atomic64_add_unchecked);
10946 EXPORT_SYMBOL(atomic64_add_ret);
10947+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10948 EXPORT_SYMBOL(atomic64_sub);
10949+EXPORT_SYMBOL(atomic64_sub_unchecked);
10950 EXPORT_SYMBOL(atomic64_sub_ret);
10951 EXPORT_SYMBOL(atomic64_dec_if_positive);
10952
10953diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10954index 30c3ecc..736f015 100644
10955--- a/arch/sparc/mm/Makefile
10956+++ b/arch/sparc/mm/Makefile
10957@@ -2,7 +2,7 @@
10958 #
10959
10960 asflags-y := -ansi
10961-ccflags-y := -Werror
10962+#ccflags-y := -Werror
10963
10964 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10965 obj-y += fault_$(BITS).o
10966diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10967index 59dbd46..1dd7f5e 100644
10968--- a/arch/sparc/mm/fault_32.c
10969+++ b/arch/sparc/mm/fault_32.c
10970@@ -21,6 +21,9 @@
10971 #include <linux/perf_event.h>
10972 #include <linux/interrupt.h>
10973 #include <linux/kdebug.h>
10974+#include <linux/slab.h>
10975+#include <linux/pagemap.h>
10976+#include <linux/compiler.h>
10977
10978 #include <asm/page.h>
10979 #include <asm/pgtable.h>
10980@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10981 return safe_compute_effective_address(regs, insn);
10982 }
10983
10984+#ifdef CONFIG_PAX_PAGEEXEC
10985+#ifdef CONFIG_PAX_DLRESOLVE
10986+static void pax_emuplt_close(struct vm_area_struct *vma)
10987+{
10988+ vma->vm_mm->call_dl_resolve = 0UL;
10989+}
10990+
10991+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10992+{
10993+ unsigned int *kaddr;
10994+
10995+ vmf->page = alloc_page(GFP_HIGHUSER);
10996+ if (!vmf->page)
10997+ return VM_FAULT_OOM;
10998+
10999+ kaddr = kmap(vmf->page);
11000+ memset(kaddr, 0, PAGE_SIZE);
11001+ kaddr[0] = 0x9DE3BFA8U; /* save */
11002+ flush_dcache_page(vmf->page);
11003+ kunmap(vmf->page);
11004+ return VM_FAULT_MAJOR;
11005+}
11006+
11007+static const struct vm_operations_struct pax_vm_ops = {
11008+ .close = pax_emuplt_close,
11009+ .fault = pax_emuplt_fault
11010+};
11011+
11012+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11013+{
11014+ int ret;
11015+
11016+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11017+ vma->vm_mm = current->mm;
11018+ vma->vm_start = addr;
11019+ vma->vm_end = addr + PAGE_SIZE;
11020+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11021+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11022+ vma->vm_ops = &pax_vm_ops;
11023+
11024+ ret = insert_vm_struct(current->mm, vma);
11025+ if (ret)
11026+ return ret;
11027+
11028+ ++current->mm->total_vm;
11029+ return 0;
11030+}
11031+#endif
11032+
11033+/*
11034+ * PaX: decide what to do with offenders (regs->pc = fault address)
11035+ *
11036+ * returns 1 when task should be killed
11037+ * 2 when patched PLT trampoline was detected
11038+ * 3 when unpatched PLT trampoline was detected
11039+ */
11040+static int pax_handle_fetch_fault(struct pt_regs *regs)
11041+{
11042+
11043+#ifdef CONFIG_PAX_EMUPLT
11044+ int err;
11045+
11046+ do { /* PaX: patched PLT emulation #1 */
11047+ unsigned int sethi1, sethi2, jmpl;
11048+
11049+ err = get_user(sethi1, (unsigned int *)regs->pc);
11050+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11051+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11052+
11053+ if (err)
11054+ break;
11055+
11056+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11057+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11058+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11059+ {
11060+ unsigned int addr;
11061+
11062+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11063+ addr = regs->u_regs[UREG_G1];
11064+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11065+ regs->pc = addr;
11066+ regs->npc = addr+4;
11067+ return 2;
11068+ }
11069+ } while (0);
11070+
11071+ do { /* PaX: patched PLT emulation #2 */
11072+ unsigned int ba;
11073+
11074+ err = get_user(ba, (unsigned int *)regs->pc);
11075+
11076+ if (err)
11077+ break;
11078+
11079+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11080+ unsigned int addr;
11081+
11082+ if ((ba & 0xFFC00000U) == 0x30800000U)
11083+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11084+ else
11085+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11086+ regs->pc = addr;
11087+ regs->npc = addr+4;
11088+ return 2;
11089+ }
11090+ } while (0);
11091+
11092+ do { /* PaX: patched PLT emulation #3 */
11093+ unsigned int sethi, bajmpl, nop;
11094+
11095+ err = get_user(sethi, (unsigned int *)regs->pc);
11096+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11097+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11098+
11099+ if (err)
11100+ break;
11101+
11102+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11103+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11104+ nop == 0x01000000U)
11105+ {
11106+ unsigned int addr;
11107+
11108+ addr = (sethi & 0x003FFFFFU) << 10;
11109+ regs->u_regs[UREG_G1] = addr;
11110+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11111+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11112+ else
11113+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11114+ regs->pc = addr;
11115+ regs->npc = addr+4;
11116+ return 2;
11117+ }
11118+ } while (0);
11119+
11120+ do { /* PaX: unpatched PLT emulation step 1 */
11121+ unsigned int sethi, ba, nop;
11122+
11123+ err = get_user(sethi, (unsigned int *)regs->pc);
11124+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11125+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11126+
11127+ if (err)
11128+ break;
11129+
11130+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11131+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11132+ nop == 0x01000000U)
11133+ {
11134+ unsigned int addr, save, call;
11135+
11136+ if ((ba & 0xFFC00000U) == 0x30800000U)
11137+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11138+ else
11139+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11140+
11141+ err = get_user(save, (unsigned int *)addr);
11142+ err |= get_user(call, (unsigned int *)(addr+4));
11143+ err |= get_user(nop, (unsigned int *)(addr+8));
11144+ if (err)
11145+ break;
11146+
11147+#ifdef CONFIG_PAX_DLRESOLVE
11148+ if (save == 0x9DE3BFA8U &&
11149+ (call & 0xC0000000U) == 0x40000000U &&
11150+ nop == 0x01000000U)
11151+ {
11152+ struct vm_area_struct *vma;
11153+ unsigned long call_dl_resolve;
11154+
11155+ down_read(&current->mm->mmap_sem);
11156+ call_dl_resolve = current->mm->call_dl_resolve;
11157+ up_read(&current->mm->mmap_sem);
11158+ if (likely(call_dl_resolve))
11159+ goto emulate;
11160+
11161+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11162+
11163+ down_write(&current->mm->mmap_sem);
11164+ if (current->mm->call_dl_resolve) {
11165+ call_dl_resolve = current->mm->call_dl_resolve;
11166+ up_write(&current->mm->mmap_sem);
11167+ if (vma)
11168+ kmem_cache_free(vm_area_cachep, vma);
11169+ goto emulate;
11170+ }
11171+
11172+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11173+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11174+ up_write(&current->mm->mmap_sem);
11175+ if (vma)
11176+ kmem_cache_free(vm_area_cachep, vma);
11177+ return 1;
11178+ }
11179+
11180+ if (pax_insert_vma(vma, call_dl_resolve)) {
11181+ up_write(&current->mm->mmap_sem);
11182+ kmem_cache_free(vm_area_cachep, vma);
11183+ return 1;
11184+ }
11185+
11186+ current->mm->call_dl_resolve = call_dl_resolve;
11187+ up_write(&current->mm->mmap_sem);
11188+
11189+emulate:
11190+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11191+ regs->pc = call_dl_resolve;
11192+ regs->npc = addr+4;
11193+ return 3;
11194+ }
11195+#endif
11196+
11197+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11198+ if ((save & 0xFFC00000U) == 0x05000000U &&
11199+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11200+ nop == 0x01000000U)
11201+ {
11202+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11203+ regs->u_regs[UREG_G2] = addr + 4;
11204+ addr = (save & 0x003FFFFFU) << 10;
11205+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11206+ regs->pc = addr;
11207+ regs->npc = addr+4;
11208+ return 3;
11209+ }
11210+ }
11211+ } while (0);
11212+
11213+ do { /* PaX: unpatched PLT emulation step 2 */
11214+ unsigned int save, call, nop;
11215+
11216+ err = get_user(save, (unsigned int *)(regs->pc-4));
11217+ err |= get_user(call, (unsigned int *)regs->pc);
11218+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11219+ if (err)
11220+ break;
11221+
11222+ if (save == 0x9DE3BFA8U &&
11223+ (call & 0xC0000000U) == 0x40000000U &&
11224+ nop == 0x01000000U)
11225+ {
11226+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11227+
11228+ regs->u_regs[UREG_RETPC] = regs->pc;
11229+ regs->pc = dl_resolve;
11230+ regs->npc = dl_resolve+4;
11231+ return 3;
11232+ }
11233+ } while (0);
11234+#endif
11235+
11236+ return 1;
11237+}
11238+
11239+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11240+{
11241+ unsigned long i;
11242+
11243+ printk(KERN_ERR "PAX: bytes at PC: ");
11244+ for (i = 0; i < 8; i++) {
11245+ unsigned int c;
11246+ if (get_user(c, (unsigned int *)pc+i))
11247+ printk(KERN_CONT "???????? ");
11248+ else
11249+ printk(KERN_CONT "%08x ", c);
11250+ }
11251+ printk("\n");
11252+}
11253+#endif
11254+
11255 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11256 int text_fault)
11257 {
11258@@ -229,6 +503,24 @@ good_area:
11259 if (!(vma->vm_flags & VM_WRITE))
11260 goto bad_area;
11261 } else {
11262+
11263+#ifdef CONFIG_PAX_PAGEEXEC
11264+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11265+ up_read(&mm->mmap_sem);
11266+ switch (pax_handle_fetch_fault(regs)) {
11267+
11268+#ifdef CONFIG_PAX_EMUPLT
11269+ case 2:
11270+ case 3:
11271+ return;
11272+#endif
11273+
11274+ }
11275+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11276+ do_group_exit(SIGKILL);
11277+ }
11278+#endif
11279+
11280 /* Allow reads even for write-only mappings */
11281 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11282 goto bad_area;
11283diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11284index 69bb818..6ca35c8 100644
11285--- a/arch/sparc/mm/fault_64.c
11286+++ b/arch/sparc/mm/fault_64.c
11287@@ -22,6 +22,9 @@
11288 #include <linux/kdebug.h>
11289 #include <linux/percpu.h>
11290 #include <linux/context_tracking.h>
11291+#include <linux/slab.h>
11292+#include <linux/pagemap.h>
11293+#include <linux/compiler.h>
11294
11295 #include <asm/page.h>
11296 #include <asm/pgtable.h>
11297@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11298 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11299 regs->tpc);
11300 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11301- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11302+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11303 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11304 dump_stack();
11305 unhandled_fault(regs->tpc, current, regs);
11306@@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11307 show_regs(regs);
11308 }
11309
11310+#ifdef CONFIG_PAX_PAGEEXEC
11311+#ifdef CONFIG_PAX_DLRESOLVE
11312+static void pax_emuplt_close(struct vm_area_struct *vma)
11313+{
11314+ vma->vm_mm->call_dl_resolve = 0UL;
11315+}
11316+
11317+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11318+{
11319+ unsigned int *kaddr;
11320+
11321+ vmf->page = alloc_page(GFP_HIGHUSER);
11322+ if (!vmf->page)
11323+ return VM_FAULT_OOM;
11324+
11325+ kaddr = kmap(vmf->page);
11326+ memset(kaddr, 0, PAGE_SIZE);
11327+ kaddr[0] = 0x9DE3BFA8U; /* save */
11328+ flush_dcache_page(vmf->page);
11329+ kunmap(vmf->page);
11330+ return VM_FAULT_MAJOR;
11331+}
11332+
11333+static const struct vm_operations_struct pax_vm_ops = {
11334+ .close = pax_emuplt_close,
11335+ .fault = pax_emuplt_fault
11336+};
11337+
11338+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11339+{
11340+ int ret;
11341+
11342+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11343+ vma->vm_mm = current->mm;
11344+ vma->vm_start = addr;
11345+ vma->vm_end = addr + PAGE_SIZE;
11346+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11347+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11348+ vma->vm_ops = &pax_vm_ops;
11349+
11350+ ret = insert_vm_struct(current->mm, vma);
11351+ if (ret)
11352+ return ret;
11353+
11354+ ++current->mm->total_vm;
11355+ return 0;
11356+}
11357+#endif
11358+
11359+/*
11360+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11361+ *
11362+ * returns 1 when task should be killed
11363+ * 2 when patched PLT trampoline was detected
11364+ * 3 when unpatched PLT trampoline was detected
11365+ */
11366+static int pax_handle_fetch_fault(struct pt_regs *regs)
11367+{
11368+
11369+#ifdef CONFIG_PAX_EMUPLT
11370+ int err;
11371+
11372+ do { /* PaX: patched PLT emulation #1 */
11373+ unsigned int sethi1, sethi2, jmpl;
11374+
11375+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11376+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11377+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11378+
11379+ if (err)
11380+ break;
11381+
11382+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11383+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11384+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11385+ {
11386+ unsigned long addr;
11387+
11388+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11389+ addr = regs->u_regs[UREG_G1];
11390+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11391+
11392+ if (test_thread_flag(TIF_32BIT))
11393+ addr &= 0xFFFFFFFFUL;
11394+
11395+ regs->tpc = addr;
11396+ regs->tnpc = addr+4;
11397+ return 2;
11398+ }
11399+ } while (0);
11400+
11401+ do { /* PaX: patched PLT emulation #2 */
11402+ unsigned int ba;
11403+
11404+ err = get_user(ba, (unsigned int *)regs->tpc);
11405+
11406+ if (err)
11407+ break;
11408+
11409+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11410+ unsigned long addr;
11411+
11412+ if ((ba & 0xFFC00000U) == 0x30800000U)
11413+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11414+ else
11415+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11416+
11417+ if (test_thread_flag(TIF_32BIT))
11418+ addr &= 0xFFFFFFFFUL;
11419+
11420+ regs->tpc = addr;
11421+ regs->tnpc = addr+4;
11422+ return 2;
11423+ }
11424+ } while (0);
11425+
11426+ do { /* PaX: patched PLT emulation #3 */
11427+ unsigned int sethi, bajmpl, nop;
11428+
11429+ err = get_user(sethi, (unsigned int *)regs->tpc);
11430+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11431+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11432+
11433+ if (err)
11434+ break;
11435+
11436+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11437+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11438+ nop == 0x01000000U)
11439+ {
11440+ unsigned long addr;
11441+
11442+ addr = (sethi & 0x003FFFFFU) << 10;
11443+ regs->u_regs[UREG_G1] = addr;
11444+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11445+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11446+ else
11447+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11448+
11449+ if (test_thread_flag(TIF_32BIT))
11450+ addr &= 0xFFFFFFFFUL;
11451+
11452+ regs->tpc = addr;
11453+ regs->tnpc = addr+4;
11454+ return 2;
11455+ }
11456+ } while (0);
11457+
11458+ do { /* PaX: patched PLT emulation #4 */
11459+ unsigned int sethi, mov1, call, mov2;
11460+
11461+ err = get_user(sethi, (unsigned int *)regs->tpc);
11462+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11463+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11464+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11465+
11466+ if (err)
11467+ break;
11468+
11469+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11470+ mov1 == 0x8210000FU &&
11471+ (call & 0xC0000000U) == 0x40000000U &&
11472+ mov2 == 0x9E100001U)
11473+ {
11474+ unsigned long addr;
11475+
11476+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11477+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11478+
11479+ if (test_thread_flag(TIF_32BIT))
11480+ addr &= 0xFFFFFFFFUL;
11481+
11482+ regs->tpc = addr;
11483+ regs->tnpc = addr+4;
11484+ return 2;
11485+ }
11486+ } while (0);
11487+
11488+ do { /* PaX: patched PLT emulation #5 */
11489+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11490+
11491+ err = get_user(sethi, (unsigned int *)regs->tpc);
11492+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11493+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11494+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11495+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11496+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11497+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11498+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11499+
11500+ if (err)
11501+ break;
11502+
11503+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11504+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11505+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11506+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11507+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11508+ sllx == 0x83287020U &&
11509+ jmpl == 0x81C04005U &&
11510+ nop == 0x01000000U)
11511+ {
11512+ unsigned long addr;
11513+
11514+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11515+ regs->u_regs[UREG_G1] <<= 32;
11516+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11517+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11518+ regs->tpc = addr;
11519+ regs->tnpc = addr+4;
11520+ return 2;
11521+ }
11522+ } while (0);
11523+
11524+ do { /* PaX: patched PLT emulation #6 */
11525+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11526+
11527+ err = get_user(sethi, (unsigned int *)regs->tpc);
11528+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11529+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11530+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11531+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11532+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11533+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11534+
11535+ if (err)
11536+ break;
11537+
11538+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11539+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11540+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11541+ sllx == 0x83287020U &&
11542+ (or & 0xFFFFE000U) == 0x8A116000U &&
11543+ jmpl == 0x81C04005U &&
11544+ nop == 0x01000000U)
11545+ {
11546+ unsigned long addr;
11547+
11548+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11549+ regs->u_regs[UREG_G1] <<= 32;
11550+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11551+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11552+ regs->tpc = addr;
11553+ regs->tnpc = addr+4;
11554+ return 2;
11555+ }
11556+ } while (0);
11557+
11558+ do { /* PaX: unpatched PLT emulation step 1 */
11559+ unsigned int sethi, ba, nop;
11560+
11561+ err = get_user(sethi, (unsigned int *)regs->tpc);
11562+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11563+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11564+
11565+ if (err)
11566+ break;
11567+
11568+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11569+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11570+ nop == 0x01000000U)
11571+ {
11572+ unsigned long addr;
11573+ unsigned int save, call;
11574+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11575+
11576+ if ((ba & 0xFFC00000U) == 0x30800000U)
11577+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11578+ else
11579+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11580+
11581+ if (test_thread_flag(TIF_32BIT))
11582+ addr &= 0xFFFFFFFFUL;
11583+
11584+ err = get_user(save, (unsigned int *)addr);
11585+ err |= get_user(call, (unsigned int *)(addr+4));
11586+ err |= get_user(nop, (unsigned int *)(addr+8));
11587+ if (err)
11588+ break;
11589+
11590+#ifdef CONFIG_PAX_DLRESOLVE
11591+ if (save == 0x9DE3BFA8U &&
11592+ (call & 0xC0000000U) == 0x40000000U &&
11593+ nop == 0x01000000U)
11594+ {
11595+ struct vm_area_struct *vma;
11596+ unsigned long call_dl_resolve;
11597+
11598+ down_read(&current->mm->mmap_sem);
11599+ call_dl_resolve = current->mm->call_dl_resolve;
11600+ up_read(&current->mm->mmap_sem);
11601+ if (likely(call_dl_resolve))
11602+ goto emulate;
11603+
11604+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11605+
11606+ down_write(&current->mm->mmap_sem);
11607+ if (current->mm->call_dl_resolve) {
11608+ call_dl_resolve = current->mm->call_dl_resolve;
11609+ up_write(&current->mm->mmap_sem);
11610+ if (vma)
11611+ kmem_cache_free(vm_area_cachep, vma);
11612+ goto emulate;
11613+ }
11614+
11615+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11616+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11617+ up_write(&current->mm->mmap_sem);
11618+ if (vma)
11619+ kmem_cache_free(vm_area_cachep, vma);
11620+ return 1;
11621+ }
11622+
11623+ if (pax_insert_vma(vma, call_dl_resolve)) {
11624+ up_write(&current->mm->mmap_sem);
11625+ kmem_cache_free(vm_area_cachep, vma);
11626+ return 1;
11627+ }
11628+
11629+ current->mm->call_dl_resolve = call_dl_resolve;
11630+ up_write(&current->mm->mmap_sem);
11631+
11632+emulate:
11633+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11634+ regs->tpc = call_dl_resolve;
11635+ regs->tnpc = addr+4;
11636+ return 3;
11637+ }
11638+#endif
11639+
11640+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11641+ if ((save & 0xFFC00000U) == 0x05000000U &&
11642+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11643+ nop == 0x01000000U)
11644+ {
11645+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11646+ regs->u_regs[UREG_G2] = addr + 4;
11647+ addr = (save & 0x003FFFFFU) << 10;
11648+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11649+
11650+ if (test_thread_flag(TIF_32BIT))
11651+ addr &= 0xFFFFFFFFUL;
11652+
11653+ regs->tpc = addr;
11654+ regs->tnpc = addr+4;
11655+ return 3;
11656+ }
11657+
11658+ /* PaX: 64-bit PLT stub */
11659+ err = get_user(sethi1, (unsigned int *)addr);
11660+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11661+ err |= get_user(or1, (unsigned int *)(addr+8));
11662+ err |= get_user(or2, (unsigned int *)(addr+12));
11663+ err |= get_user(sllx, (unsigned int *)(addr+16));
11664+ err |= get_user(add, (unsigned int *)(addr+20));
11665+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11666+ err |= get_user(nop, (unsigned int *)(addr+28));
11667+ if (err)
11668+ break;
11669+
11670+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11671+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11672+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11673+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11674+ sllx == 0x89293020U &&
11675+ add == 0x8A010005U &&
11676+ jmpl == 0x89C14000U &&
11677+ nop == 0x01000000U)
11678+ {
11679+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11680+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11681+ regs->u_regs[UREG_G4] <<= 32;
11682+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11683+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11684+ regs->u_regs[UREG_G4] = addr + 24;
11685+ addr = regs->u_regs[UREG_G5];
11686+ regs->tpc = addr;
11687+ regs->tnpc = addr+4;
11688+ return 3;
11689+ }
11690+ }
11691+ } while (0);
11692+
11693+#ifdef CONFIG_PAX_DLRESOLVE
11694+ do { /* PaX: unpatched PLT emulation step 2 */
11695+ unsigned int save, call, nop;
11696+
11697+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11698+ err |= get_user(call, (unsigned int *)regs->tpc);
11699+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11700+ if (err)
11701+ break;
11702+
11703+ if (save == 0x9DE3BFA8U &&
11704+ (call & 0xC0000000U) == 0x40000000U &&
11705+ nop == 0x01000000U)
11706+ {
11707+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11708+
11709+ if (test_thread_flag(TIF_32BIT))
11710+ dl_resolve &= 0xFFFFFFFFUL;
11711+
11712+ regs->u_regs[UREG_RETPC] = regs->tpc;
11713+ regs->tpc = dl_resolve;
11714+ regs->tnpc = dl_resolve+4;
11715+ return 3;
11716+ }
11717+ } while (0);
11718+#endif
11719+
11720+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11721+ unsigned int sethi, ba, nop;
11722+
11723+ err = get_user(sethi, (unsigned int *)regs->tpc);
11724+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11725+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11726+
11727+ if (err)
11728+ break;
11729+
11730+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11731+ (ba & 0xFFF00000U) == 0x30600000U &&
11732+ nop == 0x01000000U)
11733+ {
11734+ unsigned long addr;
11735+
11736+ addr = (sethi & 0x003FFFFFU) << 10;
11737+ regs->u_regs[UREG_G1] = addr;
11738+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11739+
11740+ if (test_thread_flag(TIF_32BIT))
11741+ addr &= 0xFFFFFFFFUL;
11742+
11743+ regs->tpc = addr;
11744+ regs->tnpc = addr+4;
11745+ return 2;
11746+ }
11747+ } while (0);
11748+
11749+#endif
11750+
11751+ return 1;
11752+}
11753+
11754+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11755+{
11756+ unsigned long i;
11757+
11758+ printk(KERN_ERR "PAX: bytes at PC: ");
11759+ for (i = 0; i < 8; i++) {
11760+ unsigned int c;
11761+ if (get_user(c, (unsigned int *)pc+i))
11762+ printk(KERN_CONT "???????? ");
11763+ else
11764+ printk(KERN_CONT "%08x ", c);
11765+ }
11766+ printk("\n");
11767+}
11768+#endif
11769+
11770 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11771 {
11772 enum ctx_state prev_state = exception_enter();
11773@@ -344,6 +807,29 @@ retry:
11774 if (!vma)
11775 goto bad_area;
11776
11777+#ifdef CONFIG_PAX_PAGEEXEC
11778+ /* PaX: detect ITLB misses on non-exec pages */
11779+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11780+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11781+ {
11782+ if (address != regs->tpc)
11783+ goto good_area;
11784+
11785+ up_read(&mm->mmap_sem);
11786+ switch (pax_handle_fetch_fault(regs)) {
11787+
11788+#ifdef CONFIG_PAX_EMUPLT
11789+ case 2:
11790+ case 3:
11791+ return;
11792+#endif
11793+
11794+ }
11795+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11796+ do_group_exit(SIGKILL);
11797+ }
11798+#endif
11799+
11800 /* Pure DTLB misses do not tell us whether the fault causing
11801 * load/store/atomic was a write or not, it only says that there
11802 * was no match. So in such a case we (carefully) read the
11803diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11804index 9bd9ce8..dc84852 100644
11805--- a/arch/sparc/mm/hugetlbpage.c
11806+++ b/arch/sparc/mm/hugetlbpage.c
11807@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11808 unsigned long addr,
11809 unsigned long len,
11810 unsigned long pgoff,
11811- unsigned long flags)
11812+ unsigned long flags,
11813+ unsigned long offset)
11814 {
11815+ struct mm_struct *mm = current->mm;
11816 unsigned long task_size = TASK_SIZE;
11817 struct vm_unmapped_area_info info;
11818
11819@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11820
11821 info.flags = 0;
11822 info.length = len;
11823- info.low_limit = TASK_UNMAPPED_BASE;
11824+ info.low_limit = mm->mmap_base;
11825 info.high_limit = min(task_size, VA_EXCLUDE_START);
11826 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11827 info.align_offset = 0;
11828+ info.threadstack_offset = offset;
11829 addr = vm_unmapped_area(&info);
11830
11831 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11832 VM_BUG_ON(addr != -ENOMEM);
11833 info.low_limit = VA_EXCLUDE_END;
11834+
11835+#ifdef CONFIG_PAX_RANDMMAP
11836+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11837+ info.low_limit += mm->delta_mmap;
11838+#endif
11839+
11840 info.high_limit = task_size;
11841 addr = vm_unmapped_area(&info);
11842 }
11843@@ -55,7 +64,8 @@ static unsigned long
11844 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11845 const unsigned long len,
11846 const unsigned long pgoff,
11847- const unsigned long flags)
11848+ const unsigned long flags,
11849+ const unsigned long offset)
11850 {
11851 struct mm_struct *mm = current->mm;
11852 unsigned long addr = addr0;
11853@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11854 info.high_limit = mm->mmap_base;
11855 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11856 info.align_offset = 0;
11857+ info.threadstack_offset = offset;
11858 addr = vm_unmapped_area(&info);
11859
11860 /*
11861@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11862 VM_BUG_ON(addr != -ENOMEM);
11863 info.flags = 0;
11864 info.low_limit = TASK_UNMAPPED_BASE;
11865+
11866+#ifdef CONFIG_PAX_RANDMMAP
11867+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11868+ info.low_limit += mm->delta_mmap;
11869+#endif
11870+
11871 info.high_limit = STACK_TOP32;
11872 addr = vm_unmapped_area(&info);
11873 }
11874@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11875 struct mm_struct *mm = current->mm;
11876 struct vm_area_struct *vma;
11877 unsigned long task_size = TASK_SIZE;
11878+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11879
11880 if (test_thread_flag(TIF_32BIT))
11881 task_size = STACK_TOP32;
11882@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11883 return addr;
11884 }
11885
11886+#ifdef CONFIG_PAX_RANDMMAP
11887+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11888+#endif
11889+
11890 if (addr) {
11891 addr = ALIGN(addr, HPAGE_SIZE);
11892 vma = find_vma(mm, addr);
11893- if (task_size - len >= addr &&
11894- (!vma || addr + len <= vma->vm_start))
11895+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11896 return addr;
11897 }
11898 if (mm->get_unmapped_area == arch_get_unmapped_area)
11899 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11900- pgoff, flags);
11901+ pgoff, flags, offset);
11902 else
11903 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11904- pgoff, flags);
11905+ pgoff, flags, offset);
11906 }
11907
11908 pte_t *huge_pte_alloc(struct mm_struct *mm,
11909diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11910index eafbc65..5a8070d 100644
11911--- a/arch/sparc/mm/init_64.c
11912+++ b/arch/sparc/mm/init_64.c
11913@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11914 int num_kernel_image_mappings;
11915
11916 #ifdef CONFIG_DEBUG_DCFLUSH
11917-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11918+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11919 #ifdef CONFIG_SMP
11920-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11921+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11922 #endif
11923 #endif
11924
11925@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11926 {
11927 BUG_ON(tlb_type == hypervisor);
11928 #ifdef CONFIG_DEBUG_DCFLUSH
11929- atomic_inc(&dcpage_flushes);
11930+ atomic_inc_unchecked(&dcpage_flushes);
11931 #endif
11932
11933 #ifdef DCACHE_ALIASING_POSSIBLE
11934@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11935
11936 #ifdef CONFIG_DEBUG_DCFLUSH
11937 seq_printf(m, "DCPageFlushes\t: %d\n",
11938- atomic_read(&dcpage_flushes));
11939+ atomic_read_unchecked(&dcpage_flushes));
11940 #ifdef CONFIG_SMP
11941 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11942- atomic_read(&dcpage_flushes_xcall));
11943+ atomic_read_unchecked(&dcpage_flushes_xcall));
11944 #endif /* CONFIG_SMP */
11945 #endif /* CONFIG_DEBUG_DCFLUSH */
11946 }
11947diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11948index b3692ce..e4517c9 100644
11949--- a/arch/tile/Kconfig
11950+++ b/arch/tile/Kconfig
11951@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11952
11953 config KEXEC
11954 bool "kexec system call"
11955+ depends on !GRKERNSEC_KMEM
11956 ---help---
11957 kexec is a system call that implements the ability to shutdown your
11958 current kernel, and to start another kernel. It is like a reboot
11959diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11960index ad220ee..2f537b3 100644
11961--- a/arch/tile/include/asm/atomic_64.h
11962+++ b/arch/tile/include/asm/atomic_64.h
11963@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11964
11965 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11966
11967+#define atomic64_read_unchecked(v) atomic64_read(v)
11968+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11969+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11970+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11971+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11972+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11973+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11974+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11975+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11976+
11977 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11978 #define smp_mb__before_atomic_dec() smp_mb()
11979 #define smp_mb__after_atomic_dec() smp_mb()
11980diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11981index 6160761..00cac88 100644
11982--- a/arch/tile/include/asm/cache.h
11983+++ b/arch/tile/include/asm/cache.h
11984@@ -15,11 +15,12 @@
11985 #ifndef _ASM_TILE_CACHE_H
11986 #define _ASM_TILE_CACHE_H
11987
11988+#include <linux/const.h>
11989 #include <arch/chip.h>
11990
11991 /* bytes per L1 data cache line */
11992 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11993-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11994+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11995
11996 /* bytes per L2 cache line */
11997 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11998diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11999index b6cde32..c0cb736 100644
12000--- a/arch/tile/include/asm/uaccess.h
12001+++ b/arch/tile/include/asm/uaccess.h
12002@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12003 const void __user *from,
12004 unsigned long n)
12005 {
12006- int sz = __compiletime_object_size(to);
12007+ size_t sz = __compiletime_object_size(to);
12008
12009- if (likely(sz == -1 || sz >= n))
12010+ if (likely(sz == (size_t)-1 || sz >= n))
12011 n = _copy_from_user(to, from, n);
12012 else
12013 copy_from_user_overflow();
12014diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12015index 0cb3bba..7338b2d 100644
12016--- a/arch/tile/mm/hugetlbpage.c
12017+++ b/arch/tile/mm/hugetlbpage.c
12018@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12019 info.high_limit = TASK_SIZE;
12020 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12021 info.align_offset = 0;
12022+ info.threadstack_offset = 0;
12023 return vm_unmapped_area(&info);
12024 }
12025
12026@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12027 info.high_limit = current->mm->mmap_base;
12028 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12029 info.align_offset = 0;
12030+ info.threadstack_offset = 0;
12031 addr = vm_unmapped_area(&info);
12032
12033 /*
12034diff --git a/arch/um/Makefile b/arch/um/Makefile
12035index 36e658a..71a5c5a 100644
12036--- a/arch/um/Makefile
12037+++ b/arch/um/Makefile
12038@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12039 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12040 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12041
12042+ifdef CONSTIFY_PLUGIN
12043+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12044+endif
12045+
12046 #This will adjust *FLAGS accordingly to the platform.
12047 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12048
12049diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12050index 19e1bdd..3665b77 100644
12051--- a/arch/um/include/asm/cache.h
12052+++ b/arch/um/include/asm/cache.h
12053@@ -1,6 +1,7 @@
12054 #ifndef __UM_CACHE_H
12055 #define __UM_CACHE_H
12056
12057+#include <linux/const.h>
12058
12059 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12060 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12061@@ -12,6 +13,6 @@
12062 # define L1_CACHE_SHIFT 5
12063 #endif
12064
12065-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12066+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12067
12068 #endif
12069diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12070index 2e0a6b1..a64d0f5 100644
12071--- a/arch/um/include/asm/kmap_types.h
12072+++ b/arch/um/include/asm/kmap_types.h
12073@@ -8,6 +8,6 @@
12074
12075 /* No more #include "asm/arch/kmap_types.h" ! */
12076
12077-#define KM_TYPE_NR 14
12078+#define KM_TYPE_NR 15
12079
12080 #endif
12081diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12082index 5ff53d9..5850cdf 100644
12083--- a/arch/um/include/asm/page.h
12084+++ b/arch/um/include/asm/page.h
12085@@ -14,6 +14,9 @@
12086 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12087 #define PAGE_MASK (~(PAGE_SIZE-1))
12088
12089+#define ktla_ktva(addr) (addr)
12090+#define ktva_ktla(addr) (addr)
12091+
12092 #ifndef __ASSEMBLY__
12093
12094 struct page;
12095diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12096index 0032f92..cd151e0 100644
12097--- a/arch/um/include/asm/pgtable-3level.h
12098+++ b/arch/um/include/asm/pgtable-3level.h
12099@@ -58,6 +58,7 @@
12100 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12101 #define pud_populate(mm, pud, pmd) \
12102 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12103+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12104
12105 #ifdef CONFIG_64BIT
12106 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12107diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12108index eecc414..48adb87 100644
12109--- a/arch/um/kernel/process.c
12110+++ b/arch/um/kernel/process.c
12111@@ -356,22 +356,6 @@ int singlestepping(void * t)
12112 return 2;
12113 }
12114
12115-/*
12116- * Only x86 and x86_64 have an arch_align_stack().
12117- * All other arches have "#define arch_align_stack(x) (x)"
12118- * in their asm/system.h
12119- * As this is included in UML from asm-um/system-generic.h,
12120- * we can use it to behave as the subarch does.
12121- */
12122-#ifndef arch_align_stack
12123-unsigned long arch_align_stack(unsigned long sp)
12124-{
12125- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12126- sp -= get_random_int() % 8192;
12127- return sp & ~0xf;
12128-}
12129-#endif
12130-
12131 unsigned long get_wchan(struct task_struct *p)
12132 {
12133 unsigned long stack_page, sp, ip;
12134diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12135index ad8f795..2c7eec6 100644
12136--- a/arch/unicore32/include/asm/cache.h
12137+++ b/arch/unicore32/include/asm/cache.h
12138@@ -12,8 +12,10 @@
12139 #ifndef __UNICORE_CACHE_H__
12140 #define __UNICORE_CACHE_H__
12141
12142-#define L1_CACHE_SHIFT (5)
12143-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12144+#include <linux/const.h>
12145+
12146+#define L1_CACHE_SHIFT 5
12147+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12148
12149 /*
12150 * Memory returned by kmalloc() may be used for DMA, so we must make
12151diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12152index 0af5250..59f9597 100644
12153--- a/arch/x86/Kconfig
12154+++ b/arch/x86/Kconfig
12155@@ -126,7 +126,7 @@ config X86
12156 select RTC_LIB
12157 select HAVE_DEBUG_STACKOVERFLOW
12158 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12159- select HAVE_CC_STACKPROTECTOR
12160+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12161
12162 config INSTRUCTION_DECODER
12163 def_bool y
12164@@ -251,7 +251,7 @@ config X86_HT
12165
12166 config X86_32_LAZY_GS
12167 def_bool y
12168- depends on X86_32 && !CC_STACKPROTECTOR
12169+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12170
12171 config ARCH_HWEIGHT_CFLAGS
12172 string
12173@@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12174
12175 menuconfig HYPERVISOR_GUEST
12176 bool "Linux guest support"
12177+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12178 ---help---
12179 Say Y here to enable options for running Linux under various hyper-
12180 visors. This option enables basic hypervisor detection and platform
12181@@ -1111,7 +1112,7 @@ choice
12182
12183 config NOHIGHMEM
12184 bool "off"
12185- depends on !X86_NUMAQ
12186+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12187 ---help---
12188 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12189 However, the address space of 32-bit x86 processors is only 4
12190@@ -1148,7 +1149,7 @@ config NOHIGHMEM
12191
12192 config HIGHMEM4G
12193 bool "4GB"
12194- depends on !X86_NUMAQ
12195+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12196 ---help---
12197 Select this if you have a 32-bit processor and between 1 and 4
12198 gigabytes of physical RAM.
12199@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12200 hex
12201 default 0xB0000000 if VMSPLIT_3G_OPT
12202 default 0x80000000 if VMSPLIT_2G
12203- default 0x78000000 if VMSPLIT_2G_OPT
12204+ default 0x70000000 if VMSPLIT_2G_OPT
12205 default 0x40000000 if VMSPLIT_1G
12206 default 0xC0000000
12207 depends on X86_32
12208@@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12209
12210 config KEXEC
12211 bool "kexec system call"
12212+ depends on !GRKERNSEC_KMEM
12213 ---help---
12214 kexec is a system call that implements the ability to shutdown your
12215 current kernel, and to start another kernel. It is like a reboot
12216@@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12217
12218 config PHYSICAL_ALIGN
12219 hex "Alignment value to which kernel should be aligned"
12220- default "0x200000"
12221+ default "0x1000000"
12222+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12223+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12224 range 0x2000 0x1000000 if X86_32
12225 range 0x200000 0x1000000 if X86_64
12226 ---help---
12227@@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12228 If unsure, say N.
12229
12230 config COMPAT_VDSO
12231- def_bool y
12232+ def_bool n
12233 prompt "Compat VDSO support"
12234 depends on X86_32 || IA32_EMULATION
12235+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12236 ---help---
12237 Map the 32-bit VDSO to the predictable old-style address too.
12238
12239diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12240index f3aaf23..a1d3c49 100644
12241--- a/arch/x86/Kconfig.cpu
12242+++ b/arch/x86/Kconfig.cpu
12243@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12244
12245 config X86_F00F_BUG
12246 def_bool y
12247- depends on M586MMX || M586TSC || M586 || M486
12248+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12249
12250 config X86_INVD_BUG
12251 def_bool y
12252@@ -327,7 +327,7 @@ config X86_INVD_BUG
12253
12254 config X86_ALIGNMENT_16
12255 def_bool y
12256- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12257+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12258
12259 config X86_INTEL_USERCOPY
12260 def_bool y
12261@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12262 # generates cmov.
12263 config X86_CMOV
12264 def_bool y
12265- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12266+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12267
12268 config X86_MINIMUM_CPU_FAMILY
12269 int
12270diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12271index 321a52c..3d51a5e 100644
12272--- a/arch/x86/Kconfig.debug
12273+++ b/arch/x86/Kconfig.debug
12274@@ -84,7 +84,7 @@ config X86_PTDUMP
12275 config DEBUG_RODATA
12276 bool "Write protect kernel read-only data structures"
12277 default y
12278- depends on DEBUG_KERNEL
12279+ depends on DEBUG_KERNEL && BROKEN
12280 ---help---
12281 Mark the kernel read-only data as write-protected in the pagetables,
12282 in order to catch accidental (and incorrect) writes to such const
12283@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12284
12285 config DEBUG_SET_MODULE_RONX
12286 bool "Set loadable kernel module data as NX and text as RO"
12287- depends on MODULES
12288+ depends on MODULES && BROKEN
12289 ---help---
12290 This option helps catch unintended modifications to loadable
12291 kernel module's text and read-only data. It also prevents execution
12292diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12293index f8842c4..e893775 100644
12294--- a/arch/x86/Makefile
12295+++ b/arch/x86/Makefile
12296@@ -71,14 +71,12 @@ ifeq ($(CONFIG_X86_32),y)
12297 # CPU-specific tuning. Anything which can be shared with UML should go here.
12298 include $(srctree)/arch/x86/Makefile_32.cpu
12299 KBUILD_CFLAGS += $(cflags-y)
12300-
12301- # temporary until string.h is fixed
12302- KBUILD_CFLAGS += -ffreestanding
12303 else
12304 BITS := 64
12305 UTS_MACHINE := x86_64
12306 CHECKFLAGS += -D__x86_64__ -m64
12307
12308+ biarch := $(call cc-option,-m64)
12309 KBUILD_AFLAGS += -m64
12310 KBUILD_CFLAGS += -m64
12311
12312@@ -111,6 +109,9 @@ else
12313 KBUILD_CFLAGS += -maccumulate-outgoing-args
12314 endif
12315
12316+# temporary until string.h is fixed
12317+KBUILD_CFLAGS += -ffreestanding
12318+
12319 # Make sure compiler does not have buggy stack-protector support.
12320 ifdef CONFIG_CC_STACKPROTECTOR
12321 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12322@@ -268,3 +269,12 @@ define archhelp
12323 echo ' FDINITRD=file initrd for the booted kernel'
12324 echo ' kvmconfig - Enable additional options for guest kernel support'
12325 endef
12326+
12327+define OLD_LD
12328+
12329+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12330+*** Please upgrade your binutils to 2.18 or newer
12331+endef
12332+
12333+archprepare:
12334+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12335diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12336index 878df7e..a803913 100644
12337--- a/arch/x86/boot/Makefile
12338+++ b/arch/x86/boot/Makefile
12339@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12340 # ---------------------------------------------------------------------------
12341
12342 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12343+ifdef CONSTIFY_PLUGIN
12344+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12345+endif
12346 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12347 GCOV_PROFILE := n
12348
12349diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12350index 878e4b9..20537ab 100644
12351--- a/arch/x86/boot/bitops.h
12352+++ b/arch/x86/boot/bitops.h
12353@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12354 u8 v;
12355 const u32 *p = (const u32 *)addr;
12356
12357- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12358+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12359 return v;
12360 }
12361
12362@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12363
12364 static inline void set_bit(int nr, void *addr)
12365 {
12366- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12367+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12368 }
12369
12370 #endif /* BOOT_BITOPS_H */
12371diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12372index 50f8c5e..4f84fff 100644
12373--- a/arch/x86/boot/boot.h
12374+++ b/arch/x86/boot/boot.h
12375@@ -84,7 +84,7 @@ static inline void io_delay(void)
12376 static inline u16 ds(void)
12377 {
12378 u16 seg;
12379- asm("movw %%ds,%0" : "=rm" (seg));
12380+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12381 return seg;
12382 }
12383
12384@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12385 static inline int memcmp(const void *s1, const void *s2, size_t len)
12386 {
12387 u8 diff;
12388- asm("repe; cmpsb; setnz %0"
12389+ asm volatile("repe; cmpsb; setnz %0"
12390 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12391 return diff;
12392 }
12393diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12394index 0fcd913..3bb5c42 100644
12395--- a/arch/x86/boot/compressed/Makefile
12396+++ b/arch/x86/boot/compressed/Makefile
12397@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12398 KBUILD_CFLAGS += -mno-mmx -mno-sse
12399 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12400 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12401+ifdef CONSTIFY_PLUGIN
12402+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12403+endif
12404
12405 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12406 GCOV_PROFILE := n
12407diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12408index a53440e..c3dbf1e 100644
12409--- a/arch/x86/boot/compressed/efi_stub_32.S
12410+++ b/arch/x86/boot/compressed/efi_stub_32.S
12411@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12412 * parameter 2, ..., param n. To make things easy, we save the return
12413 * address of efi_call_phys in a global variable.
12414 */
12415- popl %ecx
12416- movl %ecx, saved_return_addr(%edx)
12417- /* get the function pointer into ECX*/
12418- popl %ecx
12419- movl %ecx, efi_rt_function_ptr(%edx)
12420+ popl saved_return_addr(%edx)
12421+ popl efi_rt_function_ptr(%edx)
12422
12423 /*
12424 * 3. Call the physical function.
12425 */
12426- call *%ecx
12427+ call *efi_rt_function_ptr(%edx)
12428
12429 /*
12430 * 4. Balance the stack. And because EAX contain the return value,
12431@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12432 1: popl %edx
12433 subl $1b, %edx
12434
12435- movl efi_rt_function_ptr(%edx), %ecx
12436- pushl %ecx
12437+ pushl efi_rt_function_ptr(%edx)
12438
12439 /*
12440 * 10. Push the saved return address onto the stack and return.
12441 */
12442- movl saved_return_addr(%edx), %ecx
12443- pushl %ecx
12444- ret
12445+ jmpl *saved_return_addr(%edx)
12446 ENDPROC(efi_call_phys)
12447 .previous
12448
12449diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12450index f45ab7a..ebc015f 100644
12451--- a/arch/x86/boot/compressed/head_32.S
12452+++ b/arch/x86/boot/compressed/head_32.S
12453@@ -119,10 +119,10 @@ preferred_addr:
12454 addl %eax, %ebx
12455 notl %eax
12456 andl %eax, %ebx
12457- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12458+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12459 jge 1f
12460 #endif
12461- movl $LOAD_PHYSICAL_ADDR, %ebx
12462+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12463 1:
12464
12465 /* Target address to relocate to for decompression */
12466diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12467index b10fa66..5ee0472 100644
12468--- a/arch/x86/boot/compressed/head_64.S
12469+++ b/arch/x86/boot/compressed/head_64.S
12470@@ -94,10 +94,10 @@ ENTRY(startup_32)
12471 addl %eax, %ebx
12472 notl %eax
12473 andl %eax, %ebx
12474- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12475+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12476 jge 1f
12477 #endif
12478- movl $LOAD_PHYSICAL_ADDR, %ebx
12479+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12480 1:
12481
12482 /* Target address to relocate to for decompression */
12483@@ -268,10 +268,10 @@ preferred_addr:
12484 addq %rax, %rbp
12485 notq %rax
12486 andq %rax, %rbp
12487- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12488+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12489 jge 1f
12490 #endif
12491- movq $LOAD_PHYSICAL_ADDR, %rbp
12492+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12493 1:
12494
12495 /* Target address to relocate to for decompression */
12496@@ -363,8 +363,8 @@ gdt:
12497 .long gdt
12498 .word 0
12499 .quad 0x0000000000000000 /* NULL descriptor */
12500- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12501- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12502+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12503+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12504 .quad 0x0080890000000000 /* TS descriptor */
12505 .quad 0x0000000000000000 /* TS continued */
12506 gdt_end:
12507diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12508index 196eaf3..c96716d 100644
12509--- a/arch/x86/boot/compressed/misc.c
12510+++ b/arch/x86/boot/compressed/misc.c
12511@@ -218,7 +218,7 @@ void __putstr(const char *s)
12512
12513 void *memset(void *s, int c, size_t n)
12514 {
12515- int i;
12516+ size_t i;
12517 char *ss = s;
12518
12519 for (i = 0; i < n; i++)
12520@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12521 * Calculate the delta between where vmlinux was linked to load
12522 * and where it was actually loaded.
12523 */
12524- delta = min_addr - LOAD_PHYSICAL_ADDR;
12525+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12526 if (!delta) {
12527 debug_putstr("No relocation needed... ");
12528 return;
12529@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12530 Elf32_Ehdr ehdr;
12531 Elf32_Phdr *phdrs, *phdr;
12532 #endif
12533- void *dest;
12534+ void *dest, *prev;
12535 int i;
12536
12537 memcpy(&ehdr, output, sizeof(ehdr));
12538@@ -374,13 +374,16 @@ static void parse_elf(void *output)
12539 case PT_LOAD:
12540 #ifdef CONFIG_RELOCATABLE
12541 dest = output;
12542- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12543+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12544 #else
12545 dest = (void *)(phdr->p_paddr);
12546 #endif
12547 memcpy(dest,
12548 output + phdr->p_offset,
12549 phdr->p_filesz);
12550+ if (i)
12551+ memset(prev, 0xff, dest - prev);
12552+ prev = dest + phdr->p_filesz;
12553 break;
12554 default: /* Ignore other PT_* */ break;
12555 }
12556@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12557 error("Destination address too large");
12558 #endif
12559 #ifndef CONFIG_RELOCATABLE
12560- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12561+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12562 error("Wrong destination address");
12563 #endif
12564
12565diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12566index 100a9a1..bb3bdb0 100644
12567--- a/arch/x86/boot/cpucheck.c
12568+++ b/arch/x86/boot/cpucheck.c
12569@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12570 u32 ecx = MSR_K7_HWCR;
12571 u32 eax, edx;
12572
12573- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12574+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12575 eax &= ~(1 << 15);
12576- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12577+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12578
12579 get_cpuflags(); /* Make sure it really did something */
12580 err = check_cpuflags();
12581@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12582 u32 ecx = MSR_VIA_FCR;
12583 u32 eax, edx;
12584
12585- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12586+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12587 eax |= (1<<1)|(1<<7);
12588- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12589+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12590
12591 set_bit(X86_FEATURE_CX8, cpu.flags);
12592 err = check_cpuflags();
12593@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12594 u32 eax, edx;
12595 u32 level = 1;
12596
12597- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12598- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12599- asm("cpuid"
12600+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12601+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12602+ asm volatile("cpuid"
12603 : "+a" (level), "=d" (cpu.flags[0])
12604 : : "ecx", "ebx");
12605- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12606+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12607
12608 err = check_cpuflags();
12609 }
12610diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12611index ec3b8ba..6a0db1f 100644
12612--- a/arch/x86/boot/header.S
12613+++ b/arch/x86/boot/header.S
12614@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12615 # single linked list of
12616 # struct setup_data
12617
12618-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12619+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12620
12621 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12622+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12623+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12624+#else
12625 #define VO_INIT_SIZE (VO__end - VO__text)
12626+#endif
12627 #if ZO_INIT_SIZE > VO_INIT_SIZE
12628 #define INIT_SIZE ZO_INIT_SIZE
12629 #else
12630diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12631index db75d07..8e6d0af 100644
12632--- a/arch/x86/boot/memory.c
12633+++ b/arch/x86/boot/memory.c
12634@@ -19,7 +19,7 @@
12635
12636 static int detect_memory_e820(void)
12637 {
12638- int count = 0;
12639+ unsigned int count = 0;
12640 struct biosregs ireg, oreg;
12641 struct e820entry *desc = boot_params.e820_map;
12642 static struct e820entry buf; /* static so it is zeroed */
12643diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12644index 11e8c6e..fdbb1ed 100644
12645--- a/arch/x86/boot/video-vesa.c
12646+++ b/arch/x86/boot/video-vesa.c
12647@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12648
12649 boot_params.screen_info.vesapm_seg = oreg.es;
12650 boot_params.screen_info.vesapm_off = oreg.di;
12651+ boot_params.screen_info.vesapm_size = oreg.cx;
12652 }
12653
12654 /*
12655diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12656index 43eda28..5ab5fdb 100644
12657--- a/arch/x86/boot/video.c
12658+++ b/arch/x86/boot/video.c
12659@@ -96,7 +96,7 @@ static void store_mode_params(void)
12660 static unsigned int get_entry(void)
12661 {
12662 char entry_buf[4];
12663- int i, len = 0;
12664+ unsigned int i, len = 0;
12665 int key;
12666 unsigned int v;
12667
12668diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12669index 9105655..41779c1 100644
12670--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12671+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12672@@ -8,6 +8,8 @@
12673 * including this sentence is retained in full.
12674 */
12675
12676+#include <asm/alternative-asm.h>
12677+
12678 .extern crypto_ft_tab
12679 .extern crypto_it_tab
12680 .extern crypto_fl_tab
12681@@ -70,6 +72,8 @@
12682 je B192; \
12683 leaq 32(r9),r9;
12684
12685+#define ret pax_force_retaddr; ret
12686+
12687 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12688 movq r1,r2; \
12689 movq r3,r4; \
12690diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12691index 477e9d7..c92c7d8 100644
12692--- a/arch/x86/crypto/aesni-intel_asm.S
12693+++ b/arch/x86/crypto/aesni-intel_asm.S
12694@@ -31,6 +31,7 @@
12695
12696 #include <linux/linkage.h>
12697 #include <asm/inst.h>
12698+#include <asm/alternative-asm.h>
12699
12700 #ifdef __x86_64__
12701 .data
12702@@ -205,7 +206,7 @@ enc: .octa 0x2
12703 * num_initial_blocks = b mod 4
12704 * encrypt the initial num_initial_blocks blocks and apply ghash on
12705 * the ciphertext
12706-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12707+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12708 * are clobbered
12709 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12710 */
12711@@ -214,8 +215,8 @@ enc: .octa 0x2
12712 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12713 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12714 mov arg7, %r10 # %r10 = AAD
12715- mov arg8, %r12 # %r12 = aadLen
12716- mov %r12, %r11
12717+ mov arg8, %r15 # %r15 = aadLen
12718+ mov %r15, %r11
12719 pxor %xmm\i, %xmm\i
12720 _get_AAD_loop\num_initial_blocks\operation:
12721 movd (%r10), \TMP1
12722@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12723 psrldq $4, %xmm\i
12724 pxor \TMP1, %xmm\i
12725 add $4, %r10
12726- sub $4, %r12
12727+ sub $4, %r15
12728 jne _get_AAD_loop\num_initial_blocks\operation
12729 cmp $16, %r11
12730 je _get_AAD_loop2_done\num_initial_blocks\operation
12731- mov $16, %r12
12732+ mov $16, %r15
12733 _get_AAD_loop2\num_initial_blocks\operation:
12734 psrldq $4, %xmm\i
12735- sub $4, %r12
12736- cmp %r11, %r12
12737+ sub $4, %r15
12738+ cmp %r11, %r15
12739 jne _get_AAD_loop2\num_initial_blocks\operation
12740 _get_AAD_loop2_done\num_initial_blocks\operation:
12741 movdqa SHUF_MASK(%rip), %xmm14
12742@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12743 * num_initial_blocks = b mod 4
12744 * encrypt the initial num_initial_blocks blocks and apply ghash on
12745 * the ciphertext
12746-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12747+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12748 * are clobbered
12749 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12750 */
12751@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12752 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12753 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12754 mov arg7, %r10 # %r10 = AAD
12755- mov arg8, %r12 # %r12 = aadLen
12756- mov %r12, %r11
12757+ mov arg8, %r15 # %r15 = aadLen
12758+ mov %r15, %r11
12759 pxor %xmm\i, %xmm\i
12760 _get_AAD_loop\num_initial_blocks\operation:
12761 movd (%r10), \TMP1
12762@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12763 psrldq $4, %xmm\i
12764 pxor \TMP1, %xmm\i
12765 add $4, %r10
12766- sub $4, %r12
12767+ sub $4, %r15
12768 jne _get_AAD_loop\num_initial_blocks\operation
12769 cmp $16, %r11
12770 je _get_AAD_loop2_done\num_initial_blocks\operation
12771- mov $16, %r12
12772+ mov $16, %r15
12773 _get_AAD_loop2\num_initial_blocks\operation:
12774 psrldq $4, %xmm\i
12775- sub $4, %r12
12776- cmp %r11, %r12
12777+ sub $4, %r15
12778+ cmp %r11, %r15
12779 jne _get_AAD_loop2\num_initial_blocks\operation
12780 _get_AAD_loop2_done\num_initial_blocks\operation:
12781 movdqa SHUF_MASK(%rip), %xmm14
12782@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12783 *
12784 *****************************************************************************/
12785 ENTRY(aesni_gcm_dec)
12786- push %r12
12787+ push %r15
12788 push %r13
12789 push %r14
12790 mov %rsp, %r14
12791@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12792 */
12793 sub $VARIABLE_OFFSET, %rsp
12794 and $~63, %rsp # align rsp to 64 bytes
12795- mov %arg6, %r12
12796- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12797+ mov %arg6, %r15
12798+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12799 movdqa SHUF_MASK(%rip), %xmm2
12800 PSHUFB_XMM %xmm2, %xmm13
12801
12802@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12803 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12804 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12805 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12806- mov %r13, %r12
12807- and $(3<<4), %r12
12808+ mov %r13, %r15
12809+ and $(3<<4), %r15
12810 jz _initial_num_blocks_is_0_decrypt
12811- cmp $(2<<4), %r12
12812+ cmp $(2<<4), %r15
12813 jb _initial_num_blocks_is_1_decrypt
12814 je _initial_num_blocks_is_2_decrypt
12815 _initial_num_blocks_is_3_decrypt:
12816@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12817 sub $16, %r11
12818 add %r13, %r11
12819 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12820- lea SHIFT_MASK+16(%rip), %r12
12821- sub %r13, %r12
12822+ lea SHIFT_MASK+16(%rip), %r15
12823+ sub %r13, %r15
12824 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12825 # (%r13 is the number of bytes in plaintext mod 16)
12826- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12827+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12828 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12829
12830 movdqa %xmm1, %xmm2
12831 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12832- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12833+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12834 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12835 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12836 pand %xmm1, %xmm2
12837@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12838 sub $1, %r13
12839 jne _less_than_8_bytes_left_decrypt
12840 _multiple_of_16_bytes_decrypt:
12841- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12842- shl $3, %r12 # convert into number of bits
12843- movd %r12d, %xmm15 # len(A) in %xmm15
12844+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12845+ shl $3, %r15 # convert into number of bits
12846+ movd %r15d, %xmm15 # len(A) in %xmm15
12847 shl $3, %arg4 # len(C) in bits (*128)
12848 MOVQ_R64_XMM %arg4, %xmm1
12849 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12850@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12851 mov %r14, %rsp
12852 pop %r14
12853 pop %r13
12854- pop %r12
12855+ pop %r15
12856+ pax_force_retaddr
12857 ret
12858 ENDPROC(aesni_gcm_dec)
12859
12860@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12861 * poly = x^128 + x^127 + x^126 + x^121 + 1
12862 ***************************************************************************/
12863 ENTRY(aesni_gcm_enc)
12864- push %r12
12865+ push %r15
12866 push %r13
12867 push %r14
12868 mov %rsp, %r14
12869@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12870 #
12871 sub $VARIABLE_OFFSET, %rsp
12872 and $~63, %rsp
12873- mov %arg6, %r12
12874- movdqu (%r12), %xmm13
12875+ mov %arg6, %r15
12876+ movdqu (%r15), %xmm13
12877 movdqa SHUF_MASK(%rip), %xmm2
12878 PSHUFB_XMM %xmm2, %xmm13
12879
12880@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12881 movdqa %xmm13, HashKey(%rsp)
12882 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12883 and $-16, %r13
12884- mov %r13, %r12
12885+ mov %r13, %r15
12886
12887 # Encrypt first few blocks
12888
12889- and $(3<<4), %r12
12890+ and $(3<<4), %r15
12891 jz _initial_num_blocks_is_0_encrypt
12892- cmp $(2<<4), %r12
12893+ cmp $(2<<4), %r15
12894 jb _initial_num_blocks_is_1_encrypt
12895 je _initial_num_blocks_is_2_encrypt
12896 _initial_num_blocks_is_3_encrypt:
12897@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12898 sub $16, %r11
12899 add %r13, %r11
12900 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12901- lea SHIFT_MASK+16(%rip), %r12
12902- sub %r13, %r12
12903+ lea SHIFT_MASK+16(%rip), %r15
12904+ sub %r13, %r15
12905 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12906 # (%r13 is the number of bytes in plaintext mod 16)
12907- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12908+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12909 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12910 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12911- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12912+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12913 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12914 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12915 movdqa SHUF_MASK(%rip), %xmm10
12916@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12917 sub $1, %r13
12918 jne _less_than_8_bytes_left_encrypt
12919 _multiple_of_16_bytes_encrypt:
12920- mov arg8, %r12 # %r12 = addLen (number of bytes)
12921- shl $3, %r12
12922- movd %r12d, %xmm15 # len(A) in %xmm15
12923+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12924+ shl $3, %r15
12925+ movd %r15d, %xmm15 # len(A) in %xmm15
12926 shl $3, %arg4 # len(C) in bits (*128)
12927 MOVQ_R64_XMM %arg4, %xmm1
12928 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12929@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12930 mov %r14, %rsp
12931 pop %r14
12932 pop %r13
12933- pop %r12
12934+ pop %r15
12935+ pax_force_retaddr
12936 ret
12937 ENDPROC(aesni_gcm_enc)
12938
12939@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12940 pxor %xmm1, %xmm0
12941 movaps %xmm0, (TKEYP)
12942 add $0x10, TKEYP
12943+ pax_force_retaddr
12944 ret
12945 ENDPROC(_key_expansion_128)
12946 ENDPROC(_key_expansion_256a)
12947@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12948 shufps $0b01001110, %xmm2, %xmm1
12949 movaps %xmm1, 0x10(TKEYP)
12950 add $0x20, TKEYP
12951+ pax_force_retaddr
12952 ret
12953 ENDPROC(_key_expansion_192a)
12954
12955@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12956
12957 movaps %xmm0, (TKEYP)
12958 add $0x10, TKEYP
12959+ pax_force_retaddr
12960 ret
12961 ENDPROC(_key_expansion_192b)
12962
12963@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12964 pxor %xmm1, %xmm2
12965 movaps %xmm2, (TKEYP)
12966 add $0x10, TKEYP
12967+ pax_force_retaddr
12968 ret
12969 ENDPROC(_key_expansion_256b)
12970
12971@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12972 #ifndef __x86_64__
12973 popl KEYP
12974 #endif
12975+ pax_force_retaddr
12976 ret
12977 ENDPROC(aesni_set_key)
12978
12979@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12980 popl KLEN
12981 popl KEYP
12982 #endif
12983+ pax_force_retaddr
12984 ret
12985 ENDPROC(aesni_enc)
12986
12987@@ -1974,6 +1983,7 @@ _aesni_enc1:
12988 AESENC KEY STATE
12989 movaps 0x70(TKEYP), KEY
12990 AESENCLAST KEY STATE
12991+ pax_force_retaddr
12992 ret
12993 ENDPROC(_aesni_enc1)
12994
12995@@ -2083,6 +2093,7 @@ _aesni_enc4:
12996 AESENCLAST KEY STATE2
12997 AESENCLAST KEY STATE3
12998 AESENCLAST KEY STATE4
12999+ pax_force_retaddr
13000 ret
13001 ENDPROC(_aesni_enc4)
13002
13003@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13004 popl KLEN
13005 popl KEYP
13006 #endif
13007+ pax_force_retaddr
13008 ret
13009 ENDPROC(aesni_dec)
13010
13011@@ -2164,6 +2176,7 @@ _aesni_dec1:
13012 AESDEC KEY STATE
13013 movaps 0x70(TKEYP), KEY
13014 AESDECLAST KEY STATE
13015+ pax_force_retaddr
13016 ret
13017 ENDPROC(_aesni_dec1)
13018
13019@@ -2273,6 +2286,7 @@ _aesni_dec4:
13020 AESDECLAST KEY STATE2
13021 AESDECLAST KEY STATE3
13022 AESDECLAST KEY STATE4
13023+ pax_force_retaddr
13024 ret
13025 ENDPROC(_aesni_dec4)
13026
13027@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13028 popl KEYP
13029 popl LEN
13030 #endif
13031+ pax_force_retaddr
13032 ret
13033 ENDPROC(aesni_ecb_enc)
13034
13035@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13036 popl KEYP
13037 popl LEN
13038 #endif
13039+ pax_force_retaddr
13040 ret
13041 ENDPROC(aesni_ecb_dec)
13042
13043@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13044 popl LEN
13045 popl IVP
13046 #endif
13047+ pax_force_retaddr
13048 ret
13049 ENDPROC(aesni_cbc_enc)
13050
13051@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13052 popl LEN
13053 popl IVP
13054 #endif
13055+ pax_force_retaddr
13056 ret
13057 ENDPROC(aesni_cbc_dec)
13058
13059@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13060 mov $1, TCTR_LOW
13061 MOVQ_R64_XMM TCTR_LOW INC
13062 MOVQ_R64_XMM CTR TCTR_LOW
13063+ pax_force_retaddr
13064 ret
13065 ENDPROC(_aesni_inc_init)
13066
13067@@ -2579,6 +2598,7 @@ _aesni_inc:
13068 .Linc_low:
13069 movaps CTR, IV
13070 PSHUFB_XMM BSWAP_MASK IV
13071+ pax_force_retaddr
13072 ret
13073 ENDPROC(_aesni_inc)
13074
13075@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13076 .Lctr_enc_ret:
13077 movups IV, (IVP)
13078 .Lctr_enc_just_ret:
13079+ pax_force_retaddr
13080 ret
13081 ENDPROC(aesni_ctr_enc)
13082
13083@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13084 pxor INC, STATE4
13085 movdqu STATE4, 0x70(OUTP)
13086
13087+ pax_force_retaddr
13088 ret
13089 ENDPROC(aesni_xts_crypt8)
13090
13091diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13092index 246c670..466e2d6 100644
13093--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13094+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13095@@ -21,6 +21,7 @@
13096 */
13097
13098 #include <linux/linkage.h>
13099+#include <asm/alternative-asm.h>
13100
13101 .file "blowfish-x86_64-asm.S"
13102 .text
13103@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13104 jnz .L__enc_xor;
13105
13106 write_block();
13107+ pax_force_retaddr
13108 ret;
13109 .L__enc_xor:
13110 xor_block();
13111+ pax_force_retaddr
13112 ret;
13113 ENDPROC(__blowfish_enc_blk)
13114
13115@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13116
13117 movq %r11, %rbp;
13118
13119+ pax_force_retaddr
13120 ret;
13121 ENDPROC(blowfish_dec_blk)
13122
13123@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13124
13125 popq %rbx;
13126 popq %rbp;
13127+ pax_force_retaddr
13128 ret;
13129
13130 .L__enc_xor4:
13131@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13132
13133 popq %rbx;
13134 popq %rbp;
13135+ pax_force_retaddr
13136 ret;
13137 ENDPROC(__blowfish_enc_blk_4way)
13138
13139@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13140 popq %rbx;
13141 popq %rbp;
13142
13143+ pax_force_retaddr
13144 ret;
13145 ENDPROC(blowfish_dec_blk_4way)
13146diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13147index ce71f92..1dce7ec 100644
13148--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13149+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13150@@ -16,6 +16,7 @@
13151 */
13152
13153 #include <linux/linkage.h>
13154+#include <asm/alternative-asm.h>
13155
13156 #define CAMELLIA_TABLE_BYTE_LEN 272
13157
13158@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13159 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13160 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13161 %rcx, (%r9));
13162+ pax_force_retaddr
13163 ret;
13164 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13165
13166@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13167 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13168 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13169 %rax, (%r9));
13170+ pax_force_retaddr
13171 ret;
13172 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13173
13174@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13175 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13176 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13177
13178+ pax_force_retaddr
13179 ret;
13180
13181 .align 8
13182@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13183 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13184 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13185
13186+ pax_force_retaddr
13187 ret;
13188
13189 .align 8
13190@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13191 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13192 %xmm8, %rsi);
13193
13194+ pax_force_retaddr
13195 ret;
13196 ENDPROC(camellia_ecb_enc_16way)
13197
13198@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13199 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13200 %xmm8, %rsi);
13201
13202+ pax_force_retaddr
13203 ret;
13204 ENDPROC(camellia_ecb_dec_16way)
13205
13206@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13207 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13208 %xmm8, %rsi);
13209
13210+ pax_force_retaddr
13211 ret;
13212 ENDPROC(camellia_cbc_dec_16way)
13213
13214@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13215 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13216 %xmm8, %rsi);
13217
13218+ pax_force_retaddr
13219 ret;
13220 ENDPROC(camellia_ctr_16way)
13221
13222@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13223 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13224 %xmm8, %rsi);
13225
13226+ pax_force_retaddr
13227 ret;
13228 ENDPROC(camellia_xts_crypt_16way)
13229
13230diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13231index 0e0b886..5a3123c 100644
13232--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13233+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13234@@ -11,6 +11,7 @@
13235 */
13236
13237 #include <linux/linkage.h>
13238+#include <asm/alternative-asm.h>
13239
13240 #define CAMELLIA_TABLE_BYTE_LEN 272
13241
13242@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13243 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13244 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13245 %rcx, (%r9));
13246+ pax_force_retaddr
13247 ret;
13248 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13249
13250@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13251 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13252 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13253 %rax, (%r9));
13254+ pax_force_retaddr
13255 ret;
13256 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13257
13258@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13259 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13260 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13261
13262+ pax_force_retaddr
13263 ret;
13264
13265 .align 8
13266@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13267 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13268 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13269
13270+ pax_force_retaddr
13271 ret;
13272
13273 .align 8
13274@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13275
13276 vzeroupper;
13277
13278+ pax_force_retaddr
13279 ret;
13280 ENDPROC(camellia_ecb_enc_32way)
13281
13282@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13283
13284 vzeroupper;
13285
13286+ pax_force_retaddr
13287 ret;
13288 ENDPROC(camellia_ecb_dec_32way)
13289
13290@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13291
13292 vzeroupper;
13293
13294+ pax_force_retaddr
13295 ret;
13296 ENDPROC(camellia_cbc_dec_32way)
13297
13298@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13299
13300 vzeroupper;
13301
13302+ pax_force_retaddr
13303 ret;
13304 ENDPROC(camellia_ctr_32way)
13305
13306@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13307
13308 vzeroupper;
13309
13310+ pax_force_retaddr
13311 ret;
13312 ENDPROC(camellia_xts_crypt_32way)
13313
13314diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13315index 310319c..db3d7b5 100644
13316--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13317+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13318@@ -21,6 +21,7 @@
13319 */
13320
13321 #include <linux/linkage.h>
13322+#include <asm/alternative-asm.h>
13323
13324 .file "camellia-x86_64-asm_64.S"
13325 .text
13326@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13327 enc_outunpack(mov, RT1);
13328
13329 movq RRBP, %rbp;
13330+ pax_force_retaddr
13331 ret;
13332
13333 .L__enc_xor:
13334 enc_outunpack(xor, RT1);
13335
13336 movq RRBP, %rbp;
13337+ pax_force_retaddr
13338 ret;
13339 ENDPROC(__camellia_enc_blk)
13340
13341@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13342 dec_outunpack();
13343
13344 movq RRBP, %rbp;
13345+ pax_force_retaddr
13346 ret;
13347 ENDPROC(camellia_dec_blk)
13348
13349@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13350
13351 movq RRBP, %rbp;
13352 popq %rbx;
13353+ pax_force_retaddr
13354 ret;
13355
13356 .L__enc2_xor:
13357@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13358
13359 movq RRBP, %rbp;
13360 popq %rbx;
13361+ pax_force_retaddr
13362 ret;
13363 ENDPROC(__camellia_enc_blk_2way)
13364
13365@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13366
13367 movq RRBP, %rbp;
13368 movq RXOR, %rbx;
13369+ pax_force_retaddr
13370 ret;
13371 ENDPROC(camellia_dec_blk_2way)
13372diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13373index c35fd5d..2d8c7db 100644
13374--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13375+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13376@@ -24,6 +24,7 @@
13377 */
13378
13379 #include <linux/linkage.h>
13380+#include <asm/alternative-asm.h>
13381
13382 .file "cast5-avx-x86_64-asm_64.S"
13383
13384@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13385 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13386 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13387
13388+ pax_force_retaddr
13389 ret;
13390 ENDPROC(__cast5_enc_blk16)
13391
13392@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13393 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13394 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13395
13396+ pax_force_retaddr
13397 ret;
13398
13399 .L__skip_dec:
13400@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13401 vmovdqu RR4, (6*4*4)(%r11);
13402 vmovdqu RL4, (7*4*4)(%r11);
13403
13404+ pax_force_retaddr
13405 ret;
13406 ENDPROC(cast5_ecb_enc_16way)
13407
13408@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13409 vmovdqu RR4, (6*4*4)(%r11);
13410 vmovdqu RL4, (7*4*4)(%r11);
13411
13412+ pax_force_retaddr
13413 ret;
13414 ENDPROC(cast5_ecb_dec_16way)
13415
13416@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13417 * %rdx: src
13418 */
13419
13420- pushq %r12;
13421+ pushq %r14;
13422
13423 movq %rsi, %r11;
13424- movq %rdx, %r12;
13425+ movq %rdx, %r14;
13426
13427 vmovdqu (0*16)(%rdx), RL1;
13428 vmovdqu (1*16)(%rdx), RR1;
13429@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13430 call __cast5_dec_blk16;
13431
13432 /* xor with src */
13433- vmovq (%r12), RX;
13434+ vmovq (%r14), RX;
13435 vpshufd $0x4f, RX, RX;
13436 vpxor RX, RR1, RR1;
13437- vpxor 0*16+8(%r12), RL1, RL1;
13438- vpxor 1*16+8(%r12), RR2, RR2;
13439- vpxor 2*16+8(%r12), RL2, RL2;
13440- vpxor 3*16+8(%r12), RR3, RR3;
13441- vpxor 4*16+8(%r12), RL3, RL3;
13442- vpxor 5*16+8(%r12), RR4, RR4;
13443- vpxor 6*16+8(%r12), RL4, RL4;
13444+ vpxor 0*16+8(%r14), RL1, RL1;
13445+ vpxor 1*16+8(%r14), RR2, RR2;
13446+ vpxor 2*16+8(%r14), RL2, RL2;
13447+ vpxor 3*16+8(%r14), RR3, RR3;
13448+ vpxor 4*16+8(%r14), RL3, RL3;
13449+ vpxor 5*16+8(%r14), RR4, RR4;
13450+ vpxor 6*16+8(%r14), RL4, RL4;
13451
13452 vmovdqu RR1, (0*16)(%r11);
13453 vmovdqu RL1, (1*16)(%r11);
13454@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13455 vmovdqu RR4, (6*16)(%r11);
13456 vmovdqu RL4, (7*16)(%r11);
13457
13458- popq %r12;
13459+ popq %r14;
13460
13461+ pax_force_retaddr
13462 ret;
13463 ENDPROC(cast5_cbc_dec_16way)
13464
13465@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13466 * %rcx: iv (big endian, 64bit)
13467 */
13468
13469- pushq %r12;
13470+ pushq %r14;
13471
13472 movq %rsi, %r11;
13473- movq %rdx, %r12;
13474+ movq %rdx, %r14;
13475
13476 vpcmpeqd RTMP, RTMP, RTMP;
13477 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13478@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13479 call __cast5_enc_blk16;
13480
13481 /* dst = src ^ iv */
13482- vpxor (0*16)(%r12), RR1, RR1;
13483- vpxor (1*16)(%r12), RL1, RL1;
13484- vpxor (2*16)(%r12), RR2, RR2;
13485- vpxor (3*16)(%r12), RL2, RL2;
13486- vpxor (4*16)(%r12), RR3, RR3;
13487- vpxor (5*16)(%r12), RL3, RL3;
13488- vpxor (6*16)(%r12), RR4, RR4;
13489- vpxor (7*16)(%r12), RL4, RL4;
13490+ vpxor (0*16)(%r14), RR1, RR1;
13491+ vpxor (1*16)(%r14), RL1, RL1;
13492+ vpxor (2*16)(%r14), RR2, RR2;
13493+ vpxor (3*16)(%r14), RL2, RL2;
13494+ vpxor (4*16)(%r14), RR3, RR3;
13495+ vpxor (5*16)(%r14), RL3, RL3;
13496+ vpxor (6*16)(%r14), RR4, RR4;
13497+ vpxor (7*16)(%r14), RL4, RL4;
13498 vmovdqu RR1, (0*16)(%r11);
13499 vmovdqu RL1, (1*16)(%r11);
13500 vmovdqu RR2, (2*16)(%r11);
13501@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13502 vmovdqu RR4, (6*16)(%r11);
13503 vmovdqu RL4, (7*16)(%r11);
13504
13505- popq %r12;
13506+ popq %r14;
13507
13508+ pax_force_retaddr
13509 ret;
13510 ENDPROC(cast5_ctr_16way)
13511diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13512index e3531f8..e123f35 100644
13513--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13514+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13515@@ -24,6 +24,7 @@
13516 */
13517
13518 #include <linux/linkage.h>
13519+#include <asm/alternative-asm.h>
13520 #include "glue_helper-asm-avx.S"
13521
13522 .file "cast6-avx-x86_64-asm_64.S"
13523@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13524 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13525 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13526
13527+ pax_force_retaddr
13528 ret;
13529 ENDPROC(__cast6_enc_blk8)
13530
13531@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13532 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13533 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13534
13535+ pax_force_retaddr
13536 ret;
13537 ENDPROC(__cast6_dec_blk8)
13538
13539@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13540
13541 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13542
13543+ pax_force_retaddr
13544 ret;
13545 ENDPROC(cast6_ecb_enc_8way)
13546
13547@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13548
13549 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13550
13551+ pax_force_retaddr
13552 ret;
13553 ENDPROC(cast6_ecb_dec_8way)
13554
13555@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13556 * %rdx: src
13557 */
13558
13559- pushq %r12;
13560+ pushq %r14;
13561
13562 movq %rsi, %r11;
13563- movq %rdx, %r12;
13564+ movq %rdx, %r14;
13565
13566 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13567
13568 call __cast6_dec_blk8;
13569
13570- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13571+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13572
13573- popq %r12;
13574+ popq %r14;
13575
13576+ pax_force_retaddr
13577 ret;
13578 ENDPROC(cast6_cbc_dec_8way)
13579
13580@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13581 * %rcx: iv (little endian, 128bit)
13582 */
13583
13584- pushq %r12;
13585+ pushq %r14;
13586
13587 movq %rsi, %r11;
13588- movq %rdx, %r12;
13589+ movq %rdx, %r14;
13590
13591 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13592 RD2, RX, RKR, RKM);
13593
13594 call __cast6_enc_blk8;
13595
13596- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13597+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13598
13599- popq %r12;
13600+ popq %r14;
13601
13602+ pax_force_retaddr
13603 ret;
13604 ENDPROC(cast6_ctr_8way)
13605
13606@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13607 /* dst <= regs xor IVs(in dst) */
13608 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13609
13610+ pax_force_retaddr
13611 ret;
13612 ENDPROC(cast6_xts_enc_8way)
13613
13614@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13615 /* dst <= regs xor IVs(in dst) */
13616 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13617
13618+ pax_force_retaddr
13619 ret;
13620 ENDPROC(cast6_xts_dec_8way)
13621diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13622index dbc4339..de6e120 100644
13623--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13624+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13625@@ -45,6 +45,7 @@
13626
13627 #include <asm/inst.h>
13628 #include <linux/linkage.h>
13629+#include <asm/alternative-asm.h>
13630
13631 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13632
13633@@ -312,6 +313,7 @@ do_return:
13634 popq %rsi
13635 popq %rdi
13636 popq %rbx
13637+ pax_force_retaddr
13638 ret
13639
13640 ################################################################
13641diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13642index 185fad4..ff4cd36 100644
13643--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13644+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13645@@ -18,6 +18,7 @@
13646
13647 #include <linux/linkage.h>
13648 #include <asm/inst.h>
13649+#include <asm/alternative-asm.h>
13650
13651 .data
13652
13653@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13654 psrlq $1, T2
13655 pxor T2, T1
13656 pxor T1, DATA
13657+ pax_force_retaddr
13658 ret
13659 ENDPROC(__clmul_gf128mul_ble)
13660
13661@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13662 call __clmul_gf128mul_ble
13663 PSHUFB_XMM BSWAP DATA
13664 movups DATA, (%rdi)
13665+ pax_force_retaddr
13666 ret
13667 ENDPROC(clmul_ghash_mul)
13668
13669@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13670 PSHUFB_XMM BSWAP DATA
13671 movups DATA, (%rdi)
13672 .Lupdate_just_ret:
13673+ pax_force_retaddr
13674 ret
13675 ENDPROC(clmul_ghash_update)
13676diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13677index 9279e0b..c4b3d2c 100644
13678--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13679+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13680@@ -1,4 +1,5 @@
13681 #include <linux/linkage.h>
13682+#include <asm/alternative-asm.h>
13683
13684 # enter salsa20_encrypt_bytes
13685 ENTRY(salsa20_encrypt_bytes)
13686@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13687 add %r11,%rsp
13688 mov %rdi,%rax
13689 mov %rsi,%rdx
13690+ pax_force_retaddr
13691 ret
13692 # bytesatleast65:
13693 ._bytesatleast65:
13694@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13695 add %r11,%rsp
13696 mov %rdi,%rax
13697 mov %rsi,%rdx
13698+ pax_force_retaddr
13699 ret
13700 ENDPROC(salsa20_keysetup)
13701
13702@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13703 add %r11,%rsp
13704 mov %rdi,%rax
13705 mov %rsi,%rdx
13706+ pax_force_retaddr
13707 ret
13708 ENDPROC(salsa20_ivsetup)
13709diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13710index 2f202f4..d9164d6 100644
13711--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13712+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13713@@ -24,6 +24,7 @@
13714 */
13715
13716 #include <linux/linkage.h>
13717+#include <asm/alternative-asm.h>
13718 #include "glue_helper-asm-avx.S"
13719
13720 .file "serpent-avx-x86_64-asm_64.S"
13721@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13722 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13723 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13724
13725+ pax_force_retaddr
13726 ret;
13727 ENDPROC(__serpent_enc_blk8_avx)
13728
13729@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13730 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13731 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13732
13733+ pax_force_retaddr
13734 ret;
13735 ENDPROC(__serpent_dec_blk8_avx)
13736
13737@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13738
13739 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13740
13741+ pax_force_retaddr
13742 ret;
13743 ENDPROC(serpent_ecb_enc_8way_avx)
13744
13745@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13746
13747 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13748
13749+ pax_force_retaddr
13750 ret;
13751 ENDPROC(serpent_ecb_dec_8way_avx)
13752
13753@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13754
13755 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13756
13757+ pax_force_retaddr
13758 ret;
13759 ENDPROC(serpent_cbc_dec_8way_avx)
13760
13761@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13762
13763 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13764
13765+ pax_force_retaddr
13766 ret;
13767 ENDPROC(serpent_ctr_8way_avx)
13768
13769@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13770 /* dst <= regs xor IVs(in dst) */
13771 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13772
13773+ pax_force_retaddr
13774 ret;
13775 ENDPROC(serpent_xts_enc_8way_avx)
13776
13777@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13778 /* dst <= regs xor IVs(in dst) */
13779 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13780
13781+ pax_force_retaddr
13782 ret;
13783 ENDPROC(serpent_xts_dec_8way_avx)
13784diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13785index b222085..abd483c 100644
13786--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13787+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13788@@ -15,6 +15,7 @@
13789 */
13790
13791 #include <linux/linkage.h>
13792+#include <asm/alternative-asm.h>
13793 #include "glue_helper-asm-avx2.S"
13794
13795 .file "serpent-avx2-asm_64.S"
13796@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13797 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13798 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13799
13800+ pax_force_retaddr
13801 ret;
13802 ENDPROC(__serpent_enc_blk16)
13803
13804@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13805 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13806 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13807
13808+ pax_force_retaddr
13809 ret;
13810 ENDPROC(__serpent_dec_blk16)
13811
13812@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13813
13814 vzeroupper;
13815
13816+ pax_force_retaddr
13817 ret;
13818 ENDPROC(serpent_ecb_enc_16way)
13819
13820@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13821
13822 vzeroupper;
13823
13824+ pax_force_retaddr
13825 ret;
13826 ENDPROC(serpent_ecb_dec_16way)
13827
13828@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13829
13830 vzeroupper;
13831
13832+ pax_force_retaddr
13833 ret;
13834 ENDPROC(serpent_cbc_dec_16way)
13835
13836@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13837
13838 vzeroupper;
13839
13840+ pax_force_retaddr
13841 ret;
13842 ENDPROC(serpent_ctr_16way)
13843
13844@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13845
13846 vzeroupper;
13847
13848+ pax_force_retaddr
13849 ret;
13850 ENDPROC(serpent_xts_enc_16way)
13851
13852@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13853
13854 vzeroupper;
13855
13856+ pax_force_retaddr
13857 ret;
13858 ENDPROC(serpent_xts_dec_16way)
13859diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13860index acc066c..1559cc4 100644
13861--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13862+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13863@@ -25,6 +25,7 @@
13864 */
13865
13866 #include <linux/linkage.h>
13867+#include <asm/alternative-asm.h>
13868
13869 .file "serpent-sse2-x86_64-asm_64.S"
13870 .text
13871@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13872 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13873 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13874
13875+ pax_force_retaddr
13876 ret;
13877
13878 .L__enc_xor8:
13879 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13880 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13881
13882+ pax_force_retaddr
13883 ret;
13884 ENDPROC(__serpent_enc_blk_8way)
13885
13886@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13887 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13888 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13889
13890+ pax_force_retaddr
13891 ret;
13892 ENDPROC(serpent_dec_blk_8way)
13893diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13894index a410950..9dfe7ad 100644
13895--- a/arch/x86/crypto/sha1_ssse3_asm.S
13896+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13897@@ -29,6 +29,7 @@
13898 */
13899
13900 #include <linux/linkage.h>
13901+#include <asm/alternative-asm.h>
13902
13903 #define CTX %rdi // arg1
13904 #define BUF %rsi // arg2
13905@@ -75,9 +76,9 @@
13906
13907 push %rbx
13908 push %rbp
13909- push %r12
13910+ push %r14
13911
13912- mov %rsp, %r12
13913+ mov %rsp, %r14
13914 sub $64, %rsp # allocate workspace
13915 and $~15, %rsp # align stack
13916
13917@@ -99,11 +100,12 @@
13918 xor %rax, %rax
13919 rep stosq
13920
13921- mov %r12, %rsp # deallocate workspace
13922+ mov %r14, %rsp # deallocate workspace
13923
13924- pop %r12
13925+ pop %r14
13926 pop %rbp
13927 pop %rbx
13928+ pax_force_retaddr
13929 ret
13930
13931 ENDPROC(\name)
13932diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13933index 642f156..51a513c 100644
13934--- a/arch/x86/crypto/sha256-avx-asm.S
13935+++ b/arch/x86/crypto/sha256-avx-asm.S
13936@@ -49,6 +49,7 @@
13937
13938 #ifdef CONFIG_AS_AVX
13939 #include <linux/linkage.h>
13940+#include <asm/alternative-asm.h>
13941
13942 ## assume buffers not aligned
13943 #define VMOVDQ vmovdqu
13944@@ -460,6 +461,7 @@ done_hash:
13945 popq %r13
13946 popq %rbp
13947 popq %rbx
13948+ pax_force_retaddr
13949 ret
13950 ENDPROC(sha256_transform_avx)
13951
13952diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13953index 9e86944..3795e6a 100644
13954--- a/arch/x86/crypto/sha256-avx2-asm.S
13955+++ b/arch/x86/crypto/sha256-avx2-asm.S
13956@@ -50,6 +50,7 @@
13957
13958 #ifdef CONFIG_AS_AVX2
13959 #include <linux/linkage.h>
13960+#include <asm/alternative-asm.h>
13961
13962 ## assume buffers not aligned
13963 #define VMOVDQ vmovdqu
13964@@ -720,6 +721,7 @@ done_hash:
13965 popq %r12
13966 popq %rbp
13967 popq %rbx
13968+ pax_force_retaddr
13969 ret
13970 ENDPROC(sha256_transform_rorx)
13971
13972diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13973index f833b74..8c62a9e 100644
13974--- a/arch/x86/crypto/sha256-ssse3-asm.S
13975+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13976@@ -47,6 +47,7 @@
13977 ########################################################################
13978
13979 #include <linux/linkage.h>
13980+#include <asm/alternative-asm.h>
13981
13982 ## assume buffers not aligned
13983 #define MOVDQ movdqu
13984@@ -471,6 +472,7 @@ done_hash:
13985 popq %rbp
13986 popq %rbx
13987
13988+ pax_force_retaddr
13989 ret
13990 ENDPROC(sha256_transform_ssse3)
13991
13992diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13993index 974dde9..a823ff9 100644
13994--- a/arch/x86/crypto/sha512-avx-asm.S
13995+++ b/arch/x86/crypto/sha512-avx-asm.S
13996@@ -49,6 +49,7 @@
13997
13998 #ifdef CONFIG_AS_AVX
13999 #include <linux/linkage.h>
14000+#include <asm/alternative-asm.h>
14001
14002 .text
14003
14004@@ -364,6 +365,7 @@ updateblock:
14005 mov frame_RSPSAVE(%rsp), %rsp
14006
14007 nowork:
14008+ pax_force_retaddr
14009 ret
14010 ENDPROC(sha512_transform_avx)
14011
14012diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14013index 568b961..ed20c37 100644
14014--- a/arch/x86/crypto/sha512-avx2-asm.S
14015+++ b/arch/x86/crypto/sha512-avx2-asm.S
14016@@ -51,6 +51,7 @@
14017
14018 #ifdef CONFIG_AS_AVX2
14019 #include <linux/linkage.h>
14020+#include <asm/alternative-asm.h>
14021
14022 .text
14023
14024@@ -678,6 +679,7 @@ done_hash:
14025
14026 # Restore Stack Pointer
14027 mov frame_RSPSAVE(%rsp), %rsp
14028+ pax_force_retaddr
14029 ret
14030 ENDPROC(sha512_transform_rorx)
14031
14032diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14033index fb56855..6edd768 100644
14034--- a/arch/x86/crypto/sha512-ssse3-asm.S
14035+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14036@@ -48,6 +48,7 @@
14037 ########################################################################
14038
14039 #include <linux/linkage.h>
14040+#include <asm/alternative-asm.h>
14041
14042 .text
14043
14044@@ -363,6 +364,7 @@ updateblock:
14045 mov frame_RSPSAVE(%rsp), %rsp
14046
14047 nowork:
14048+ pax_force_retaddr
14049 ret
14050 ENDPROC(sha512_transform_ssse3)
14051
14052diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14053index 0505813..b067311 100644
14054--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14055+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14056@@ -24,6 +24,7 @@
14057 */
14058
14059 #include <linux/linkage.h>
14060+#include <asm/alternative-asm.h>
14061 #include "glue_helper-asm-avx.S"
14062
14063 .file "twofish-avx-x86_64-asm_64.S"
14064@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14065 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14066 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14067
14068+ pax_force_retaddr
14069 ret;
14070 ENDPROC(__twofish_enc_blk8)
14071
14072@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14073 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14074 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14075
14076+ pax_force_retaddr
14077 ret;
14078 ENDPROC(__twofish_dec_blk8)
14079
14080@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14081
14082 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14083
14084+ pax_force_retaddr
14085 ret;
14086 ENDPROC(twofish_ecb_enc_8way)
14087
14088@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14089
14090 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14091
14092+ pax_force_retaddr
14093 ret;
14094 ENDPROC(twofish_ecb_dec_8way)
14095
14096@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14097 * %rdx: src
14098 */
14099
14100- pushq %r12;
14101+ pushq %r14;
14102
14103 movq %rsi, %r11;
14104- movq %rdx, %r12;
14105+ movq %rdx, %r14;
14106
14107 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14108
14109 call __twofish_dec_blk8;
14110
14111- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14112+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14113
14114- popq %r12;
14115+ popq %r14;
14116
14117+ pax_force_retaddr
14118 ret;
14119 ENDPROC(twofish_cbc_dec_8way)
14120
14121@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14122 * %rcx: iv (little endian, 128bit)
14123 */
14124
14125- pushq %r12;
14126+ pushq %r14;
14127
14128 movq %rsi, %r11;
14129- movq %rdx, %r12;
14130+ movq %rdx, %r14;
14131
14132 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14133 RD2, RX0, RX1, RY0);
14134
14135 call __twofish_enc_blk8;
14136
14137- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14138+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14139
14140- popq %r12;
14141+ popq %r14;
14142
14143+ pax_force_retaddr
14144 ret;
14145 ENDPROC(twofish_ctr_8way)
14146
14147@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14148 /* dst <= regs xor IVs(in dst) */
14149 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14150
14151+ pax_force_retaddr
14152 ret;
14153 ENDPROC(twofish_xts_enc_8way)
14154
14155@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14156 /* dst <= regs xor IVs(in dst) */
14157 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14158
14159+ pax_force_retaddr
14160 ret;
14161 ENDPROC(twofish_xts_dec_8way)
14162diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14163index 1c3b7ce..02f578d 100644
14164--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14165+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14166@@ -21,6 +21,7 @@
14167 */
14168
14169 #include <linux/linkage.h>
14170+#include <asm/alternative-asm.h>
14171
14172 .file "twofish-x86_64-asm-3way.S"
14173 .text
14174@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14175 popq %r13;
14176 popq %r14;
14177 popq %r15;
14178+ pax_force_retaddr
14179 ret;
14180
14181 .L__enc_xor3:
14182@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14183 popq %r13;
14184 popq %r14;
14185 popq %r15;
14186+ pax_force_retaddr
14187 ret;
14188 ENDPROC(__twofish_enc_blk_3way)
14189
14190@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14191 popq %r13;
14192 popq %r14;
14193 popq %r15;
14194+ pax_force_retaddr
14195 ret;
14196 ENDPROC(twofish_dec_blk_3way)
14197diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14198index a039d21..524b8b2 100644
14199--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14200+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14201@@ -22,6 +22,7 @@
14202
14203 #include <linux/linkage.h>
14204 #include <asm/asm-offsets.h>
14205+#include <asm/alternative-asm.h>
14206
14207 #define a_offset 0
14208 #define b_offset 4
14209@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14210
14211 popq R1
14212 movq $1,%rax
14213+ pax_force_retaddr
14214 ret
14215 ENDPROC(twofish_enc_blk)
14216
14217@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14218
14219 popq R1
14220 movq $1,%rax
14221+ pax_force_retaddr
14222 ret
14223 ENDPROC(twofish_dec_blk)
14224diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14225index d21ff89..6da8e6e 100644
14226--- a/arch/x86/ia32/ia32_aout.c
14227+++ b/arch/x86/ia32/ia32_aout.c
14228@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14229 unsigned long dump_start, dump_size;
14230 struct user32 dump;
14231
14232+ memset(&dump, 0, sizeof(dump));
14233+
14234 fs = get_fs();
14235 set_fs(KERNEL_DS);
14236 has_dumped = 1;
14237diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14238index 2206757..85cbcfa 100644
14239--- a/arch/x86/ia32/ia32_signal.c
14240+++ b/arch/x86/ia32/ia32_signal.c
14241@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14242 if (__get_user(set.sig[0], &frame->sc.oldmask)
14243 || (_COMPAT_NSIG_WORDS > 1
14244 && __copy_from_user((((char *) &set.sig) + 4),
14245- &frame->extramask,
14246+ frame->extramask,
14247 sizeof(frame->extramask))))
14248 goto badframe;
14249
14250@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14251 sp -= frame_size;
14252 /* Align the stack pointer according to the i386 ABI,
14253 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14254- sp = ((sp + 4) & -16ul) - 4;
14255+ sp = ((sp - 12) & -16ul) - 4;
14256 return (void __user *) sp;
14257 }
14258
14259@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14260 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14261 sigreturn);
14262 else
14263- restorer = &frame->retcode;
14264+ restorer = frame->retcode;
14265 }
14266
14267 put_user_try {
14268@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14269 * These are actually not used anymore, but left because some
14270 * gdb versions depend on them as a marker.
14271 */
14272- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14273+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14274 } put_user_catch(err);
14275
14276 if (err)
14277@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14278 0xb8,
14279 __NR_ia32_rt_sigreturn,
14280 0x80cd,
14281- 0,
14282+ 0
14283 };
14284
14285 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14286@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14287
14288 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14289 restorer = ksig->ka.sa.sa_restorer;
14290+ else if (current->mm->context.vdso)
14291+ /* Return stub is in 32bit vsyscall page */
14292+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14293 else
14294- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14295- rt_sigreturn);
14296+ restorer = frame->retcode;
14297 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14298
14299 /*
14300 * Not actually used anymore, but left because some gdb
14301 * versions need it.
14302 */
14303- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14304+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14305 } put_user_catch(err);
14306
14307 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14308diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14309index 4299eb0..c0687a7 100644
14310--- a/arch/x86/ia32/ia32entry.S
14311+++ b/arch/x86/ia32/ia32entry.S
14312@@ -15,8 +15,10 @@
14313 #include <asm/irqflags.h>
14314 #include <asm/asm.h>
14315 #include <asm/smap.h>
14316+#include <asm/pgtable.h>
14317 #include <linux/linkage.h>
14318 #include <linux/err.h>
14319+#include <asm/alternative-asm.h>
14320
14321 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14322 #include <linux/elf-em.h>
14323@@ -62,12 +64,12 @@
14324 */
14325 .macro LOAD_ARGS32 offset, _r9=0
14326 .if \_r9
14327- movl \offset+16(%rsp),%r9d
14328+ movl \offset+R9(%rsp),%r9d
14329 .endif
14330- movl \offset+40(%rsp),%ecx
14331- movl \offset+48(%rsp),%edx
14332- movl \offset+56(%rsp),%esi
14333- movl \offset+64(%rsp),%edi
14334+ movl \offset+RCX(%rsp),%ecx
14335+ movl \offset+RDX(%rsp),%edx
14336+ movl \offset+RSI(%rsp),%esi
14337+ movl \offset+RDI(%rsp),%edi
14338 movl %eax,%eax /* zero extension */
14339 .endm
14340
14341@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14342 ENDPROC(native_irq_enable_sysexit)
14343 #endif
14344
14345+ .macro pax_enter_kernel_user
14346+ pax_set_fptr_mask
14347+#ifdef CONFIG_PAX_MEMORY_UDEREF
14348+ call pax_enter_kernel_user
14349+#endif
14350+ .endm
14351+
14352+ .macro pax_exit_kernel_user
14353+#ifdef CONFIG_PAX_MEMORY_UDEREF
14354+ call pax_exit_kernel_user
14355+#endif
14356+#ifdef CONFIG_PAX_RANDKSTACK
14357+ pushq %rax
14358+ pushq %r11
14359+ call pax_randomize_kstack
14360+ popq %r11
14361+ popq %rax
14362+#endif
14363+ .endm
14364+
14365+ .macro pax_erase_kstack
14366+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14367+ call pax_erase_kstack
14368+#endif
14369+ .endm
14370+
14371 /*
14372 * 32bit SYSENTER instruction entry.
14373 *
14374@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14375 CFI_REGISTER rsp,rbp
14376 SWAPGS_UNSAFE_STACK
14377 movq PER_CPU_VAR(kernel_stack), %rsp
14378- addq $(KERNEL_STACK_OFFSET),%rsp
14379- /*
14380- * No need to follow this irqs on/off section: the syscall
14381- * disabled irqs, here we enable it straight after entry:
14382- */
14383- ENABLE_INTERRUPTS(CLBR_NONE)
14384 movl %ebp,%ebp /* zero extension */
14385 pushq_cfi $__USER32_DS
14386 /*CFI_REL_OFFSET ss,0*/
14387@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14388 CFI_REL_OFFSET rsp,0
14389 pushfq_cfi
14390 /*CFI_REL_OFFSET rflags,0*/
14391- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14392- CFI_REGISTER rip,r10
14393+ orl $X86_EFLAGS_IF,(%rsp)
14394+ GET_THREAD_INFO(%r11)
14395+ movl TI_sysenter_return(%r11), %r11d
14396+ CFI_REGISTER rip,r11
14397 pushq_cfi $__USER32_CS
14398 /*CFI_REL_OFFSET cs,0*/
14399 movl %eax, %eax
14400- pushq_cfi %r10
14401+ pushq_cfi %r11
14402 CFI_REL_OFFSET rip,0
14403 pushq_cfi %rax
14404 cld
14405 SAVE_ARGS 0,1,0
14406+ pax_enter_kernel_user
14407+
14408+#ifdef CONFIG_PAX_RANDKSTACK
14409+ pax_erase_kstack
14410+#endif
14411+
14412+ /*
14413+ * No need to follow this irqs on/off section: the syscall
14414+ * disabled irqs, here we enable it straight after entry:
14415+ */
14416+ ENABLE_INTERRUPTS(CLBR_NONE)
14417 /* no need to do an access_ok check here because rbp has been
14418 32bit zero extended */
14419+
14420+#ifdef CONFIG_PAX_MEMORY_UDEREF
14421+ addq pax_user_shadow_base,%rbp
14422+ ASM_PAX_OPEN_USERLAND
14423+#endif
14424+
14425 ASM_STAC
14426 1: movl (%rbp),%ebp
14427 _ASM_EXTABLE(1b,ia32_badarg)
14428 ASM_CLAC
14429- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14430- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14431+
14432+#ifdef CONFIG_PAX_MEMORY_UDEREF
14433+ ASM_PAX_CLOSE_USERLAND
14434+#endif
14435+
14436+ GET_THREAD_INFO(%r11)
14437+ orl $TS_COMPAT,TI_status(%r11)
14438+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14439 CFI_REMEMBER_STATE
14440 jnz sysenter_tracesys
14441 cmpq $(IA32_NR_syscalls-1),%rax
14442@@ -162,15 +209,18 @@ sysenter_do_call:
14443 sysenter_dispatch:
14444 call *ia32_sys_call_table(,%rax,8)
14445 movq %rax,RAX-ARGOFFSET(%rsp)
14446+ GET_THREAD_INFO(%r11)
14447 DISABLE_INTERRUPTS(CLBR_NONE)
14448 TRACE_IRQS_OFF
14449- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14450+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14451 jnz sysexit_audit
14452 sysexit_from_sys_call:
14453- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14454+ pax_exit_kernel_user
14455+ pax_erase_kstack
14456+ andl $~TS_COMPAT,TI_status(%r11)
14457 /* clear IF, that popfq doesn't enable interrupts early */
14458- andl $~0x200,EFLAGS-R11(%rsp)
14459- movl RIP-R11(%rsp),%edx /* User %eip */
14460+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14461+ movl RIP(%rsp),%edx /* User %eip */
14462 CFI_REGISTER rip,rdx
14463 RESTORE_ARGS 0,24,0,0,0,0
14464 xorq %r8,%r8
14465@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14466 movl %eax,%esi /* 2nd arg: syscall number */
14467 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14468 call __audit_syscall_entry
14469+
14470+ pax_erase_kstack
14471+
14472 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14473 cmpq $(IA32_NR_syscalls-1),%rax
14474 ja ia32_badsys
14475@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14476 .endm
14477
14478 .macro auditsys_exit exit
14479- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14480+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14481 jnz ia32_ret_from_sys_call
14482 TRACE_IRQS_ON
14483 ENABLE_INTERRUPTS(CLBR_NONE)
14484@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14485 1: setbe %al /* 1 if error, 0 if not */
14486 movzbl %al,%edi /* zero-extend that into %edi */
14487 call __audit_syscall_exit
14488+ GET_THREAD_INFO(%r11)
14489 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14490 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14491 DISABLE_INTERRUPTS(CLBR_NONE)
14492 TRACE_IRQS_OFF
14493- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14494+ testl %edi,TI_flags(%r11)
14495 jz \exit
14496 CLEAR_RREGS -ARGOFFSET
14497 jmp int_with_check
14498@@ -237,7 +291,7 @@ sysexit_audit:
14499
14500 sysenter_tracesys:
14501 #ifdef CONFIG_AUDITSYSCALL
14502- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14503+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14504 jz sysenter_auditsys
14505 #endif
14506 SAVE_REST
14507@@ -249,6 +303,9 @@ sysenter_tracesys:
14508 RESTORE_REST
14509 cmpq $(IA32_NR_syscalls-1),%rax
14510 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14511+
14512+ pax_erase_kstack
14513+
14514 jmp sysenter_do_call
14515 CFI_ENDPROC
14516 ENDPROC(ia32_sysenter_target)
14517@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14518 ENTRY(ia32_cstar_target)
14519 CFI_STARTPROC32 simple
14520 CFI_SIGNAL_FRAME
14521- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14522+ CFI_DEF_CFA rsp,0
14523 CFI_REGISTER rip,rcx
14524 /*CFI_REGISTER rflags,r11*/
14525 SWAPGS_UNSAFE_STACK
14526 movl %esp,%r8d
14527 CFI_REGISTER rsp,r8
14528 movq PER_CPU_VAR(kernel_stack),%rsp
14529+ SAVE_ARGS 8*6,0,0
14530+ pax_enter_kernel_user
14531+
14532+#ifdef CONFIG_PAX_RANDKSTACK
14533+ pax_erase_kstack
14534+#endif
14535+
14536 /*
14537 * No need to follow this irqs on/off section: the syscall
14538 * disabled irqs and here we enable it straight after entry:
14539 */
14540 ENABLE_INTERRUPTS(CLBR_NONE)
14541- SAVE_ARGS 8,0,0
14542 movl %eax,%eax /* zero extension */
14543 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14544 movq %rcx,RIP-ARGOFFSET(%rsp)
14545@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14546 /* no need to do an access_ok check here because r8 has been
14547 32bit zero extended */
14548 /* hardware stack frame is complete now */
14549+
14550+#ifdef CONFIG_PAX_MEMORY_UDEREF
14551+ ASM_PAX_OPEN_USERLAND
14552+ movq pax_user_shadow_base,%r8
14553+ addq RSP-ARGOFFSET(%rsp),%r8
14554+#endif
14555+
14556 ASM_STAC
14557 1: movl (%r8),%r9d
14558 _ASM_EXTABLE(1b,ia32_badarg)
14559 ASM_CLAC
14560- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14561- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14562+
14563+#ifdef CONFIG_PAX_MEMORY_UDEREF
14564+ ASM_PAX_CLOSE_USERLAND
14565+#endif
14566+
14567+ GET_THREAD_INFO(%r11)
14568+ orl $TS_COMPAT,TI_status(%r11)
14569+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14570 CFI_REMEMBER_STATE
14571 jnz cstar_tracesys
14572 cmpq $IA32_NR_syscalls-1,%rax
14573@@ -319,13 +395,16 @@ cstar_do_call:
14574 cstar_dispatch:
14575 call *ia32_sys_call_table(,%rax,8)
14576 movq %rax,RAX-ARGOFFSET(%rsp)
14577+ GET_THREAD_INFO(%r11)
14578 DISABLE_INTERRUPTS(CLBR_NONE)
14579 TRACE_IRQS_OFF
14580- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14581+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14582 jnz sysretl_audit
14583 sysretl_from_sys_call:
14584- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14585- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14586+ pax_exit_kernel_user
14587+ pax_erase_kstack
14588+ andl $~TS_COMPAT,TI_status(%r11)
14589+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14590 movl RIP-ARGOFFSET(%rsp),%ecx
14591 CFI_REGISTER rip,rcx
14592 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14593@@ -352,7 +431,7 @@ sysretl_audit:
14594
14595 cstar_tracesys:
14596 #ifdef CONFIG_AUDITSYSCALL
14597- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14598+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14599 jz cstar_auditsys
14600 #endif
14601 xchgl %r9d,%ebp
14602@@ -366,11 +445,19 @@ cstar_tracesys:
14603 xchgl %ebp,%r9d
14604 cmpq $(IA32_NR_syscalls-1),%rax
14605 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14606+
14607+ pax_erase_kstack
14608+
14609 jmp cstar_do_call
14610 END(ia32_cstar_target)
14611
14612 ia32_badarg:
14613 ASM_CLAC
14614+
14615+#ifdef CONFIG_PAX_MEMORY_UDEREF
14616+ ASM_PAX_CLOSE_USERLAND
14617+#endif
14618+
14619 movq $-EFAULT,%rax
14620 jmp ia32_sysret
14621 CFI_ENDPROC
14622@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14623 CFI_REL_OFFSET rip,RIP-RIP
14624 PARAVIRT_ADJUST_EXCEPTION_FRAME
14625 SWAPGS
14626- /*
14627- * No need to follow this irqs on/off section: the syscall
14628- * disabled irqs and here we enable it straight after entry:
14629- */
14630- ENABLE_INTERRUPTS(CLBR_NONE)
14631 movl %eax,%eax
14632 pushq_cfi %rax
14633 cld
14634 /* note the registers are not zero extended to the sf.
14635 this could be a problem. */
14636 SAVE_ARGS 0,1,0
14637- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14638- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14639+ pax_enter_kernel_user
14640+
14641+#ifdef CONFIG_PAX_RANDKSTACK
14642+ pax_erase_kstack
14643+#endif
14644+
14645+ /*
14646+ * No need to follow this irqs on/off section: the syscall
14647+ * disabled irqs and here we enable it straight after entry:
14648+ */
14649+ ENABLE_INTERRUPTS(CLBR_NONE)
14650+ GET_THREAD_INFO(%r11)
14651+ orl $TS_COMPAT,TI_status(%r11)
14652+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14653 jnz ia32_tracesys
14654 cmpq $(IA32_NR_syscalls-1),%rax
14655 ja ia32_badsys
14656@@ -442,6 +536,9 @@ ia32_tracesys:
14657 RESTORE_REST
14658 cmpq $(IA32_NR_syscalls-1),%rax
14659 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14660+
14661+ pax_erase_kstack
14662+
14663 jmp ia32_do_call
14664 END(ia32_syscall)
14665
14666diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14667index 8e0ceec..af13504 100644
14668--- a/arch/x86/ia32/sys_ia32.c
14669+++ b/arch/x86/ia32/sys_ia32.c
14670@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14671 */
14672 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14673 {
14674- typeof(ubuf->st_uid) uid = 0;
14675- typeof(ubuf->st_gid) gid = 0;
14676+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14677+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14678 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14679 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14680 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14681diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14682index 372231c..51b537d 100644
14683--- a/arch/x86/include/asm/alternative-asm.h
14684+++ b/arch/x86/include/asm/alternative-asm.h
14685@@ -18,6 +18,45 @@
14686 .endm
14687 #endif
14688
14689+#ifdef KERNEXEC_PLUGIN
14690+ .macro pax_force_retaddr_bts rip=0
14691+ btsq $63,\rip(%rsp)
14692+ .endm
14693+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14694+ .macro pax_force_retaddr rip=0, reload=0
14695+ btsq $63,\rip(%rsp)
14696+ .endm
14697+ .macro pax_force_fptr ptr
14698+ btsq $63,\ptr
14699+ .endm
14700+ .macro pax_set_fptr_mask
14701+ .endm
14702+#endif
14703+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14704+ .macro pax_force_retaddr rip=0, reload=0
14705+ .if \reload
14706+ pax_set_fptr_mask
14707+ .endif
14708+ orq %r12,\rip(%rsp)
14709+ .endm
14710+ .macro pax_force_fptr ptr
14711+ orq %r12,\ptr
14712+ .endm
14713+ .macro pax_set_fptr_mask
14714+ movabs $0x8000000000000000,%r12
14715+ .endm
14716+#endif
14717+#else
14718+ .macro pax_force_retaddr rip=0, reload=0
14719+ .endm
14720+ .macro pax_force_fptr ptr
14721+ .endm
14722+ .macro pax_force_retaddr_bts rip=0
14723+ .endm
14724+ .macro pax_set_fptr_mask
14725+ .endm
14726+#endif
14727+
14728 .macro altinstruction_entry orig alt feature orig_len alt_len
14729 .long \orig - .
14730 .long \alt - .
14731diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14732index 0a3f9c9..c9d081d 100644
14733--- a/arch/x86/include/asm/alternative.h
14734+++ b/arch/x86/include/asm/alternative.h
14735@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14736 ".pushsection .discard,\"aw\",@progbits\n" \
14737 DISCARD_ENTRY(1) \
14738 ".popsection\n" \
14739- ".pushsection .altinstr_replacement, \"ax\"\n" \
14740+ ".pushsection .altinstr_replacement, \"a\"\n" \
14741 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14742 ".popsection"
14743
14744@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14745 DISCARD_ENTRY(1) \
14746 DISCARD_ENTRY(2) \
14747 ".popsection\n" \
14748- ".pushsection .altinstr_replacement, \"ax\"\n" \
14749+ ".pushsection .altinstr_replacement, \"a\"\n" \
14750 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14751 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14752 ".popsection"
14753diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14754index 1d2091a..f5074c1 100644
14755--- a/arch/x86/include/asm/apic.h
14756+++ b/arch/x86/include/asm/apic.h
14757@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14758
14759 #ifdef CONFIG_X86_LOCAL_APIC
14760
14761-extern unsigned int apic_verbosity;
14762+extern int apic_verbosity;
14763 extern int local_apic_timer_c2_ok;
14764
14765 extern int disable_apic;
14766diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14767index 20370c6..a2eb9b0 100644
14768--- a/arch/x86/include/asm/apm.h
14769+++ b/arch/x86/include/asm/apm.h
14770@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14771 __asm__ __volatile__(APM_DO_ZERO_SEGS
14772 "pushl %%edi\n\t"
14773 "pushl %%ebp\n\t"
14774- "lcall *%%cs:apm_bios_entry\n\t"
14775+ "lcall *%%ss:apm_bios_entry\n\t"
14776 "setc %%al\n\t"
14777 "popl %%ebp\n\t"
14778 "popl %%edi\n\t"
14779@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14780 __asm__ __volatile__(APM_DO_ZERO_SEGS
14781 "pushl %%edi\n\t"
14782 "pushl %%ebp\n\t"
14783- "lcall *%%cs:apm_bios_entry\n\t"
14784+ "lcall *%%ss:apm_bios_entry\n\t"
14785 "setc %%bl\n\t"
14786 "popl %%ebp\n\t"
14787 "popl %%edi\n\t"
14788diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14789index b17f4f4..9620151 100644
14790--- a/arch/x86/include/asm/atomic.h
14791+++ b/arch/x86/include/asm/atomic.h
14792@@ -23,7 +23,18 @@
14793 */
14794 static inline int atomic_read(const atomic_t *v)
14795 {
14796- return (*(volatile int *)&(v)->counter);
14797+ return (*(volatile const int *)&(v)->counter);
14798+}
14799+
14800+/**
14801+ * atomic_read_unchecked - read atomic variable
14802+ * @v: pointer of type atomic_unchecked_t
14803+ *
14804+ * Atomically reads the value of @v.
14805+ */
14806+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14807+{
14808+ return (*(volatile const int *)&(v)->counter);
14809 }
14810
14811 /**
14812@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14813 }
14814
14815 /**
14816+ * atomic_set_unchecked - set atomic variable
14817+ * @v: pointer of type atomic_unchecked_t
14818+ * @i: required value
14819+ *
14820+ * Atomically sets the value of @v to @i.
14821+ */
14822+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14823+{
14824+ v->counter = i;
14825+}
14826+
14827+/**
14828 * atomic_add - add integer to atomic variable
14829 * @i: integer value to add
14830 * @v: pointer of type atomic_t
14831@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14832 */
14833 static inline void atomic_add(int i, atomic_t *v)
14834 {
14835- asm volatile(LOCK_PREFIX "addl %1,%0"
14836+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14837+
14838+#ifdef CONFIG_PAX_REFCOUNT
14839+ "jno 0f\n"
14840+ LOCK_PREFIX "subl %1,%0\n"
14841+ "int $4\n0:\n"
14842+ _ASM_EXTABLE(0b, 0b)
14843+#endif
14844+
14845+ : "+m" (v->counter)
14846+ : "ir" (i));
14847+}
14848+
14849+/**
14850+ * atomic_add_unchecked - add integer to atomic variable
14851+ * @i: integer value to add
14852+ * @v: pointer of type atomic_unchecked_t
14853+ *
14854+ * Atomically adds @i to @v.
14855+ */
14856+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14857+{
14858+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14859 : "+m" (v->counter)
14860 : "ir" (i));
14861 }
14862@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14863 */
14864 static inline void atomic_sub(int i, atomic_t *v)
14865 {
14866- asm volatile(LOCK_PREFIX "subl %1,%0"
14867+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14868+
14869+#ifdef CONFIG_PAX_REFCOUNT
14870+ "jno 0f\n"
14871+ LOCK_PREFIX "addl %1,%0\n"
14872+ "int $4\n0:\n"
14873+ _ASM_EXTABLE(0b, 0b)
14874+#endif
14875+
14876+ : "+m" (v->counter)
14877+ : "ir" (i));
14878+}
14879+
14880+/**
14881+ * atomic_sub_unchecked - subtract integer from atomic variable
14882+ * @i: integer value to subtract
14883+ * @v: pointer of type atomic_unchecked_t
14884+ *
14885+ * Atomically subtracts @i from @v.
14886+ */
14887+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14888+{
14889+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14890 : "+m" (v->counter)
14891 : "ir" (i));
14892 }
14893@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14894 */
14895 static inline int atomic_sub_and_test(int i, atomic_t *v)
14896 {
14897- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14898+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14899 }
14900
14901 /**
14902@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14903 */
14904 static inline void atomic_inc(atomic_t *v)
14905 {
14906- asm volatile(LOCK_PREFIX "incl %0"
14907+ asm volatile(LOCK_PREFIX "incl %0\n"
14908+
14909+#ifdef CONFIG_PAX_REFCOUNT
14910+ "jno 0f\n"
14911+ LOCK_PREFIX "decl %0\n"
14912+ "int $4\n0:\n"
14913+ _ASM_EXTABLE(0b, 0b)
14914+#endif
14915+
14916+ : "+m" (v->counter));
14917+}
14918+
14919+/**
14920+ * atomic_inc_unchecked - increment atomic variable
14921+ * @v: pointer of type atomic_unchecked_t
14922+ *
14923+ * Atomically increments @v by 1.
14924+ */
14925+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14926+{
14927+ asm volatile(LOCK_PREFIX "incl %0\n"
14928 : "+m" (v->counter));
14929 }
14930
14931@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14932 */
14933 static inline void atomic_dec(atomic_t *v)
14934 {
14935- asm volatile(LOCK_PREFIX "decl %0"
14936+ asm volatile(LOCK_PREFIX "decl %0\n"
14937+
14938+#ifdef CONFIG_PAX_REFCOUNT
14939+ "jno 0f\n"
14940+ LOCK_PREFIX "incl %0\n"
14941+ "int $4\n0:\n"
14942+ _ASM_EXTABLE(0b, 0b)
14943+#endif
14944+
14945+ : "+m" (v->counter));
14946+}
14947+
14948+/**
14949+ * atomic_dec_unchecked - decrement atomic variable
14950+ * @v: pointer of type atomic_unchecked_t
14951+ *
14952+ * Atomically decrements @v by 1.
14953+ */
14954+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14955+{
14956+ asm volatile(LOCK_PREFIX "decl %0\n"
14957 : "+m" (v->counter));
14958 }
14959
14960@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14961 */
14962 static inline int atomic_dec_and_test(atomic_t *v)
14963 {
14964- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14965+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14966 }
14967
14968 /**
14969@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14970 */
14971 static inline int atomic_inc_and_test(atomic_t *v)
14972 {
14973- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14974+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14975+}
14976+
14977+/**
14978+ * atomic_inc_and_test_unchecked - increment and test
14979+ * @v: pointer of type atomic_unchecked_t
14980+ *
14981+ * Atomically increments @v by 1
14982+ * and returns true if the result is zero, or false for all
14983+ * other cases.
14984+ */
14985+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14986+{
14987+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14988 }
14989
14990 /**
14991@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14992 */
14993 static inline int atomic_add_negative(int i, atomic_t *v)
14994 {
14995- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14996+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14997 }
14998
14999 /**
15000@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15001 */
15002 static inline int atomic_add_return(int i, atomic_t *v)
15003 {
15004+ return i + xadd_check_overflow(&v->counter, i);
15005+}
15006+
15007+/**
15008+ * atomic_add_return_unchecked - add integer and return
15009+ * @i: integer value to add
15010+ * @v: pointer of type atomic_unchecked_t
15011+ *
15012+ * Atomically adds @i to @v and returns @i + @v
15013+ */
15014+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15015+{
15016 return i + xadd(&v->counter, i);
15017 }
15018
15019@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15020 }
15021
15022 #define atomic_inc_return(v) (atomic_add_return(1, v))
15023+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15024+{
15025+ return atomic_add_return_unchecked(1, v);
15026+}
15027 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15028
15029-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15030+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15031+{
15032+ return cmpxchg(&v->counter, old, new);
15033+}
15034+
15035+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15036 {
15037 return cmpxchg(&v->counter, old, new);
15038 }
15039@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15040 return xchg(&v->counter, new);
15041 }
15042
15043+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15044+{
15045+ return xchg(&v->counter, new);
15046+}
15047+
15048 /**
15049 * __atomic_add_unless - add unless the number is already a given value
15050 * @v: pointer of type atomic_t
15051@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15052 * Atomically adds @a to @v, so long as @v was not already @u.
15053 * Returns the old value of @v.
15054 */
15055-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15056+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15057 {
15058- int c, old;
15059+ int c, old, new;
15060 c = atomic_read(v);
15061 for (;;) {
15062- if (unlikely(c == (u)))
15063+ if (unlikely(c == u))
15064 break;
15065- old = atomic_cmpxchg((v), c, c + (a));
15066+
15067+ asm volatile("addl %2,%0\n"
15068+
15069+#ifdef CONFIG_PAX_REFCOUNT
15070+ "jno 0f\n"
15071+ "subl %2,%0\n"
15072+ "int $4\n0:\n"
15073+ _ASM_EXTABLE(0b, 0b)
15074+#endif
15075+
15076+ : "=r" (new)
15077+ : "0" (c), "ir" (a));
15078+
15079+ old = atomic_cmpxchg(v, c, new);
15080 if (likely(old == c))
15081 break;
15082 c = old;
15083@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15084 }
15085
15086 /**
15087+ * atomic_inc_not_zero_hint - increment if not null
15088+ * @v: pointer of type atomic_t
15089+ * @hint: probable value of the atomic before the increment
15090+ *
15091+ * This version of atomic_inc_not_zero() gives a hint of probable
15092+ * value of the atomic. This helps processor to not read the memory
15093+ * before doing the atomic read/modify/write cycle, lowering
15094+ * number of bus transactions on some arches.
15095+ *
15096+ * Returns: 0 if increment was not done, 1 otherwise.
15097+ */
15098+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15099+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15100+{
15101+ int val, c = hint, new;
15102+
15103+ /* sanity test, should be removed by compiler if hint is a constant */
15104+ if (!hint)
15105+ return __atomic_add_unless(v, 1, 0);
15106+
15107+ do {
15108+ asm volatile("incl %0\n"
15109+
15110+#ifdef CONFIG_PAX_REFCOUNT
15111+ "jno 0f\n"
15112+ "decl %0\n"
15113+ "int $4\n0:\n"
15114+ _ASM_EXTABLE(0b, 0b)
15115+#endif
15116+
15117+ : "=r" (new)
15118+ : "0" (c));
15119+
15120+ val = atomic_cmpxchg(v, c, new);
15121+ if (val == c)
15122+ return 1;
15123+ c = val;
15124+ } while (c);
15125+
15126+ return 0;
15127+}
15128+
15129+/**
15130 * atomic_inc_short - increment of a short integer
15131 * @v: pointer to type int
15132 *
15133@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15134 #endif
15135
15136 /* These are x86-specific, used by some header files */
15137-#define atomic_clear_mask(mask, addr) \
15138- asm volatile(LOCK_PREFIX "andl %0,%1" \
15139- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15140+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15141+{
15142+ asm volatile(LOCK_PREFIX "andl %1,%0"
15143+ : "+m" (v->counter)
15144+ : "r" (~(mask))
15145+ : "memory");
15146+}
15147
15148-#define atomic_set_mask(mask, addr) \
15149- asm volatile(LOCK_PREFIX "orl %0,%1" \
15150- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15151- : "memory")
15152+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15153+{
15154+ asm volatile(LOCK_PREFIX "andl %1,%0"
15155+ : "+m" (v->counter)
15156+ : "r" (~(mask))
15157+ : "memory");
15158+}
15159+
15160+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15161+{
15162+ asm volatile(LOCK_PREFIX "orl %1,%0"
15163+ : "+m" (v->counter)
15164+ : "r" (mask)
15165+ : "memory");
15166+}
15167+
15168+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15169+{
15170+ asm volatile(LOCK_PREFIX "orl %1,%0"
15171+ : "+m" (v->counter)
15172+ : "r" (mask)
15173+ : "memory");
15174+}
15175
15176 /* Atomic operations are already serializing on x86 */
15177 #define smp_mb__before_atomic_dec() barrier()
15178diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15179index b154de7..bf18a5a 100644
15180--- a/arch/x86/include/asm/atomic64_32.h
15181+++ b/arch/x86/include/asm/atomic64_32.h
15182@@ -12,6 +12,14 @@ typedef struct {
15183 u64 __aligned(8) counter;
15184 } atomic64_t;
15185
15186+#ifdef CONFIG_PAX_REFCOUNT
15187+typedef struct {
15188+ u64 __aligned(8) counter;
15189+} atomic64_unchecked_t;
15190+#else
15191+typedef atomic64_t atomic64_unchecked_t;
15192+#endif
15193+
15194 #define ATOMIC64_INIT(val) { (val) }
15195
15196 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15197@@ -37,21 +45,31 @@ typedef struct {
15198 ATOMIC64_DECL_ONE(sym##_386)
15199
15200 ATOMIC64_DECL_ONE(add_386);
15201+ATOMIC64_DECL_ONE(add_unchecked_386);
15202 ATOMIC64_DECL_ONE(sub_386);
15203+ATOMIC64_DECL_ONE(sub_unchecked_386);
15204 ATOMIC64_DECL_ONE(inc_386);
15205+ATOMIC64_DECL_ONE(inc_unchecked_386);
15206 ATOMIC64_DECL_ONE(dec_386);
15207+ATOMIC64_DECL_ONE(dec_unchecked_386);
15208 #endif
15209
15210 #define alternative_atomic64(f, out, in...) \
15211 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15212
15213 ATOMIC64_DECL(read);
15214+ATOMIC64_DECL(read_unchecked);
15215 ATOMIC64_DECL(set);
15216+ATOMIC64_DECL(set_unchecked);
15217 ATOMIC64_DECL(xchg);
15218 ATOMIC64_DECL(add_return);
15219+ATOMIC64_DECL(add_return_unchecked);
15220 ATOMIC64_DECL(sub_return);
15221+ATOMIC64_DECL(sub_return_unchecked);
15222 ATOMIC64_DECL(inc_return);
15223+ATOMIC64_DECL(inc_return_unchecked);
15224 ATOMIC64_DECL(dec_return);
15225+ATOMIC64_DECL(dec_return_unchecked);
15226 ATOMIC64_DECL(dec_if_positive);
15227 ATOMIC64_DECL(inc_not_zero);
15228 ATOMIC64_DECL(add_unless);
15229@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15230 }
15231
15232 /**
15233+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15234+ * @p: pointer to type atomic64_unchecked_t
15235+ * @o: expected value
15236+ * @n: new value
15237+ *
15238+ * Atomically sets @v to @n if it was equal to @o and returns
15239+ * the old value.
15240+ */
15241+
15242+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15243+{
15244+ return cmpxchg64(&v->counter, o, n);
15245+}
15246+
15247+/**
15248 * atomic64_xchg - xchg atomic64 variable
15249 * @v: pointer to type atomic64_t
15250 * @n: value to assign
15251@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15252 }
15253
15254 /**
15255+ * atomic64_set_unchecked - set atomic64 variable
15256+ * @v: pointer to type atomic64_unchecked_t
15257+ * @n: value to assign
15258+ *
15259+ * Atomically sets the value of @v to @n.
15260+ */
15261+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15262+{
15263+ unsigned high = (unsigned)(i >> 32);
15264+ unsigned low = (unsigned)i;
15265+ alternative_atomic64(set, /* no output */,
15266+ "S" (v), "b" (low), "c" (high)
15267+ : "eax", "edx", "memory");
15268+}
15269+
15270+/**
15271 * atomic64_read - read atomic64 variable
15272 * @v: pointer to type atomic64_t
15273 *
15274@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15275 }
15276
15277 /**
15278+ * atomic64_read_unchecked - read atomic64 variable
15279+ * @v: pointer to type atomic64_unchecked_t
15280+ *
15281+ * Atomically reads the value of @v and returns it.
15282+ */
15283+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15284+{
15285+ long long r;
15286+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15287+ return r;
15288+ }
15289+
15290+/**
15291 * atomic64_add_return - add and return
15292 * @i: integer value to add
15293 * @v: pointer to type atomic64_t
15294@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15295 return i;
15296 }
15297
15298+/**
15299+ * atomic64_add_return_unchecked - add and return
15300+ * @i: integer value to add
15301+ * @v: pointer to type atomic64_unchecked_t
15302+ *
15303+ * Atomically adds @i to @v and returns @i + *@v
15304+ */
15305+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15306+{
15307+ alternative_atomic64(add_return_unchecked,
15308+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15309+ ASM_NO_INPUT_CLOBBER("memory"));
15310+ return i;
15311+}
15312+
15313 /*
15314 * Other variants with different arithmetic operators:
15315 */
15316@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15317 return a;
15318 }
15319
15320+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15321+{
15322+ long long a;
15323+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15324+ "S" (v) : "memory", "ecx");
15325+ return a;
15326+}
15327+
15328 static inline long long atomic64_dec_return(atomic64_t *v)
15329 {
15330 long long a;
15331@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15332 }
15333
15334 /**
15335+ * atomic64_add_unchecked - add integer to atomic64 variable
15336+ * @i: integer value to add
15337+ * @v: pointer to type atomic64_unchecked_t
15338+ *
15339+ * Atomically adds @i to @v.
15340+ */
15341+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15342+{
15343+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15344+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15345+ ASM_NO_INPUT_CLOBBER("memory"));
15346+ return i;
15347+}
15348+
15349+/**
15350 * atomic64_sub - subtract the atomic64 variable
15351 * @i: integer value to subtract
15352 * @v: pointer to type atomic64_t
15353diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15354index 46e9052..ae45136 100644
15355--- a/arch/x86/include/asm/atomic64_64.h
15356+++ b/arch/x86/include/asm/atomic64_64.h
15357@@ -18,7 +18,19 @@
15358 */
15359 static inline long atomic64_read(const atomic64_t *v)
15360 {
15361- return (*(volatile long *)&(v)->counter);
15362+ return (*(volatile const long *)&(v)->counter);
15363+}
15364+
15365+/**
15366+ * atomic64_read_unchecked - read atomic64 variable
15367+ * @v: pointer of type atomic64_unchecked_t
15368+ *
15369+ * Atomically reads the value of @v.
15370+ * Doesn't imply a read memory barrier.
15371+ */
15372+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15373+{
15374+ return (*(volatile const long *)&(v)->counter);
15375 }
15376
15377 /**
15378@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15379 }
15380
15381 /**
15382+ * atomic64_set_unchecked - set atomic64 variable
15383+ * @v: pointer to type atomic64_unchecked_t
15384+ * @i: required value
15385+ *
15386+ * Atomically sets the value of @v to @i.
15387+ */
15388+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15389+{
15390+ v->counter = i;
15391+}
15392+
15393+/**
15394 * atomic64_add - add integer to atomic64 variable
15395 * @i: integer value to add
15396 * @v: pointer to type atomic64_t
15397@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15398 */
15399 static inline void atomic64_add(long i, atomic64_t *v)
15400 {
15401+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15402+
15403+#ifdef CONFIG_PAX_REFCOUNT
15404+ "jno 0f\n"
15405+ LOCK_PREFIX "subq %1,%0\n"
15406+ "int $4\n0:\n"
15407+ _ASM_EXTABLE(0b, 0b)
15408+#endif
15409+
15410+ : "=m" (v->counter)
15411+ : "er" (i), "m" (v->counter));
15412+}
15413+
15414+/**
15415+ * atomic64_add_unchecked - add integer to atomic64 variable
15416+ * @i: integer value to add
15417+ * @v: pointer to type atomic64_unchecked_t
15418+ *
15419+ * Atomically adds @i to @v.
15420+ */
15421+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15422+{
15423 asm volatile(LOCK_PREFIX "addq %1,%0"
15424 : "=m" (v->counter)
15425 : "er" (i), "m" (v->counter));
15426@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15427 */
15428 static inline void atomic64_sub(long i, atomic64_t *v)
15429 {
15430- asm volatile(LOCK_PREFIX "subq %1,%0"
15431+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15432+
15433+#ifdef CONFIG_PAX_REFCOUNT
15434+ "jno 0f\n"
15435+ LOCK_PREFIX "addq %1,%0\n"
15436+ "int $4\n0:\n"
15437+ _ASM_EXTABLE(0b, 0b)
15438+#endif
15439+
15440+ : "=m" (v->counter)
15441+ : "er" (i), "m" (v->counter));
15442+}
15443+
15444+/**
15445+ * atomic64_sub_unchecked - subtract the atomic64 variable
15446+ * @i: integer value to subtract
15447+ * @v: pointer to type atomic64_unchecked_t
15448+ *
15449+ * Atomically subtracts @i from @v.
15450+ */
15451+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15452+{
15453+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15454 : "=m" (v->counter)
15455 : "er" (i), "m" (v->counter));
15456 }
15457@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15458 */
15459 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15460 {
15461- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15462+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15463 }
15464
15465 /**
15466@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15467 */
15468 static inline void atomic64_inc(atomic64_t *v)
15469 {
15470+ asm volatile(LOCK_PREFIX "incq %0\n"
15471+
15472+#ifdef CONFIG_PAX_REFCOUNT
15473+ "jno 0f\n"
15474+ LOCK_PREFIX "decq %0\n"
15475+ "int $4\n0:\n"
15476+ _ASM_EXTABLE(0b, 0b)
15477+#endif
15478+
15479+ : "=m" (v->counter)
15480+ : "m" (v->counter));
15481+}
15482+
15483+/**
15484+ * atomic64_inc_unchecked - increment atomic64 variable
15485+ * @v: pointer to type atomic64_unchecked_t
15486+ *
15487+ * Atomically increments @v by 1.
15488+ */
15489+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15490+{
15491 asm volatile(LOCK_PREFIX "incq %0"
15492 : "=m" (v->counter)
15493 : "m" (v->counter));
15494@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15495 */
15496 static inline void atomic64_dec(atomic64_t *v)
15497 {
15498- asm volatile(LOCK_PREFIX "decq %0"
15499+ asm volatile(LOCK_PREFIX "decq %0\n"
15500+
15501+#ifdef CONFIG_PAX_REFCOUNT
15502+ "jno 0f\n"
15503+ LOCK_PREFIX "incq %0\n"
15504+ "int $4\n0:\n"
15505+ _ASM_EXTABLE(0b, 0b)
15506+#endif
15507+
15508+ : "=m" (v->counter)
15509+ : "m" (v->counter));
15510+}
15511+
15512+/**
15513+ * atomic64_dec_unchecked - decrement atomic64 variable
15514+ * @v: pointer to type atomic64_t
15515+ *
15516+ * Atomically decrements @v by 1.
15517+ */
15518+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15519+{
15520+ asm volatile(LOCK_PREFIX "decq %0\n"
15521 : "=m" (v->counter)
15522 : "m" (v->counter));
15523 }
15524@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15525 */
15526 static inline int atomic64_dec_and_test(atomic64_t *v)
15527 {
15528- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15529+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15530 }
15531
15532 /**
15533@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15534 */
15535 static inline int atomic64_inc_and_test(atomic64_t *v)
15536 {
15537- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15538+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15539 }
15540
15541 /**
15542@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15543 */
15544 static inline int atomic64_add_negative(long i, atomic64_t *v)
15545 {
15546- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15547+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15548 }
15549
15550 /**
15551@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15552 */
15553 static inline long atomic64_add_return(long i, atomic64_t *v)
15554 {
15555+ return i + xadd_check_overflow(&v->counter, i);
15556+}
15557+
15558+/**
15559+ * atomic64_add_return_unchecked - add and return
15560+ * @i: integer value to add
15561+ * @v: pointer to type atomic64_unchecked_t
15562+ *
15563+ * Atomically adds @i to @v and returns @i + @v
15564+ */
15565+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15566+{
15567 return i + xadd(&v->counter, i);
15568 }
15569
15570@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15571 }
15572
15573 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15574+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15575+{
15576+ return atomic64_add_return_unchecked(1, v);
15577+}
15578 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15579
15580 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15581@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15582 return cmpxchg(&v->counter, old, new);
15583 }
15584
15585+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15586+{
15587+ return cmpxchg(&v->counter, old, new);
15588+}
15589+
15590 static inline long atomic64_xchg(atomic64_t *v, long new)
15591 {
15592 return xchg(&v->counter, new);
15593@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15594 */
15595 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15596 {
15597- long c, old;
15598+ long c, old, new;
15599 c = atomic64_read(v);
15600 for (;;) {
15601- if (unlikely(c == (u)))
15602+ if (unlikely(c == u))
15603 break;
15604- old = atomic64_cmpxchg((v), c, c + (a));
15605+
15606+ asm volatile("add %2,%0\n"
15607+
15608+#ifdef CONFIG_PAX_REFCOUNT
15609+ "jno 0f\n"
15610+ "sub %2,%0\n"
15611+ "int $4\n0:\n"
15612+ _ASM_EXTABLE(0b, 0b)
15613+#endif
15614+
15615+ : "=r" (new)
15616+ : "0" (c), "ir" (a));
15617+
15618+ old = atomic64_cmpxchg(v, c, new);
15619 if (likely(old == c))
15620 break;
15621 c = old;
15622 }
15623- return c != (u);
15624+ return c != u;
15625 }
15626
15627 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15628diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15629index 9fc1af7..fc71228 100644
15630--- a/arch/x86/include/asm/bitops.h
15631+++ b/arch/x86/include/asm/bitops.h
15632@@ -49,7 +49,7 @@
15633 * a mask operation on a byte.
15634 */
15635 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15636-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15637+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15638 #define CONST_MASK(nr) (1 << ((nr) & 7))
15639
15640 /**
15641@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15642 */
15643 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15644 {
15645- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15646+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15647 }
15648
15649 /**
15650@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15651 */
15652 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15653 {
15654- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15655+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15656 }
15657
15658 /**
15659@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15660 */
15661 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15662 {
15663- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15664+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15665 }
15666
15667 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15668@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15669 *
15670 * Undefined if no bit exists, so code should check against 0 first.
15671 */
15672-static inline unsigned long __ffs(unsigned long word)
15673+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15674 {
15675 asm("rep; bsf %1,%0"
15676 : "=r" (word)
15677@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15678 *
15679 * Undefined if no zero exists, so code should check against ~0UL first.
15680 */
15681-static inline unsigned long ffz(unsigned long word)
15682+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15683 {
15684 asm("rep; bsf %1,%0"
15685 : "=r" (word)
15686@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15687 *
15688 * Undefined if no set bit exists, so code should check against 0 first.
15689 */
15690-static inline unsigned long __fls(unsigned long word)
15691+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15692 {
15693 asm("bsr %1,%0"
15694 : "=r" (word)
15695@@ -436,7 +436,7 @@ static inline int ffs(int x)
15696 * set bit if value is nonzero. The last (most significant) bit is
15697 * at position 32.
15698 */
15699-static inline int fls(int x)
15700+static inline int __intentional_overflow(-1) fls(int x)
15701 {
15702 int r;
15703
15704@@ -478,7 +478,7 @@ static inline int fls(int x)
15705 * at position 64.
15706 */
15707 #ifdef CONFIG_X86_64
15708-static __always_inline int fls64(__u64 x)
15709+static __always_inline long fls64(__u64 x)
15710 {
15711 int bitpos = -1;
15712 /*
15713diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15714index 4fa687a..60f2d39 100644
15715--- a/arch/x86/include/asm/boot.h
15716+++ b/arch/x86/include/asm/boot.h
15717@@ -6,10 +6,15 @@
15718 #include <uapi/asm/boot.h>
15719
15720 /* Physical address where kernel should be loaded. */
15721-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15722+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15723 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15724 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15725
15726+#ifndef __ASSEMBLY__
15727+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15728+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15729+#endif
15730+
15731 /* Minimum kernel alignment, as a power of two */
15732 #ifdef CONFIG_X86_64
15733 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15734diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15735index 48f99f1..d78ebf9 100644
15736--- a/arch/x86/include/asm/cache.h
15737+++ b/arch/x86/include/asm/cache.h
15738@@ -5,12 +5,13 @@
15739
15740 /* L1 cache line size */
15741 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15742-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15743+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15744
15745 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15746+#define __read_only __attribute__((__section__(".data..read_only")))
15747
15748 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15749-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15750+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15751
15752 #ifdef CONFIG_X86_VSMP
15753 #ifdef CONFIG_SMP
15754diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15755index 9863ee3..4a1f8e1 100644
15756--- a/arch/x86/include/asm/cacheflush.h
15757+++ b/arch/x86/include/asm/cacheflush.h
15758@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15759 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15760
15761 if (pg_flags == _PGMT_DEFAULT)
15762- return -1;
15763+ return ~0UL;
15764 else if (pg_flags == _PGMT_WC)
15765 return _PAGE_CACHE_WC;
15766 else if (pg_flags == _PGMT_UC_MINUS)
15767diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15768index cb4c73b..c473c29 100644
15769--- a/arch/x86/include/asm/calling.h
15770+++ b/arch/x86/include/asm/calling.h
15771@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15772 #define RSP 152
15773 #define SS 160
15774
15775-#define ARGOFFSET R11
15776-#define SWFRAME ORIG_RAX
15777+#define ARGOFFSET R15
15778
15779 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15780- subq $9*8+\addskip, %rsp
15781- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15782- movq_cfi rdi, 8*8
15783- movq_cfi rsi, 7*8
15784- movq_cfi rdx, 6*8
15785+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15786+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15787+ movq_cfi rdi, RDI
15788+ movq_cfi rsi, RSI
15789+ movq_cfi rdx, RDX
15790
15791 .if \save_rcx
15792- movq_cfi rcx, 5*8
15793+ movq_cfi rcx, RCX
15794 .endif
15795
15796- movq_cfi rax, 4*8
15797+ movq_cfi rax, RAX
15798
15799 .if \save_r891011
15800- movq_cfi r8, 3*8
15801- movq_cfi r9, 2*8
15802- movq_cfi r10, 1*8
15803- movq_cfi r11, 0*8
15804+ movq_cfi r8, R8
15805+ movq_cfi r9, R9
15806+ movq_cfi r10, R10
15807+ movq_cfi r11, R11
15808 .endif
15809
15810+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15811+ movq_cfi r12, R12
15812+#endif
15813+
15814 .endm
15815
15816-#define ARG_SKIP (9*8)
15817+#define ARG_SKIP ORIG_RAX
15818
15819 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15820 rstor_r8910=1, rstor_rdx=1
15821+
15822+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15823+ movq_cfi_restore R12, r12
15824+#endif
15825+
15826 .if \rstor_r11
15827- movq_cfi_restore 0*8, r11
15828+ movq_cfi_restore R11, r11
15829 .endif
15830
15831 .if \rstor_r8910
15832- movq_cfi_restore 1*8, r10
15833- movq_cfi_restore 2*8, r9
15834- movq_cfi_restore 3*8, r8
15835+ movq_cfi_restore R10, r10
15836+ movq_cfi_restore R9, r9
15837+ movq_cfi_restore R8, r8
15838 .endif
15839
15840 .if \rstor_rax
15841- movq_cfi_restore 4*8, rax
15842+ movq_cfi_restore RAX, rax
15843 .endif
15844
15845 .if \rstor_rcx
15846- movq_cfi_restore 5*8, rcx
15847+ movq_cfi_restore RCX, rcx
15848 .endif
15849
15850 .if \rstor_rdx
15851- movq_cfi_restore 6*8, rdx
15852+ movq_cfi_restore RDX, rdx
15853 .endif
15854
15855- movq_cfi_restore 7*8, rsi
15856- movq_cfi_restore 8*8, rdi
15857+ movq_cfi_restore RSI, rsi
15858+ movq_cfi_restore RDI, rdi
15859
15860- .if ARG_SKIP+\addskip > 0
15861- addq $ARG_SKIP+\addskip, %rsp
15862- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15863+ .if ORIG_RAX+\addskip > 0
15864+ addq $ORIG_RAX+\addskip, %rsp
15865+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15866 .endif
15867 .endm
15868
15869- .macro LOAD_ARGS offset, skiprax=0
15870- movq \offset(%rsp), %r11
15871- movq \offset+8(%rsp), %r10
15872- movq \offset+16(%rsp), %r9
15873- movq \offset+24(%rsp), %r8
15874- movq \offset+40(%rsp), %rcx
15875- movq \offset+48(%rsp), %rdx
15876- movq \offset+56(%rsp), %rsi
15877- movq \offset+64(%rsp), %rdi
15878+ .macro LOAD_ARGS skiprax=0
15879+ movq R11(%rsp), %r11
15880+ movq R10(%rsp), %r10
15881+ movq R9(%rsp), %r9
15882+ movq R8(%rsp), %r8
15883+ movq RCX(%rsp), %rcx
15884+ movq RDX(%rsp), %rdx
15885+ movq RSI(%rsp), %rsi
15886+ movq RDI(%rsp), %rdi
15887 .if \skiprax
15888 .else
15889- movq \offset+72(%rsp), %rax
15890+ movq RAX(%rsp), %rax
15891 .endif
15892 .endm
15893
15894-#define REST_SKIP (6*8)
15895-
15896 .macro SAVE_REST
15897- subq $REST_SKIP, %rsp
15898- CFI_ADJUST_CFA_OFFSET REST_SKIP
15899- movq_cfi rbx, 5*8
15900- movq_cfi rbp, 4*8
15901- movq_cfi r12, 3*8
15902- movq_cfi r13, 2*8
15903- movq_cfi r14, 1*8
15904- movq_cfi r15, 0*8
15905+ movq_cfi rbx, RBX
15906+ movq_cfi rbp, RBP
15907+
15908+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15909+ movq_cfi r12, R12
15910+#endif
15911+
15912+ movq_cfi r13, R13
15913+ movq_cfi r14, R14
15914+ movq_cfi r15, R15
15915 .endm
15916
15917 .macro RESTORE_REST
15918- movq_cfi_restore 0*8, r15
15919- movq_cfi_restore 1*8, r14
15920- movq_cfi_restore 2*8, r13
15921- movq_cfi_restore 3*8, r12
15922- movq_cfi_restore 4*8, rbp
15923- movq_cfi_restore 5*8, rbx
15924- addq $REST_SKIP, %rsp
15925- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15926+ movq_cfi_restore R15, r15
15927+ movq_cfi_restore R14, r14
15928+ movq_cfi_restore R13, r13
15929+
15930+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15931+ movq_cfi_restore R12, r12
15932+#endif
15933+
15934+ movq_cfi_restore RBP, rbp
15935+ movq_cfi_restore RBX, rbx
15936 .endm
15937
15938 .macro SAVE_ALL
15939diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15940index f50de69..2b0a458 100644
15941--- a/arch/x86/include/asm/checksum_32.h
15942+++ b/arch/x86/include/asm/checksum_32.h
15943@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15944 int len, __wsum sum,
15945 int *src_err_ptr, int *dst_err_ptr);
15946
15947+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15948+ int len, __wsum sum,
15949+ int *src_err_ptr, int *dst_err_ptr);
15950+
15951+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15952+ int len, __wsum sum,
15953+ int *src_err_ptr, int *dst_err_ptr);
15954+
15955 /*
15956 * Note: when you get a NULL pointer exception here this means someone
15957 * passed in an incorrect kernel address to one of these functions.
15958@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15959
15960 might_sleep();
15961 stac();
15962- ret = csum_partial_copy_generic((__force void *)src, dst,
15963+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15964 len, sum, err_ptr, NULL);
15965 clac();
15966
15967@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15968 might_sleep();
15969 if (access_ok(VERIFY_WRITE, dst, len)) {
15970 stac();
15971- ret = csum_partial_copy_generic(src, (__force void *)dst,
15972+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15973 len, sum, NULL, err_ptr);
15974 clac();
15975 return ret;
15976diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15977index d47786a..2d8883e 100644
15978--- a/arch/x86/include/asm/cmpxchg.h
15979+++ b/arch/x86/include/asm/cmpxchg.h
15980@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15981 __compiletime_error("Bad argument size for cmpxchg");
15982 extern void __xadd_wrong_size(void)
15983 __compiletime_error("Bad argument size for xadd");
15984+extern void __xadd_check_overflow_wrong_size(void)
15985+ __compiletime_error("Bad argument size for xadd_check_overflow");
15986 extern void __add_wrong_size(void)
15987 __compiletime_error("Bad argument size for add");
15988+extern void __add_check_overflow_wrong_size(void)
15989+ __compiletime_error("Bad argument size for add_check_overflow");
15990
15991 /*
15992 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15993@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
15994 __ret; \
15995 })
15996
15997+#ifdef CONFIG_PAX_REFCOUNT
15998+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15999+ ({ \
16000+ __typeof__ (*(ptr)) __ret = (arg); \
16001+ switch (sizeof(*(ptr))) { \
16002+ case __X86_CASE_L: \
16003+ asm volatile (lock #op "l %0, %1\n" \
16004+ "jno 0f\n" \
16005+ "mov %0,%1\n" \
16006+ "int $4\n0:\n" \
16007+ _ASM_EXTABLE(0b, 0b) \
16008+ : "+r" (__ret), "+m" (*(ptr)) \
16009+ : : "memory", "cc"); \
16010+ break; \
16011+ case __X86_CASE_Q: \
16012+ asm volatile (lock #op "q %q0, %1\n" \
16013+ "jno 0f\n" \
16014+ "mov %0,%1\n" \
16015+ "int $4\n0:\n" \
16016+ _ASM_EXTABLE(0b, 0b) \
16017+ : "+r" (__ret), "+m" (*(ptr)) \
16018+ : : "memory", "cc"); \
16019+ break; \
16020+ default: \
16021+ __ ## op ## _check_overflow_wrong_size(); \
16022+ } \
16023+ __ret; \
16024+ })
16025+#else
16026+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16027+#endif
16028+
16029 /*
16030 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16031 * Since this is generally used to protect other memory information, we
16032@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16033 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16034 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16035
16036+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16037+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16038+
16039 #define __add(ptr, inc, lock) \
16040 ({ \
16041 __typeof__ (*(ptr)) __ret = (inc); \
16042diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16043index 59c6c40..5e0b22c 100644
16044--- a/arch/x86/include/asm/compat.h
16045+++ b/arch/x86/include/asm/compat.h
16046@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16047 typedef u32 compat_uint_t;
16048 typedef u32 compat_ulong_t;
16049 typedef u64 __attribute__((aligned(4))) compat_u64;
16050-typedef u32 compat_uptr_t;
16051+typedef u32 __user compat_uptr_t;
16052
16053 struct compat_timespec {
16054 compat_time_t tv_sec;
16055diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16056index 5f12968..a383517 100644
16057--- a/arch/x86/include/asm/cpufeature.h
16058+++ b/arch/x86/include/asm/cpufeature.h
16059@@ -203,7 +203,7 @@
16060 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16061 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16062 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16063-
16064+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16065
16066 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16067 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16068@@ -211,7 +211,7 @@
16069 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16070 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16071 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16072-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16073+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16074 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16075 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16076 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16077@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16078 #undef cpu_has_centaur_mcr
16079 #define cpu_has_centaur_mcr 0
16080
16081+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16082 #endif /* CONFIG_X86_64 */
16083
16084 #if __GNUC__ >= 4
16085@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16086
16087 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16088 t_warn:
16089- warn_pre_alternatives();
16090+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16091+ warn_pre_alternatives();
16092 return false;
16093 #endif
16094
16095@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16096 ".section .discard,\"aw\",@progbits\n"
16097 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16098 ".previous\n"
16099- ".section .altinstr_replacement,\"ax\"\n"
16100+ ".section .altinstr_replacement,\"a\"\n"
16101 "3: movb $1,%0\n"
16102 "4:\n"
16103 ".previous\n"
16104@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16105 " .byte 2b - 1b\n" /* src len */
16106 " .byte 4f - 3f\n" /* repl len */
16107 ".previous\n"
16108- ".section .altinstr_replacement,\"ax\"\n"
16109+ ".section .altinstr_replacement,\"a\"\n"
16110 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16111 "4:\n"
16112 ".previous\n"
16113@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16114 ".section .discard,\"aw\",@progbits\n"
16115 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16116 ".previous\n"
16117- ".section .altinstr_replacement,\"ax\"\n"
16118+ ".section .altinstr_replacement,\"a\"\n"
16119 "3: movb $0,%0\n"
16120 "4:\n"
16121 ".previous\n"
16122@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16123 ".section .discard,\"aw\",@progbits\n"
16124 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16125 ".previous\n"
16126- ".section .altinstr_replacement,\"ax\"\n"
16127+ ".section .altinstr_replacement,\"a\"\n"
16128 "5: movb $1,%0\n"
16129 "6:\n"
16130 ".previous\n"
16131diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16132index 50d033a..37deb26 100644
16133--- a/arch/x86/include/asm/desc.h
16134+++ b/arch/x86/include/asm/desc.h
16135@@ -4,6 +4,7 @@
16136 #include <asm/desc_defs.h>
16137 #include <asm/ldt.h>
16138 #include <asm/mmu.h>
16139+#include <asm/pgtable.h>
16140
16141 #include <linux/smp.h>
16142 #include <linux/percpu.h>
16143@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16144
16145 desc->type = (info->read_exec_only ^ 1) << 1;
16146 desc->type |= info->contents << 2;
16147+ desc->type |= info->seg_not_present ^ 1;
16148
16149 desc->s = 1;
16150 desc->dpl = 0x3;
16151@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16152 }
16153
16154 extern struct desc_ptr idt_descr;
16155-extern gate_desc idt_table[];
16156-extern struct desc_ptr debug_idt_descr;
16157-extern gate_desc debug_idt_table[];
16158-
16159-struct gdt_page {
16160- struct desc_struct gdt[GDT_ENTRIES];
16161-} __attribute__((aligned(PAGE_SIZE)));
16162-
16163-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16164+extern gate_desc idt_table[IDT_ENTRIES];
16165+extern const struct desc_ptr debug_idt_descr;
16166+extern gate_desc debug_idt_table[IDT_ENTRIES];
16167
16168+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16169 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16170 {
16171- return per_cpu(gdt_page, cpu).gdt;
16172+ return cpu_gdt_table[cpu];
16173 }
16174
16175 #ifdef CONFIG_X86_64
16176@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16177 unsigned long base, unsigned dpl, unsigned flags,
16178 unsigned short seg)
16179 {
16180- gate->a = (seg << 16) | (base & 0xffff);
16181- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16182+ gate->gate.offset_low = base;
16183+ gate->gate.seg = seg;
16184+ gate->gate.reserved = 0;
16185+ gate->gate.type = type;
16186+ gate->gate.s = 0;
16187+ gate->gate.dpl = dpl;
16188+ gate->gate.p = 1;
16189+ gate->gate.offset_high = base >> 16;
16190 }
16191
16192 #endif
16193@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16194
16195 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16196 {
16197+ pax_open_kernel();
16198 memcpy(&idt[entry], gate, sizeof(*gate));
16199+ pax_close_kernel();
16200 }
16201
16202 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16203 {
16204+ pax_open_kernel();
16205 memcpy(&ldt[entry], desc, 8);
16206+ pax_close_kernel();
16207 }
16208
16209 static inline void
16210@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16211 default: size = sizeof(*gdt); break;
16212 }
16213
16214+ pax_open_kernel();
16215 memcpy(&gdt[entry], desc, size);
16216+ pax_close_kernel();
16217 }
16218
16219 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16220@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16221
16222 static inline void native_load_tr_desc(void)
16223 {
16224+ pax_open_kernel();
16225 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16226+ pax_close_kernel();
16227 }
16228
16229 static inline void native_load_gdt(const struct desc_ptr *dtr)
16230@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16231 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16232 unsigned int i;
16233
16234+ pax_open_kernel();
16235 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16236 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16237+ pax_close_kernel();
16238 }
16239
16240 #define _LDT_empty(info) \
16241@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16242 preempt_enable();
16243 }
16244
16245-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16246+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16247 {
16248 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16249 }
16250@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16251 }
16252
16253 #ifdef CONFIG_X86_64
16254-static inline void set_nmi_gate(int gate, void *addr)
16255+static inline void set_nmi_gate(int gate, const void *addr)
16256 {
16257 gate_desc s;
16258
16259@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16260 #endif
16261
16262 #ifdef CONFIG_TRACING
16263-extern struct desc_ptr trace_idt_descr;
16264-extern gate_desc trace_idt_table[];
16265+extern const struct desc_ptr trace_idt_descr;
16266+extern gate_desc trace_idt_table[IDT_ENTRIES];
16267 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16268 {
16269 write_idt_entry(trace_idt_table, entry, gate);
16270 }
16271
16272-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16273+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16274 unsigned dpl, unsigned ist, unsigned seg)
16275 {
16276 gate_desc s;
16277@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16278 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16279 #endif
16280
16281-static inline void _set_gate(int gate, unsigned type, void *addr,
16282+static inline void _set_gate(int gate, unsigned type, const void *addr,
16283 unsigned dpl, unsigned ist, unsigned seg)
16284 {
16285 gate_desc s;
16286@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16287 #define set_intr_gate(n, addr) \
16288 do { \
16289 BUG_ON((unsigned)n > 0xFF); \
16290- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16291+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16292 __KERNEL_CS); \
16293- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16294+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16295 0, 0, __KERNEL_CS); \
16296 } while (0)
16297
16298@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16299 /*
16300 * This routine sets up an interrupt gate at directory privilege level 3.
16301 */
16302-static inline void set_system_intr_gate(unsigned int n, void *addr)
16303+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16304 {
16305 BUG_ON((unsigned)n > 0xFF);
16306 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16307 }
16308
16309-static inline void set_system_trap_gate(unsigned int n, void *addr)
16310+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16311 {
16312 BUG_ON((unsigned)n > 0xFF);
16313 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16314 }
16315
16316-static inline void set_trap_gate(unsigned int n, void *addr)
16317+static inline void set_trap_gate(unsigned int n, const void *addr)
16318 {
16319 BUG_ON((unsigned)n > 0xFF);
16320 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16321@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16322 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16323 {
16324 BUG_ON((unsigned)n > 0xFF);
16325- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16326+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16327 }
16328
16329-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16330+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16331 {
16332 BUG_ON((unsigned)n > 0xFF);
16333 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16334 }
16335
16336-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16337+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16338 {
16339 BUG_ON((unsigned)n > 0xFF);
16340 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16341@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16342 else
16343 load_idt((const struct desc_ptr *)&idt_descr);
16344 }
16345+
16346+#ifdef CONFIG_X86_32
16347+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16348+{
16349+ struct desc_struct d;
16350+
16351+ if (likely(limit))
16352+ limit = (limit - 1UL) >> PAGE_SHIFT;
16353+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16354+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16355+}
16356+#endif
16357+
16358 #endif /* _ASM_X86_DESC_H */
16359diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16360index 278441f..b95a174 100644
16361--- a/arch/x86/include/asm/desc_defs.h
16362+++ b/arch/x86/include/asm/desc_defs.h
16363@@ -31,6 +31,12 @@ struct desc_struct {
16364 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16365 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16366 };
16367+ struct {
16368+ u16 offset_low;
16369+ u16 seg;
16370+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16371+ unsigned offset_high: 16;
16372+ } gate;
16373 };
16374 } __attribute__((packed));
16375
16376diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16377index ced283a..ffe04cc 100644
16378--- a/arch/x86/include/asm/div64.h
16379+++ b/arch/x86/include/asm/div64.h
16380@@ -39,7 +39,7 @@
16381 __mod; \
16382 })
16383
16384-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16385+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16386 {
16387 union {
16388 u64 v64;
16389diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16390index 9c999c1..3860cb8 100644
16391--- a/arch/x86/include/asm/elf.h
16392+++ b/arch/x86/include/asm/elf.h
16393@@ -243,7 +243,25 @@ extern int force_personality32;
16394 the loader. We need to make sure that it is out of the way of the program
16395 that it will "exec", and that there is sufficient room for the brk. */
16396
16397+#ifdef CONFIG_PAX_SEGMEXEC
16398+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16399+#else
16400 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16401+#endif
16402+
16403+#ifdef CONFIG_PAX_ASLR
16404+#ifdef CONFIG_X86_32
16405+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16406+
16407+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16408+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16409+#else
16410+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16411+
16412+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16413+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16414+#endif
16415+#endif
16416
16417 /* This yields a mask that user programs can use to figure out what
16418 instruction set this CPU supports. This could be done in user space,
16419@@ -296,16 +314,12 @@ do { \
16420
16421 #define ARCH_DLINFO \
16422 do { \
16423- if (vdso_enabled) \
16424- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16425- (unsigned long)current->mm->context.vdso); \
16426+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16427 } while (0)
16428
16429 #define ARCH_DLINFO_X32 \
16430 do { \
16431- if (vdso_enabled) \
16432- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16433- (unsigned long)current->mm->context.vdso); \
16434+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16435 } while (0)
16436
16437 #define AT_SYSINFO 32
16438@@ -320,7 +334,7 @@ else \
16439
16440 #endif /* !CONFIG_X86_32 */
16441
16442-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16443+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16444
16445 #define VDSO_ENTRY \
16446 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16447@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16448 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16449 #define compat_arch_setup_additional_pages syscall32_setup_pages
16450
16451-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16452-#define arch_randomize_brk arch_randomize_brk
16453-
16454 /*
16455 * True on X86_32 or when emulating IA32 on X86_64
16456 */
16457diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16458index 77a99ac..39ff7f5 100644
16459--- a/arch/x86/include/asm/emergency-restart.h
16460+++ b/arch/x86/include/asm/emergency-restart.h
16461@@ -1,6 +1,6 @@
16462 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16463 #define _ASM_X86_EMERGENCY_RESTART_H
16464
16465-extern void machine_emergency_restart(void);
16466+extern void machine_emergency_restart(void) __noreturn;
16467
16468 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16469diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16470index d3d7469..677ef72 100644
16471--- a/arch/x86/include/asm/floppy.h
16472+++ b/arch/x86/include/asm/floppy.h
16473@@ -229,18 +229,18 @@ static struct fd_routine_l {
16474 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16475 } fd_routine[] = {
16476 {
16477- request_dma,
16478- free_dma,
16479- get_dma_residue,
16480- dma_mem_alloc,
16481- hard_dma_setup
16482+ ._request_dma = request_dma,
16483+ ._free_dma = free_dma,
16484+ ._get_dma_residue = get_dma_residue,
16485+ ._dma_mem_alloc = dma_mem_alloc,
16486+ ._dma_setup = hard_dma_setup
16487 },
16488 {
16489- vdma_request_dma,
16490- vdma_nop,
16491- vdma_get_dma_residue,
16492- vdma_mem_alloc,
16493- vdma_dma_setup
16494+ ._request_dma = vdma_request_dma,
16495+ ._free_dma = vdma_nop,
16496+ ._get_dma_residue = vdma_get_dma_residue,
16497+ ._dma_mem_alloc = vdma_mem_alloc,
16498+ ._dma_setup = vdma_dma_setup
16499 }
16500 };
16501
16502diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16503index cea1c76..6c0d79b 100644
16504--- a/arch/x86/include/asm/fpu-internal.h
16505+++ b/arch/x86/include/asm/fpu-internal.h
16506@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16507 #define user_insn(insn, output, input...) \
16508 ({ \
16509 int err; \
16510+ pax_open_userland(); \
16511 asm volatile(ASM_STAC "\n" \
16512- "1:" #insn "\n\t" \
16513+ "1:" \
16514+ __copyuser_seg \
16515+ #insn "\n\t" \
16516 "2: " ASM_CLAC "\n" \
16517 ".section .fixup,\"ax\"\n" \
16518 "3: movl $-1,%[err]\n" \
16519@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16520 _ASM_EXTABLE(1b, 3b) \
16521 : [err] "=r" (err), output \
16522 : "0"(0), input); \
16523+ pax_close_userland(); \
16524 err; \
16525 })
16526
16527@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16528 "fnclex\n\t"
16529 "emms\n\t"
16530 "fildl %P[addr]" /* set F?P to defined value */
16531- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16532+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16533 }
16534
16535 return fpu_restore_checking(&tsk->thread.fpu);
16536diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16537index b4c1f54..e290c08 100644
16538--- a/arch/x86/include/asm/futex.h
16539+++ b/arch/x86/include/asm/futex.h
16540@@ -12,6 +12,7 @@
16541 #include <asm/smap.h>
16542
16543 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16544+ typecheck(u32 __user *, uaddr); \
16545 asm volatile("\t" ASM_STAC "\n" \
16546 "1:\t" insn "\n" \
16547 "2:\t" ASM_CLAC "\n" \
16548@@ -20,15 +21,16 @@
16549 "\tjmp\t2b\n" \
16550 "\t.previous\n" \
16551 _ASM_EXTABLE(1b, 3b) \
16552- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16553+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16554 : "i" (-EFAULT), "0" (oparg), "1" (0))
16555
16556 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16557+ typecheck(u32 __user *, uaddr); \
16558 asm volatile("\t" ASM_STAC "\n" \
16559 "1:\tmovl %2, %0\n" \
16560 "\tmovl\t%0, %3\n" \
16561 "\t" insn "\n" \
16562- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16563+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16564 "\tjnz\t1b\n" \
16565 "3:\t" ASM_CLAC "\n" \
16566 "\t.section .fixup,\"ax\"\n" \
16567@@ -38,7 +40,7 @@
16568 _ASM_EXTABLE(1b, 4b) \
16569 _ASM_EXTABLE(2b, 4b) \
16570 : "=&a" (oldval), "=&r" (ret), \
16571- "+m" (*uaddr), "=&r" (tem) \
16572+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16573 : "r" (oparg), "i" (-EFAULT), "1" (0))
16574
16575 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16576@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16577
16578 pagefault_disable();
16579
16580+ pax_open_userland();
16581 switch (op) {
16582 case FUTEX_OP_SET:
16583- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16584+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16585 break;
16586 case FUTEX_OP_ADD:
16587- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16588+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16589 uaddr, oparg);
16590 break;
16591 case FUTEX_OP_OR:
16592@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16593 default:
16594 ret = -ENOSYS;
16595 }
16596+ pax_close_userland();
16597
16598 pagefault_enable();
16599
16600diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16601index 67d69b8..50e4b77 100644
16602--- a/arch/x86/include/asm/hw_irq.h
16603+++ b/arch/x86/include/asm/hw_irq.h
16604@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16605 extern void enable_IO_APIC(void);
16606
16607 /* Statistics */
16608-extern atomic_t irq_err_count;
16609-extern atomic_t irq_mis_count;
16610+extern atomic_unchecked_t irq_err_count;
16611+extern atomic_unchecked_t irq_mis_count;
16612
16613 /* EISA */
16614 extern void eisa_set_level_irq(unsigned int irq);
16615diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16616index a203659..9889f1c 100644
16617--- a/arch/x86/include/asm/i8259.h
16618+++ b/arch/x86/include/asm/i8259.h
16619@@ -62,7 +62,7 @@ struct legacy_pic {
16620 void (*init)(int auto_eoi);
16621 int (*irq_pending)(unsigned int irq);
16622 void (*make_irq)(unsigned int irq);
16623-};
16624+} __do_const;
16625
16626 extern struct legacy_pic *legacy_pic;
16627 extern struct legacy_pic null_legacy_pic;
16628diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16629index 91d9c69..dfae7d0 100644
16630--- a/arch/x86/include/asm/io.h
16631+++ b/arch/x86/include/asm/io.h
16632@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16633 "m" (*(volatile type __force *)addr) barrier); }
16634
16635 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16636-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16637-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16638+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16639+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16640
16641 build_mmio_read(__readb, "b", unsigned char, "=q", )
16642-build_mmio_read(__readw, "w", unsigned short, "=r", )
16643-build_mmio_read(__readl, "l", unsigned int, "=r", )
16644+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16645+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16646
16647 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16648 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16649@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16650 return ioremap_nocache(offset, size);
16651 }
16652
16653-extern void iounmap(volatile void __iomem *addr);
16654+extern void iounmap(const volatile void __iomem *addr);
16655
16656 extern void set_iounmap_nonlazy(void);
16657
16658@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16659
16660 #include <linux/vmalloc.h>
16661
16662+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16663+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16664+{
16665+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16666+}
16667+
16668+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16669+{
16670+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16671+}
16672+
16673 /*
16674 * Convert a virtual cached pointer to an uncached pointer
16675 */
16676diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16677index bba3cf8..06bc8da 100644
16678--- a/arch/x86/include/asm/irqflags.h
16679+++ b/arch/x86/include/asm/irqflags.h
16680@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16681 sti; \
16682 sysexit
16683
16684+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16685+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16686+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16687+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16688+
16689 #else
16690 #define INTERRUPT_RETURN iret
16691 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16692diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16693index 9454c16..e4100e3 100644
16694--- a/arch/x86/include/asm/kprobes.h
16695+++ b/arch/x86/include/asm/kprobes.h
16696@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16697 #define RELATIVEJUMP_SIZE 5
16698 #define RELATIVECALL_OPCODE 0xe8
16699 #define RELATIVE_ADDR_SIZE 4
16700-#define MAX_STACK_SIZE 64
16701-#define MIN_STACK_SIZE(ADDR) \
16702- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16703- THREAD_SIZE - (unsigned long)(ADDR))) \
16704- ? (MAX_STACK_SIZE) \
16705- : (((unsigned long)current_thread_info()) + \
16706- THREAD_SIZE - (unsigned long)(ADDR)))
16707+#define MAX_STACK_SIZE 64UL
16708+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16709
16710 #define flush_insn_slot(p) do { } while (0)
16711
16712diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16713index 4ad6560..75c7bdd 100644
16714--- a/arch/x86/include/asm/local.h
16715+++ b/arch/x86/include/asm/local.h
16716@@ -10,33 +10,97 @@ typedef struct {
16717 atomic_long_t a;
16718 } local_t;
16719
16720+typedef struct {
16721+ atomic_long_unchecked_t a;
16722+} local_unchecked_t;
16723+
16724 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16725
16726 #define local_read(l) atomic_long_read(&(l)->a)
16727+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16728 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16729+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16730
16731 static inline void local_inc(local_t *l)
16732 {
16733- asm volatile(_ASM_INC "%0"
16734+ asm volatile(_ASM_INC "%0\n"
16735+
16736+#ifdef CONFIG_PAX_REFCOUNT
16737+ "jno 0f\n"
16738+ _ASM_DEC "%0\n"
16739+ "int $4\n0:\n"
16740+ _ASM_EXTABLE(0b, 0b)
16741+#endif
16742+
16743+ : "+m" (l->a.counter));
16744+}
16745+
16746+static inline void local_inc_unchecked(local_unchecked_t *l)
16747+{
16748+ asm volatile(_ASM_INC "%0\n"
16749 : "+m" (l->a.counter));
16750 }
16751
16752 static inline void local_dec(local_t *l)
16753 {
16754- asm volatile(_ASM_DEC "%0"
16755+ asm volatile(_ASM_DEC "%0\n"
16756+
16757+#ifdef CONFIG_PAX_REFCOUNT
16758+ "jno 0f\n"
16759+ _ASM_INC "%0\n"
16760+ "int $4\n0:\n"
16761+ _ASM_EXTABLE(0b, 0b)
16762+#endif
16763+
16764+ : "+m" (l->a.counter));
16765+}
16766+
16767+static inline void local_dec_unchecked(local_unchecked_t *l)
16768+{
16769+ asm volatile(_ASM_DEC "%0\n"
16770 : "+m" (l->a.counter));
16771 }
16772
16773 static inline void local_add(long i, local_t *l)
16774 {
16775- asm volatile(_ASM_ADD "%1,%0"
16776+ asm volatile(_ASM_ADD "%1,%0\n"
16777+
16778+#ifdef CONFIG_PAX_REFCOUNT
16779+ "jno 0f\n"
16780+ _ASM_SUB "%1,%0\n"
16781+ "int $4\n0:\n"
16782+ _ASM_EXTABLE(0b, 0b)
16783+#endif
16784+
16785+ : "+m" (l->a.counter)
16786+ : "ir" (i));
16787+}
16788+
16789+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16790+{
16791+ asm volatile(_ASM_ADD "%1,%0\n"
16792 : "+m" (l->a.counter)
16793 : "ir" (i));
16794 }
16795
16796 static inline void local_sub(long i, local_t *l)
16797 {
16798- asm volatile(_ASM_SUB "%1,%0"
16799+ asm volatile(_ASM_SUB "%1,%0\n"
16800+
16801+#ifdef CONFIG_PAX_REFCOUNT
16802+ "jno 0f\n"
16803+ _ASM_ADD "%1,%0\n"
16804+ "int $4\n0:\n"
16805+ _ASM_EXTABLE(0b, 0b)
16806+#endif
16807+
16808+ : "+m" (l->a.counter)
16809+ : "ir" (i));
16810+}
16811+
16812+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16813+{
16814+ asm volatile(_ASM_SUB "%1,%0\n"
16815 : "+m" (l->a.counter)
16816 : "ir" (i));
16817 }
16818@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16819 */
16820 static inline int local_sub_and_test(long i, local_t *l)
16821 {
16822- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16823+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16824 }
16825
16826 /**
16827@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16828 */
16829 static inline int local_dec_and_test(local_t *l)
16830 {
16831- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16832+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16833 }
16834
16835 /**
16836@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16837 */
16838 static inline int local_inc_and_test(local_t *l)
16839 {
16840- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16841+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16842 }
16843
16844 /**
16845@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16846 */
16847 static inline int local_add_negative(long i, local_t *l)
16848 {
16849- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16850+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16851 }
16852
16853 /**
16854@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16855 static inline long local_add_return(long i, local_t *l)
16856 {
16857 long __i = i;
16858+ asm volatile(_ASM_XADD "%0, %1\n"
16859+
16860+#ifdef CONFIG_PAX_REFCOUNT
16861+ "jno 0f\n"
16862+ _ASM_MOV "%0,%1\n"
16863+ "int $4\n0:\n"
16864+ _ASM_EXTABLE(0b, 0b)
16865+#endif
16866+
16867+ : "+r" (i), "+m" (l->a.counter)
16868+ : : "memory");
16869+ return i + __i;
16870+}
16871+
16872+/**
16873+ * local_add_return_unchecked - add and return
16874+ * @i: integer value to add
16875+ * @l: pointer to type local_unchecked_t
16876+ *
16877+ * Atomically adds @i to @l and returns @i + @l
16878+ */
16879+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16880+{
16881+ long __i = i;
16882 asm volatile(_ASM_XADD "%0, %1;"
16883 : "+r" (i), "+m" (l->a.counter)
16884 : : "memory");
16885@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16886
16887 #define local_cmpxchg(l, o, n) \
16888 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16889+#define local_cmpxchg_unchecked(l, o, n) \
16890+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16891 /* Always has a lock prefix */
16892 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16893
16894diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16895new file mode 100644
16896index 0000000..2bfd3ba
16897--- /dev/null
16898+++ b/arch/x86/include/asm/mman.h
16899@@ -0,0 +1,15 @@
16900+#ifndef _X86_MMAN_H
16901+#define _X86_MMAN_H
16902+
16903+#include <uapi/asm/mman.h>
16904+
16905+#ifdef __KERNEL__
16906+#ifndef __ASSEMBLY__
16907+#ifdef CONFIG_X86_32
16908+#define arch_mmap_check i386_mmap_check
16909+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16910+#endif
16911+#endif
16912+#endif
16913+
16914+#endif /* X86_MMAN_H */
16915diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16916index 5f55e69..e20bfb1 100644
16917--- a/arch/x86/include/asm/mmu.h
16918+++ b/arch/x86/include/asm/mmu.h
16919@@ -9,7 +9,7 @@
16920 * we put the segment information here.
16921 */
16922 typedef struct {
16923- void *ldt;
16924+ struct desc_struct *ldt;
16925 int size;
16926
16927 #ifdef CONFIG_X86_64
16928@@ -18,7 +18,19 @@ typedef struct {
16929 #endif
16930
16931 struct mutex lock;
16932- void *vdso;
16933+ unsigned long vdso;
16934+
16935+#ifdef CONFIG_X86_32
16936+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16937+ unsigned long user_cs_base;
16938+ unsigned long user_cs_limit;
16939+
16940+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16941+ cpumask_t cpu_user_cs_mask;
16942+#endif
16943+
16944+#endif
16945+#endif
16946 } mm_context_t;
16947
16948 #ifdef CONFIG_SMP
16949diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16950index be12c53..4d24039 100644
16951--- a/arch/x86/include/asm/mmu_context.h
16952+++ b/arch/x86/include/asm/mmu_context.h
16953@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16954
16955 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16956 {
16957+
16958+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16959+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16960+ unsigned int i;
16961+ pgd_t *pgd;
16962+
16963+ pax_open_kernel();
16964+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16965+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16966+ set_pgd_batched(pgd+i, native_make_pgd(0));
16967+ pax_close_kernel();
16968+ }
16969+#endif
16970+
16971 #ifdef CONFIG_SMP
16972 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16973 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16974@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16975 struct task_struct *tsk)
16976 {
16977 unsigned cpu = smp_processor_id();
16978+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16979+ int tlbstate = TLBSTATE_OK;
16980+#endif
16981
16982 if (likely(prev != next)) {
16983 #ifdef CONFIG_SMP
16984+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16985+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16986+#endif
16987 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16988 this_cpu_write(cpu_tlbstate.active_mm, next);
16989 #endif
16990 cpumask_set_cpu(cpu, mm_cpumask(next));
16991
16992 /* Re-load page tables */
16993+#ifdef CONFIG_PAX_PER_CPU_PGD
16994+ pax_open_kernel();
16995+
16996+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16997+ if (static_cpu_has(X86_FEATURE_PCID))
16998+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16999+ else
17000+#endif
17001+
17002+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17003+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17004+ pax_close_kernel();
17005+ 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));
17006+
17007+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17008+ if (static_cpu_has(X86_FEATURE_PCID)) {
17009+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17010+ u64 descriptor[2];
17011+ descriptor[0] = PCID_USER;
17012+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17013+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17014+ descriptor[0] = PCID_KERNEL;
17015+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17016+ }
17017+ } else {
17018+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17019+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17020+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17021+ else
17022+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17023+ }
17024+ } else
17025+#endif
17026+
17027+ load_cr3(get_cpu_pgd(cpu, kernel));
17028+#else
17029 load_cr3(next->pgd);
17030+#endif
17031
17032 /* Stop flush ipis for the previous mm */
17033 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17034@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17035 /* Load the LDT, if the LDT is different: */
17036 if (unlikely(prev->context.ldt != next->context.ldt))
17037 load_LDT_nolock(&next->context);
17038+
17039+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17040+ if (!(__supported_pte_mask & _PAGE_NX)) {
17041+ smp_mb__before_clear_bit();
17042+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17043+ smp_mb__after_clear_bit();
17044+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17045+ }
17046+#endif
17047+
17048+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17049+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17050+ prev->context.user_cs_limit != next->context.user_cs_limit))
17051+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17052+#ifdef CONFIG_SMP
17053+ else if (unlikely(tlbstate != TLBSTATE_OK))
17054+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17055+#endif
17056+#endif
17057+
17058 }
17059+ else {
17060+
17061+#ifdef CONFIG_PAX_PER_CPU_PGD
17062+ pax_open_kernel();
17063+
17064+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17065+ if (static_cpu_has(X86_FEATURE_PCID))
17066+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17067+ else
17068+#endif
17069+
17070+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17071+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17072+ pax_close_kernel();
17073+ 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));
17074+
17075+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17076+ if (static_cpu_has(X86_FEATURE_PCID)) {
17077+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17078+ u64 descriptor[2];
17079+ descriptor[0] = PCID_USER;
17080+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17081+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17082+ descriptor[0] = PCID_KERNEL;
17083+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17084+ }
17085+ } else {
17086+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17087+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17088+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17089+ else
17090+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17091+ }
17092+ } else
17093+#endif
17094+
17095+ load_cr3(get_cpu_pgd(cpu, kernel));
17096+#endif
17097+
17098 #ifdef CONFIG_SMP
17099- else {
17100 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17101 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17102
17103@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17104 * tlb flush IPI delivery. We must reload CR3
17105 * to make sure to use no freed page tables.
17106 */
17107+
17108+#ifndef CONFIG_PAX_PER_CPU_PGD
17109 load_cr3(next->pgd);
17110+#endif
17111+
17112 load_LDT_nolock(&next->context);
17113+
17114+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17115+ if (!(__supported_pte_mask & _PAGE_NX))
17116+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17117+#endif
17118+
17119+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17120+#ifdef CONFIG_PAX_PAGEEXEC
17121+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17122+#endif
17123+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17124+#endif
17125+
17126 }
17127+#endif
17128 }
17129-#endif
17130 }
17131
17132 #define activate_mm(prev, next) \
17133diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17134index e3b7819..b257c64 100644
17135--- a/arch/x86/include/asm/module.h
17136+++ b/arch/x86/include/asm/module.h
17137@@ -5,6 +5,7 @@
17138
17139 #ifdef CONFIG_X86_64
17140 /* X86_64 does not define MODULE_PROC_FAMILY */
17141+#define MODULE_PROC_FAMILY ""
17142 #elif defined CONFIG_M486
17143 #define MODULE_PROC_FAMILY "486 "
17144 #elif defined CONFIG_M586
17145@@ -57,8 +58,20 @@
17146 #error unknown processor family
17147 #endif
17148
17149-#ifdef CONFIG_X86_32
17150-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17151+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17152+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17153+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17154+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17155+#else
17156+#define MODULE_PAX_KERNEXEC ""
17157 #endif
17158
17159+#ifdef CONFIG_PAX_MEMORY_UDEREF
17160+#define MODULE_PAX_UDEREF "UDEREF "
17161+#else
17162+#define MODULE_PAX_UDEREF ""
17163+#endif
17164+
17165+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17166+
17167 #endif /* _ASM_X86_MODULE_H */
17168diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17169index 86f9301..b365cda 100644
17170--- a/arch/x86/include/asm/nmi.h
17171+++ b/arch/x86/include/asm/nmi.h
17172@@ -40,11 +40,11 @@ struct nmiaction {
17173 nmi_handler_t handler;
17174 unsigned long flags;
17175 const char *name;
17176-};
17177+} __do_const;
17178
17179 #define register_nmi_handler(t, fn, fg, n, init...) \
17180 ({ \
17181- static struct nmiaction init fn##_na = { \
17182+ static const struct nmiaction init fn##_na = { \
17183 .handler = (fn), \
17184 .name = (n), \
17185 .flags = (fg), \
17186@@ -52,7 +52,7 @@ struct nmiaction {
17187 __register_nmi_handler((t), &fn##_na); \
17188 })
17189
17190-int __register_nmi_handler(unsigned int, struct nmiaction *);
17191+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17192
17193 void unregister_nmi_handler(unsigned int, const char *);
17194
17195diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17196index 775873d..de5f0304 100644
17197--- a/arch/x86/include/asm/page.h
17198+++ b/arch/x86/include/asm/page.h
17199@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17200 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17201
17202 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17203+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17204
17205 #define __boot_va(x) __va(x)
17206 #define __boot_pa(x) __pa(x)
17207diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17208index 0f1ddee..e2fc3d1 100644
17209--- a/arch/x86/include/asm/page_64.h
17210+++ b/arch/x86/include/asm/page_64.h
17211@@ -7,9 +7,9 @@
17212
17213 /* duplicated to the one in bootmem.h */
17214 extern unsigned long max_pfn;
17215-extern unsigned long phys_base;
17216+extern const unsigned long phys_base;
17217
17218-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17219+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17220 {
17221 unsigned long y = x - __START_KERNEL_map;
17222
17223diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17224index cd6e1610..70f4418 100644
17225--- a/arch/x86/include/asm/paravirt.h
17226+++ b/arch/x86/include/asm/paravirt.h
17227@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17228 return (pmd_t) { ret };
17229 }
17230
17231-static inline pmdval_t pmd_val(pmd_t pmd)
17232+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17233 {
17234 pmdval_t ret;
17235
17236@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17237 val);
17238 }
17239
17240+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17241+{
17242+ pgdval_t val = native_pgd_val(pgd);
17243+
17244+ if (sizeof(pgdval_t) > sizeof(long))
17245+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17246+ val, (u64)val >> 32);
17247+ else
17248+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17249+ val);
17250+}
17251+
17252 static inline void pgd_clear(pgd_t *pgdp)
17253 {
17254 set_pgd(pgdp, __pgd(0));
17255@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17256 pv_mmu_ops.set_fixmap(idx, phys, flags);
17257 }
17258
17259+#ifdef CONFIG_PAX_KERNEXEC
17260+static inline unsigned long pax_open_kernel(void)
17261+{
17262+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17263+}
17264+
17265+static inline unsigned long pax_close_kernel(void)
17266+{
17267+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17268+}
17269+#else
17270+static inline unsigned long pax_open_kernel(void) { return 0; }
17271+static inline unsigned long pax_close_kernel(void) { return 0; }
17272+#endif
17273+
17274 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17275
17276 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17277@@ -906,7 +933,7 @@ extern void default_banner(void);
17278
17279 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17280 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17281-#define PARA_INDIRECT(addr) *%cs:addr
17282+#define PARA_INDIRECT(addr) *%ss:addr
17283 #endif
17284
17285 #define INTERRUPT_RETURN \
17286@@ -981,6 +1008,21 @@ extern void default_banner(void);
17287 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17288 CLBR_NONE, \
17289 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17290+
17291+#define GET_CR0_INTO_RDI \
17292+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17293+ mov %rax,%rdi
17294+
17295+#define SET_RDI_INTO_CR0 \
17296+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17297+
17298+#define GET_CR3_INTO_RDI \
17299+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17300+ mov %rax,%rdi
17301+
17302+#define SET_RDI_INTO_CR3 \
17303+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17304+
17305 #endif /* CONFIG_X86_32 */
17306
17307 #endif /* __ASSEMBLY__ */
17308diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17309index 7549b8b..f0edfda 100644
17310--- a/arch/x86/include/asm/paravirt_types.h
17311+++ b/arch/x86/include/asm/paravirt_types.h
17312@@ -84,7 +84,7 @@ struct pv_init_ops {
17313 */
17314 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17315 unsigned long addr, unsigned len);
17316-};
17317+} __no_const __no_randomize_layout;
17318
17319
17320 struct pv_lazy_ops {
17321@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17322 void (*enter)(void);
17323 void (*leave)(void);
17324 void (*flush)(void);
17325-};
17326+} __no_randomize_layout;
17327
17328 struct pv_time_ops {
17329 unsigned long long (*sched_clock)(void);
17330 unsigned long long (*steal_clock)(int cpu);
17331 unsigned long (*get_tsc_khz)(void);
17332-};
17333+} __no_const __no_randomize_layout;
17334
17335 struct pv_cpu_ops {
17336 /* hooks for various privileged instructions */
17337@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17338
17339 void (*start_context_switch)(struct task_struct *prev);
17340 void (*end_context_switch)(struct task_struct *next);
17341-};
17342+} __no_const __no_randomize_layout;
17343
17344 struct pv_irq_ops {
17345 /*
17346@@ -215,7 +215,7 @@ struct pv_irq_ops {
17347 #ifdef CONFIG_X86_64
17348 void (*adjust_exception_frame)(void);
17349 #endif
17350-};
17351+} __no_randomize_layout;
17352
17353 struct pv_apic_ops {
17354 #ifdef CONFIG_X86_LOCAL_APIC
17355@@ -223,7 +223,7 @@ struct pv_apic_ops {
17356 unsigned long start_eip,
17357 unsigned long start_esp);
17358 #endif
17359-};
17360+} __no_const __no_randomize_layout;
17361
17362 struct pv_mmu_ops {
17363 unsigned long (*read_cr2)(void);
17364@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17365 struct paravirt_callee_save make_pud;
17366
17367 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17368+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17369 #endif /* PAGETABLE_LEVELS == 4 */
17370 #endif /* PAGETABLE_LEVELS >= 3 */
17371
17372@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17373 an mfn. We can tell which is which from the index. */
17374 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17375 phys_addr_t phys, pgprot_t flags);
17376-};
17377+
17378+#ifdef CONFIG_PAX_KERNEXEC
17379+ unsigned long (*pax_open_kernel)(void);
17380+ unsigned long (*pax_close_kernel)(void);
17381+#endif
17382+
17383+} __no_randomize_layout;
17384
17385 struct arch_spinlock;
17386 #ifdef CONFIG_SMP
17387@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17388 struct pv_lock_ops {
17389 struct paravirt_callee_save lock_spinning;
17390 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17391-};
17392+} __no_randomize_layout;
17393
17394 /* This contains all the paravirt structures: we get a convenient
17395 * number for each function using the offset which we use to indicate
17396- * what to patch. */
17397+ * what to patch.
17398+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17399+ */
17400+
17401 struct paravirt_patch_template {
17402 struct pv_init_ops pv_init_ops;
17403 struct pv_time_ops pv_time_ops;
17404@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17405 struct pv_apic_ops pv_apic_ops;
17406 struct pv_mmu_ops pv_mmu_ops;
17407 struct pv_lock_ops pv_lock_ops;
17408-};
17409+} __no_randomize_layout;
17410
17411 extern struct pv_info pv_info;
17412 extern struct pv_init_ops pv_init_ops;
17413diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17414index c4412e9..90e88c5 100644
17415--- a/arch/x86/include/asm/pgalloc.h
17416+++ b/arch/x86/include/asm/pgalloc.h
17417@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17418 pmd_t *pmd, pte_t *pte)
17419 {
17420 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17421+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17422+}
17423+
17424+static inline void pmd_populate_user(struct mm_struct *mm,
17425+ pmd_t *pmd, pte_t *pte)
17426+{
17427+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17428 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17429 }
17430
17431@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17432
17433 #ifdef CONFIG_X86_PAE
17434 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17435+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17436+{
17437+ pud_populate(mm, pudp, pmd);
17438+}
17439 #else /* !CONFIG_X86_PAE */
17440 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17441 {
17442 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17443 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17444 }
17445+
17446+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17447+{
17448+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17449+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17450+}
17451 #endif /* CONFIG_X86_PAE */
17452
17453 #if PAGETABLE_LEVELS > 3
17454@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17455 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17456 }
17457
17458+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17459+{
17460+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17461+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17462+}
17463+
17464 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17465 {
17466 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17467diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17468index 0d193e2..bf59aeb 100644
17469--- a/arch/x86/include/asm/pgtable-2level.h
17470+++ b/arch/x86/include/asm/pgtable-2level.h
17471@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17472
17473 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17474 {
17475+ pax_open_kernel();
17476 *pmdp = pmd;
17477+ pax_close_kernel();
17478 }
17479
17480 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17481diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17482index 81bb91b..9392125 100644
17483--- a/arch/x86/include/asm/pgtable-3level.h
17484+++ b/arch/x86/include/asm/pgtable-3level.h
17485@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17486
17487 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17488 {
17489+ pax_open_kernel();
17490 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17491+ pax_close_kernel();
17492 }
17493
17494 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17495 {
17496+ pax_open_kernel();
17497 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17498+ pax_close_kernel();
17499 }
17500
17501 /*
17502diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17503index bbc8b12..f228861 100644
17504--- a/arch/x86/include/asm/pgtable.h
17505+++ b/arch/x86/include/asm/pgtable.h
17506@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17507
17508 #ifndef __PAGETABLE_PUD_FOLDED
17509 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17510+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17511 #define pgd_clear(pgd) native_pgd_clear(pgd)
17512 #endif
17513
17514@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17515
17516 #define arch_end_context_switch(prev) do {} while(0)
17517
17518+#define pax_open_kernel() native_pax_open_kernel()
17519+#define pax_close_kernel() native_pax_close_kernel()
17520 #endif /* CONFIG_PARAVIRT */
17521
17522+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17523+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17524+
17525+#ifdef CONFIG_PAX_KERNEXEC
17526+static inline unsigned long native_pax_open_kernel(void)
17527+{
17528+ unsigned long cr0;
17529+
17530+ preempt_disable();
17531+ barrier();
17532+ cr0 = read_cr0() ^ X86_CR0_WP;
17533+ BUG_ON(cr0 & X86_CR0_WP);
17534+ write_cr0(cr0);
17535+ return cr0 ^ X86_CR0_WP;
17536+}
17537+
17538+static inline unsigned long native_pax_close_kernel(void)
17539+{
17540+ unsigned long cr0;
17541+
17542+ cr0 = read_cr0() ^ X86_CR0_WP;
17543+ BUG_ON(!(cr0 & X86_CR0_WP));
17544+ write_cr0(cr0);
17545+ barrier();
17546+ preempt_enable_no_resched();
17547+ return cr0 ^ X86_CR0_WP;
17548+}
17549+#else
17550+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17551+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17552+#endif
17553+
17554 /*
17555 * The following only work if pte_present() is true.
17556 * Undefined behaviour if not..
17557 */
17558+static inline int pte_user(pte_t pte)
17559+{
17560+ return pte_val(pte) & _PAGE_USER;
17561+}
17562+
17563 static inline int pte_dirty(pte_t pte)
17564 {
17565 return pte_flags(pte) & _PAGE_DIRTY;
17566@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17567 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17568 }
17569
17570+static inline unsigned long pgd_pfn(pgd_t pgd)
17571+{
17572+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17573+}
17574+
17575 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17576
17577 static inline int pmd_large(pmd_t pte)
17578@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17579 return pte_clear_flags(pte, _PAGE_RW);
17580 }
17581
17582+static inline pte_t pte_mkread(pte_t pte)
17583+{
17584+ return __pte(pte_val(pte) | _PAGE_USER);
17585+}
17586+
17587 static inline pte_t pte_mkexec(pte_t pte)
17588 {
17589- return pte_clear_flags(pte, _PAGE_NX);
17590+#ifdef CONFIG_X86_PAE
17591+ if (__supported_pte_mask & _PAGE_NX)
17592+ return pte_clear_flags(pte, _PAGE_NX);
17593+ else
17594+#endif
17595+ return pte_set_flags(pte, _PAGE_USER);
17596+}
17597+
17598+static inline pte_t pte_exprotect(pte_t pte)
17599+{
17600+#ifdef CONFIG_X86_PAE
17601+ if (__supported_pte_mask & _PAGE_NX)
17602+ return pte_set_flags(pte, _PAGE_NX);
17603+ else
17604+#endif
17605+ return pte_clear_flags(pte, _PAGE_USER);
17606 }
17607
17608 static inline pte_t pte_mkdirty(pte_t pte)
17609@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17610 #endif
17611
17612 #ifndef __ASSEMBLY__
17613+
17614+#ifdef CONFIG_PAX_PER_CPU_PGD
17615+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17616+enum cpu_pgd_type {kernel = 0, user = 1};
17617+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17618+{
17619+ return cpu_pgd[cpu][type];
17620+}
17621+#endif
17622+
17623 #include <linux/mm_types.h>
17624 #include <linux/mmdebug.h>
17625 #include <linux/log2.h>
17626@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17627 * Currently stuck as a macro due to indirect forward reference to
17628 * linux/mmzone.h's __section_mem_map_addr() definition:
17629 */
17630-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17631+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17632
17633 /* Find an entry in the second-level page table.. */
17634 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17635@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17636 * Currently stuck as a macro due to indirect forward reference to
17637 * linux/mmzone.h's __section_mem_map_addr() definition:
17638 */
17639-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17640+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17641
17642 /* to find an entry in a page-table-directory. */
17643 static inline unsigned long pud_index(unsigned long address)
17644@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17645
17646 static inline int pgd_bad(pgd_t pgd)
17647 {
17648- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17649+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17650 }
17651
17652 static inline int pgd_none(pgd_t pgd)
17653@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17654 * pgd_offset() returns a (pgd_t *)
17655 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17656 */
17657-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17658+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17659+
17660+#ifdef CONFIG_PAX_PER_CPU_PGD
17661+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17662+#endif
17663+
17664 /*
17665 * a shortcut which implies the use of the kernel's pgd, instead
17666 * of a process's
17667@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17668 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17669 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17670
17671+#ifdef CONFIG_X86_32
17672+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17673+#else
17674+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17675+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17676+
17677+#ifdef CONFIG_PAX_MEMORY_UDEREF
17678+#ifdef __ASSEMBLY__
17679+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17680+#else
17681+extern unsigned long pax_user_shadow_base;
17682+extern pgdval_t clone_pgd_mask;
17683+#endif
17684+#endif
17685+
17686+#endif
17687+
17688 #ifndef __ASSEMBLY__
17689
17690 extern int direct_gbpages;
17691@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17692 * dst and src can be on the same page, but the range must not overlap,
17693 * and must not cross a page boundary.
17694 */
17695-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17696+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17697 {
17698- memcpy(dst, src, count * sizeof(pgd_t));
17699+ pax_open_kernel();
17700+ while (count--)
17701+ *dst++ = *src++;
17702+ pax_close_kernel();
17703 }
17704
17705+#ifdef CONFIG_PAX_PER_CPU_PGD
17706+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17707+#endif
17708+
17709+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17710+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17711+#else
17712+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17713+#endif
17714+
17715 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17716 static inline int page_level_shift(enum pg_level level)
17717 {
17718diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17719index 9ee3221..b979c6b 100644
17720--- a/arch/x86/include/asm/pgtable_32.h
17721+++ b/arch/x86/include/asm/pgtable_32.h
17722@@ -25,9 +25,6 @@
17723 struct mm_struct;
17724 struct vm_area_struct;
17725
17726-extern pgd_t swapper_pg_dir[1024];
17727-extern pgd_t initial_page_table[1024];
17728-
17729 static inline void pgtable_cache_init(void) { }
17730 static inline void check_pgt_cache(void) { }
17731 void paging_init(void);
17732@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17733 # include <asm/pgtable-2level.h>
17734 #endif
17735
17736+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17737+extern pgd_t initial_page_table[PTRS_PER_PGD];
17738+#ifdef CONFIG_X86_PAE
17739+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17740+#endif
17741+
17742 #if defined(CONFIG_HIGHPTE)
17743 #define pte_offset_map(dir, address) \
17744 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17745@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17746 /* Clear a kernel PTE and flush it from the TLB */
17747 #define kpte_clear_flush(ptep, vaddr) \
17748 do { \
17749+ pax_open_kernel(); \
17750 pte_clear(&init_mm, (vaddr), (ptep)); \
17751+ pax_close_kernel(); \
17752 __flush_tlb_one((vaddr)); \
17753 } while (0)
17754
17755 #endif /* !__ASSEMBLY__ */
17756
17757+#define HAVE_ARCH_UNMAPPED_AREA
17758+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17759+
17760 /*
17761 * kern_addr_valid() is (1) for FLATMEM and (0) for
17762 * SPARSEMEM and DISCONTIGMEM
17763diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17764index ed5903b..c7fe163 100644
17765--- a/arch/x86/include/asm/pgtable_32_types.h
17766+++ b/arch/x86/include/asm/pgtable_32_types.h
17767@@ -8,7 +8,7 @@
17768 */
17769 #ifdef CONFIG_X86_PAE
17770 # include <asm/pgtable-3level_types.h>
17771-# define PMD_SIZE (1UL << PMD_SHIFT)
17772+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17773 # define PMD_MASK (~(PMD_SIZE - 1))
17774 #else
17775 # include <asm/pgtable-2level_types.h>
17776@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17777 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17778 #endif
17779
17780+#ifdef CONFIG_PAX_KERNEXEC
17781+#ifndef __ASSEMBLY__
17782+extern unsigned char MODULES_EXEC_VADDR[];
17783+extern unsigned char MODULES_EXEC_END[];
17784+#endif
17785+#include <asm/boot.h>
17786+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17787+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17788+#else
17789+#define ktla_ktva(addr) (addr)
17790+#define ktva_ktla(addr) (addr)
17791+#endif
17792+
17793 #define MODULES_VADDR VMALLOC_START
17794 #define MODULES_END VMALLOC_END
17795 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17796diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17797index e22c1db..23a625a 100644
17798--- a/arch/x86/include/asm/pgtable_64.h
17799+++ b/arch/x86/include/asm/pgtable_64.h
17800@@ -16,10 +16,14 @@
17801
17802 extern pud_t level3_kernel_pgt[512];
17803 extern pud_t level3_ident_pgt[512];
17804+extern pud_t level3_vmalloc_start_pgt[512];
17805+extern pud_t level3_vmalloc_end_pgt[512];
17806+extern pud_t level3_vmemmap_pgt[512];
17807+extern pud_t level2_vmemmap_pgt[512];
17808 extern pmd_t level2_kernel_pgt[512];
17809 extern pmd_t level2_fixmap_pgt[512];
17810-extern pmd_t level2_ident_pgt[512];
17811-extern pgd_t init_level4_pgt[];
17812+extern pmd_t level2_ident_pgt[512*2];
17813+extern pgd_t init_level4_pgt[512];
17814
17815 #define swapper_pg_dir init_level4_pgt
17816
17817@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17818
17819 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17820 {
17821+ pax_open_kernel();
17822 *pmdp = pmd;
17823+ pax_close_kernel();
17824 }
17825
17826 static inline void native_pmd_clear(pmd_t *pmd)
17827@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17828
17829 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17830 {
17831+ pax_open_kernel();
17832 *pudp = pud;
17833+ pax_close_kernel();
17834 }
17835
17836 static inline void native_pud_clear(pud_t *pud)
17837@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17838
17839 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17840 {
17841+ pax_open_kernel();
17842+ *pgdp = pgd;
17843+ pax_close_kernel();
17844+}
17845+
17846+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17847+{
17848 *pgdp = pgd;
17849 }
17850
17851diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17852index c883bf7..19970b3 100644
17853--- a/arch/x86/include/asm/pgtable_64_types.h
17854+++ b/arch/x86/include/asm/pgtable_64_types.h
17855@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17856 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
17857 #define MODULES_END _AC(0xffffffffff000000, UL)
17858 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17859+#define MODULES_EXEC_VADDR MODULES_VADDR
17860+#define MODULES_EXEC_END MODULES_END
17861+
17862+#define ktla_ktva(addr) (addr)
17863+#define ktva_ktla(addr) (addr)
17864
17865 #define EARLY_DYNAMIC_PAGE_TABLES 64
17866
17867diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17868index 94e40f1..ebd03e4 100644
17869--- a/arch/x86/include/asm/pgtable_types.h
17870+++ b/arch/x86/include/asm/pgtable_types.h
17871@@ -16,13 +16,12 @@
17872 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17873 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17874 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17875-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17876+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17877 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17878 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17879 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17880-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17881-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17882-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17883+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17884+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17885 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17886
17887 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17888@@ -40,7 +39,6 @@
17889 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17890 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17891 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17892-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17893 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17894 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17895 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17896@@ -87,8 +85,10 @@
17897
17898 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17899 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17900-#else
17901+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17902 #define _PAGE_NX (_AT(pteval_t, 0))
17903+#else
17904+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17905 #endif
17906
17907 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17908@@ -147,6 +147,9 @@
17909 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17910 _PAGE_ACCESSED)
17911
17912+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17913+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17914+
17915 #define __PAGE_KERNEL_EXEC \
17916 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17917 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17918@@ -157,7 +160,7 @@
17919 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17920 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17921 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17922-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17923+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17924 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17925 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17926 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17927@@ -219,8 +222,8 @@
17928 * bits are combined, this will alow user to access the high address mapped
17929 * VDSO in the presence of CONFIG_COMPAT_VDSO
17930 */
17931-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17932-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17933+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17934+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17935 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17936 #endif
17937
17938@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17939 {
17940 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17941 }
17942+#endif
17943
17944+#if PAGETABLE_LEVELS == 3
17945+#include <asm-generic/pgtable-nopud.h>
17946+#endif
17947+
17948+#if PAGETABLE_LEVELS == 2
17949+#include <asm-generic/pgtable-nopmd.h>
17950+#endif
17951+
17952+#ifndef __ASSEMBLY__
17953 #if PAGETABLE_LEVELS > 3
17954 typedef struct { pudval_t pud; } pud_t;
17955
17956@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17957 return pud.pud;
17958 }
17959 #else
17960-#include <asm-generic/pgtable-nopud.h>
17961-
17962 static inline pudval_t native_pud_val(pud_t pud)
17963 {
17964 return native_pgd_val(pud.pgd);
17965@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17966 return pmd.pmd;
17967 }
17968 #else
17969-#include <asm-generic/pgtable-nopmd.h>
17970-
17971 static inline pmdval_t native_pmd_val(pmd_t pmd)
17972 {
17973 return native_pgd_val(pmd.pud.pgd);
17974@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
17975
17976 extern pteval_t __supported_pte_mask;
17977 extern void set_nx(void);
17978-extern int nx_enabled;
17979
17980 #define pgprot_writecombine pgprot_writecombine
17981 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17982diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17983index c8b0519..fd29e73 100644
17984--- a/arch/x86/include/asm/preempt.h
17985+++ b/arch/x86/include/asm/preempt.h
17986@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17987 */
17988 static __always_inline bool __preempt_count_dec_and_test(void)
17989 {
17990- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17991+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17992 }
17993
17994 /*
17995diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17996index fdedd38..95c02c2 100644
17997--- a/arch/x86/include/asm/processor.h
17998+++ b/arch/x86/include/asm/processor.h
17999@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18000 /* Index into per_cpu list: */
18001 u16 cpu_index;
18002 u32 microcode;
18003-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18004+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18005
18006 #define X86_VENDOR_INTEL 0
18007 #define X86_VENDOR_CYRIX 1
18008@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18009 : "memory");
18010 }
18011
18012+/* invpcid (%rdx),%rax */
18013+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18014+
18015+#define INVPCID_SINGLE_ADDRESS 0UL
18016+#define INVPCID_SINGLE_CONTEXT 1UL
18017+#define INVPCID_ALL_GLOBAL 2UL
18018+#define INVPCID_ALL_MONGLOBAL 3UL
18019+
18020+#define PCID_KERNEL 0UL
18021+#define PCID_USER 1UL
18022+#define PCID_NOFLUSH (1UL << 63)
18023+
18024 static inline void load_cr3(pgd_t *pgdir)
18025 {
18026- write_cr3(__pa(pgdir));
18027+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18028 }
18029
18030 #ifdef CONFIG_X86_32
18031@@ -283,7 +295,7 @@ struct tss_struct {
18032
18033 } ____cacheline_aligned;
18034
18035-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18036+extern struct tss_struct init_tss[NR_CPUS];
18037
18038 /*
18039 * Save the original ist values for checking stack pointers during debugging
18040@@ -470,6 +482,7 @@ struct thread_struct {
18041 unsigned short ds;
18042 unsigned short fsindex;
18043 unsigned short gsindex;
18044+ unsigned short ss;
18045 #endif
18046 #ifdef CONFIG_X86_32
18047 unsigned long ip;
18048@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18049 extern unsigned long mmu_cr4_features;
18050 extern u32 *trampoline_cr4_features;
18051
18052-static inline void set_in_cr4(unsigned long mask)
18053-{
18054- unsigned long cr4;
18055-
18056- mmu_cr4_features |= mask;
18057- if (trampoline_cr4_features)
18058- *trampoline_cr4_features = mmu_cr4_features;
18059- cr4 = read_cr4();
18060- cr4 |= mask;
18061- write_cr4(cr4);
18062-}
18063-
18064-static inline void clear_in_cr4(unsigned long mask)
18065-{
18066- unsigned long cr4;
18067-
18068- mmu_cr4_features &= ~mask;
18069- if (trampoline_cr4_features)
18070- *trampoline_cr4_features = mmu_cr4_features;
18071- cr4 = read_cr4();
18072- cr4 &= ~mask;
18073- write_cr4(cr4);
18074-}
18075+extern void set_in_cr4(unsigned long mask);
18076+extern void clear_in_cr4(unsigned long mask);
18077
18078 typedef struct {
18079 unsigned long seg;
18080@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18081 */
18082 #define TASK_SIZE PAGE_OFFSET
18083 #define TASK_SIZE_MAX TASK_SIZE
18084+
18085+#ifdef CONFIG_PAX_SEGMEXEC
18086+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18087+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18088+#else
18089 #define STACK_TOP TASK_SIZE
18090-#define STACK_TOP_MAX STACK_TOP
18091+#endif
18092+
18093+#define STACK_TOP_MAX TASK_SIZE
18094
18095 #define INIT_THREAD { \
18096- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18097+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18098 .vm86_info = NULL, \
18099 .sysenter_cs = __KERNEL_CS, \
18100 .io_bitmap_ptr = NULL, \
18101@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18102 */
18103 #define INIT_TSS { \
18104 .x86_tss = { \
18105- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18106+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18107 .ss0 = __KERNEL_DS, \
18108 .ss1 = __KERNEL_CS, \
18109 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18110@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18111 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18112
18113 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18114-#define KSTK_TOP(info) \
18115-({ \
18116- unsigned long *__ptr = (unsigned long *)(info); \
18117- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18118-})
18119+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18120
18121 /*
18122 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18123@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18124 #define task_pt_regs(task) \
18125 ({ \
18126 struct pt_regs *__regs__; \
18127- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18128+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18129 __regs__ - 1; \
18130 })
18131
18132@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18133 /*
18134 * User space process size. 47bits minus one guard page.
18135 */
18136-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18137+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18138
18139 /* This decides where the kernel will search for a free chunk of vm
18140 * space during mmap's.
18141 */
18142 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18143- 0xc0000000 : 0xFFFFe000)
18144+ 0xc0000000 : 0xFFFFf000)
18145
18146 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18147 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18148@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18149 #define STACK_TOP_MAX TASK_SIZE_MAX
18150
18151 #define INIT_THREAD { \
18152- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18153+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18154 }
18155
18156 #define INIT_TSS { \
18157- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18158+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18159 }
18160
18161 /*
18162@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18163 */
18164 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18165
18166+#ifdef CONFIG_PAX_SEGMEXEC
18167+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18168+#endif
18169+
18170 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18171
18172 /* Get/set a process' ability to use the timestamp counter instruction */
18173@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18174 return 0;
18175 }
18176
18177-extern unsigned long arch_align_stack(unsigned long sp);
18178+#define arch_align_stack(x) ((x) & ~0xfUL)
18179 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18180
18181 void default_idle(void);
18182@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18183 #define xen_set_default_idle 0
18184 #endif
18185
18186-void stop_this_cpu(void *dummy);
18187+void stop_this_cpu(void *dummy) __noreturn;
18188 void df_debug(struct pt_regs *regs, long error_code);
18189 #endif /* _ASM_X86_PROCESSOR_H */
18190diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18191index 14fd6fd..6740420 100644
18192--- a/arch/x86/include/asm/ptrace.h
18193+++ b/arch/x86/include/asm/ptrace.h
18194@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18195 }
18196
18197 /*
18198- * user_mode_vm(regs) determines whether a register set came from user mode.
18199+ * user_mode(regs) determines whether a register set came from user mode.
18200 * This is true if V8086 mode was enabled OR if the register set was from
18201 * protected mode with RPL-3 CS value. This tricky test checks that with
18202 * one comparison. Many places in the kernel can bypass this full check
18203- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18204+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18205+ * be used.
18206 */
18207-static inline int user_mode(struct pt_regs *regs)
18208+static inline int user_mode_novm(struct pt_regs *regs)
18209 {
18210 #ifdef CONFIG_X86_32
18211 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18212 #else
18213- return !!(regs->cs & 3);
18214+ return !!(regs->cs & SEGMENT_RPL_MASK);
18215 #endif
18216 }
18217
18218-static inline int user_mode_vm(struct pt_regs *regs)
18219+static inline int user_mode(struct pt_regs *regs)
18220 {
18221 #ifdef CONFIG_X86_32
18222 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18223 USER_RPL;
18224 #else
18225- return user_mode(regs);
18226+ return user_mode_novm(regs);
18227 #endif
18228 }
18229
18230@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18231 #ifdef CONFIG_X86_64
18232 static inline bool user_64bit_mode(struct pt_regs *regs)
18233 {
18234+ unsigned long cs = regs->cs & 0xffff;
18235 #ifndef CONFIG_PARAVIRT
18236 /*
18237 * On non-paravirt systems, this is the only long mode CPL 3
18238 * selector. We do not allow long mode selectors in the LDT.
18239 */
18240- return regs->cs == __USER_CS;
18241+ return cs == __USER_CS;
18242 #else
18243 /* Headers are too twisted for this to go in paravirt.h. */
18244- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18245+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18246 #endif
18247 }
18248
18249@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18250 * Traps from the kernel do not save sp and ss.
18251 * Use the helper function to retrieve sp.
18252 */
18253- if (offset == offsetof(struct pt_regs, sp) &&
18254- regs->cs == __KERNEL_CS)
18255- return kernel_stack_pointer(regs);
18256+ if (offset == offsetof(struct pt_regs, sp)) {
18257+ unsigned long cs = regs->cs & 0xffff;
18258+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18259+ return kernel_stack_pointer(regs);
18260+ }
18261 #endif
18262 return *(unsigned long *)((unsigned long)regs + offset);
18263 }
18264diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18265index 9c6b890..5305f53 100644
18266--- a/arch/x86/include/asm/realmode.h
18267+++ b/arch/x86/include/asm/realmode.h
18268@@ -22,16 +22,14 @@ struct real_mode_header {
18269 #endif
18270 /* APM/BIOS reboot */
18271 u32 machine_real_restart_asm;
18272-#ifdef CONFIG_X86_64
18273 u32 machine_real_restart_seg;
18274-#endif
18275 };
18276
18277 /* This must match data at trampoline_32/64.S */
18278 struct trampoline_header {
18279 #ifdef CONFIG_X86_32
18280 u32 start;
18281- u16 gdt_pad;
18282+ u16 boot_cs;
18283 u16 gdt_limit;
18284 u32 gdt_base;
18285 #else
18286diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18287index a82c4f1..ac45053 100644
18288--- a/arch/x86/include/asm/reboot.h
18289+++ b/arch/x86/include/asm/reboot.h
18290@@ -6,13 +6,13 @@
18291 struct pt_regs;
18292
18293 struct machine_ops {
18294- void (*restart)(char *cmd);
18295- void (*halt)(void);
18296- void (*power_off)(void);
18297+ void (* __noreturn restart)(char *cmd);
18298+ void (* __noreturn halt)(void);
18299+ void (* __noreturn power_off)(void);
18300 void (*shutdown)(void);
18301 void (*crash_shutdown)(struct pt_regs *);
18302- void (*emergency_restart)(void);
18303-};
18304+ void (* __noreturn emergency_restart)(void);
18305+} __no_const;
18306
18307 extern struct machine_ops machine_ops;
18308
18309diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18310index 8f7866a..e442f20 100644
18311--- a/arch/x86/include/asm/rmwcc.h
18312+++ b/arch/x86/include/asm/rmwcc.h
18313@@ -3,7 +3,34 @@
18314
18315 #ifdef CC_HAVE_ASM_GOTO
18316
18317-#define __GEN_RMWcc(fullop, var, cc, ...) \
18318+#ifdef CONFIG_PAX_REFCOUNT
18319+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18320+do { \
18321+ asm_volatile_goto (fullop \
18322+ ";jno 0f\n" \
18323+ fullantiop \
18324+ ";int $4\n0:\n" \
18325+ _ASM_EXTABLE(0b, 0b) \
18326+ ";j" cc " %l[cc_label]" \
18327+ : : "m" (var), ## __VA_ARGS__ \
18328+ : "memory" : cc_label); \
18329+ return 0; \
18330+cc_label: \
18331+ return 1; \
18332+} while (0)
18333+#else
18334+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18335+do { \
18336+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18337+ : : "m" (var), ## __VA_ARGS__ \
18338+ : "memory" : cc_label); \
18339+ return 0; \
18340+cc_label: \
18341+ return 1; \
18342+} while (0)
18343+#endif
18344+
18345+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18346 do { \
18347 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18348 : : "m" (var), ## __VA_ARGS__ \
18349@@ -13,15 +40,46 @@ cc_label: \
18350 return 1; \
18351 } while (0)
18352
18353-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18354- __GEN_RMWcc(op " " arg0, var, cc)
18355+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18356+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18357
18358-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18359- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18360+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18361+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18362+
18363+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18364+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18365+
18366+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18367+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18368
18369 #else /* !CC_HAVE_ASM_GOTO */
18370
18371-#define __GEN_RMWcc(fullop, var, cc, ...) \
18372+#ifdef CONFIG_PAX_REFCOUNT
18373+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18374+do { \
18375+ char c; \
18376+ asm volatile (fullop \
18377+ ";jno 0f\n" \
18378+ fullantiop \
18379+ ";int $4\n0:\n" \
18380+ _ASM_EXTABLE(0b, 0b) \
18381+ "; set" cc " %1" \
18382+ : "+m" (var), "=qm" (c) \
18383+ : __VA_ARGS__ : "memory"); \
18384+ return c != 0; \
18385+} while (0)
18386+#else
18387+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18388+do { \
18389+ char c; \
18390+ asm volatile (fullop "; set" cc " %1" \
18391+ : "+m" (var), "=qm" (c) \
18392+ : __VA_ARGS__ : "memory"); \
18393+ return c != 0; \
18394+} while (0)
18395+#endif
18396+
18397+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18398 do { \
18399 char c; \
18400 asm volatile (fullop "; set" cc " %1" \
18401@@ -30,11 +88,17 @@ do { \
18402 return c != 0; \
18403 } while (0)
18404
18405-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18406- __GEN_RMWcc(op " " arg0, var, cc)
18407+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18408+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18409+
18410+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18411+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18412+
18413+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18414+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18415
18416-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18417- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18418+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18419+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18420
18421 #endif /* CC_HAVE_ASM_GOTO */
18422
18423diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18424index cad82c9..2e5c5c1 100644
18425--- a/arch/x86/include/asm/rwsem.h
18426+++ b/arch/x86/include/asm/rwsem.h
18427@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18428 {
18429 asm volatile("# beginning down_read\n\t"
18430 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18431+
18432+#ifdef CONFIG_PAX_REFCOUNT
18433+ "jno 0f\n"
18434+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18435+ "int $4\n0:\n"
18436+ _ASM_EXTABLE(0b, 0b)
18437+#endif
18438+
18439 /* adds 0x00000001 */
18440 " jns 1f\n"
18441 " call call_rwsem_down_read_failed\n"
18442@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18443 "1:\n\t"
18444 " mov %1,%2\n\t"
18445 " add %3,%2\n\t"
18446+
18447+#ifdef CONFIG_PAX_REFCOUNT
18448+ "jno 0f\n"
18449+ "sub %3,%2\n"
18450+ "int $4\n0:\n"
18451+ _ASM_EXTABLE(0b, 0b)
18452+#endif
18453+
18454 " jle 2f\n\t"
18455 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18456 " jnz 1b\n\t"
18457@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18458 long tmp;
18459 asm volatile("# beginning down_write\n\t"
18460 LOCK_PREFIX " xadd %1,(%2)\n\t"
18461+
18462+#ifdef CONFIG_PAX_REFCOUNT
18463+ "jno 0f\n"
18464+ "mov %1,(%2)\n"
18465+ "int $4\n0:\n"
18466+ _ASM_EXTABLE(0b, 0b)
18467+#endif
18468+
18469 /* adds 0xffff0001, returns the old value */
18470 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18471 /* was the active mask 0 before? */
18472@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18473 long tmp;
18474 asm volatile("# beginning __up_read\n\t"
18475 LOCK_PREFIX " xadd %1,(%2)\n\t"
18476+
18477+#ifdef CONFIG_PAX_REFCOUNT
18478+ "jno 0f\n"
18479+ "mov %1,(%2)\n"
18480+ "int $4\n0:\n"
18481+ _ASM_EXTABLE(0b, 0b)
18482+#endif
18483+
18484 /* subtracts 1, returns the old value */
18485 " jns 1f\n\t"
18486 " call call_rwsem_wake\n" /* expects old value in %edx */
18487@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18488 long tmp;
18489 asm volatile("# beginning __up_write\n\t"
18490 LOCK_PREFIX " xadd %1,(%2)\n\t"
18491+
18492+#ifdef CONFIG_PAX_REFCOUNT
18493+ "jno 0f\n"
18494+ "mov %1,(%2)\n"
18495+ "int $4\n0:\n"
18496+ _ASM_EXTABLE(0b, 0b)
18497+#endif
18498+
18499 /* subtracts 0xffff0001, returns the old value */
18500 " jns 1f\n\t"
18501 " call call_rwsem_wake\n" /* expects old value in %edx */
18502@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18503 {
18504 asm volatile("# beginning __downgrade_write\n\t"
18505 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18506+
18507+#ifdef CONFIG_PAX_REFCOUNT
18508+ "jno 0f\n"
18509+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18510+ "int $4\n0:\n"
18511+ _ASM_EXTABLE(0b, 0b)
18512+#endif
18513+
18514 /*
18515 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18516 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18517@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18518 */
18519 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18520 {
18521- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18522+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18523+
18524+#ifdef CONFIG_PAX_REFCOUNT
18525+ "jno 0f\n"
18526+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18527+ "int $4\n0:\n"
18528+ _ASM_EXTABLE(0b, 0b)
18529+#endif
18530+
18531 : "+m" (sem->count)
18532 : "er" (delta));
18533 }
18534@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18535 */
18536 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18537 {
18538- return delta + xadd(&sem->count, delta);
18539+ return delta + xadd_check_overflow(&sem->count, delta);
18540 }
18541
18542 #endif /* __KERNEL__ */
18543diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18544index 6f1c3a8..7744f19 100644
18545--- a/arch/x86/include/asm/segment.h
18546+++ b/arch/x86/include/asm/segment.h
18547@@ -64,10 +64,15 @@
18548 * 26 - ESPFIX small SS
18549 * 27 - per-cpu [ offset to per-cpu data area ]
18550 * 28 - stack_canary-20 [ for stack protector ]
18551- * 29 - unused
18552- * 30 - unused
18553+ * 29 - PCI BIOS CS
18554+ * 30 - PCI BIOS DS
18555 * 31 - TSS for double fault handler
18556 */
18557+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18558+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18559+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18560+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18561+
18562 #define GDT_ENTRY_TLS_MIN 6
18563 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18564
18565@@ -79,6 +84,8 @@
18566
18567 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18568
18569+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18570+
18571 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18572
18573 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18574@@ -104,6 +111,12 @@
18575 #define __KERNEL_STACK_CANARY 0
18576 #endif
18577
18578+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18579+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18580+
18581+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18582+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18583+
18584 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18585
18586 /*
18587@@ -141,7 +154,7 @@
18588 */
18589
18590 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18591-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18592+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18593
18594
18595 #else
18596@@ -165,6 +178,8 @@
18597 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18598 #define __USER32_DS __USER_DS
18599
18600+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18601+
18602 #define GDT_ENTRY_TSS 8 /* needs two entries */
18603 #define GDT_ENTRY_LDT 10 /* needs two entries */
18604 #define GDT_ENTRY_TLS_MIN 12
18605@@ -173,6 +188,8 @@
18606 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18607 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18608
18609+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18610+
18611 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18612 #define FS_TLS 0
18613 #define GS_TLS 1
18614@@ -180,12 +197,14 @@
18615 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18616 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18617
18618-#define GDT_ENTRIES 16
18619+#define GDT_ENTRIES 17
18620
18621 #endif
18622
18623 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18624+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18625 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18626+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18627 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18628 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18629 #ifndef CONFIG_PARAVIRT
18630@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18631 {
18632 unsigned long __limit;
18633 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18634- return __limit + 1;
18635+ return __limit;
18636 }
18637
18638 #endif /* !__ASSEMBLY__ */
18639diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18640index 8d3120f..352b440 100644
18641--- a/arch/x86/include/asm/smap.h
18642+++ b/arch/x86/include/asm/smap.h
18643@@ -25,11 +25,40 @@
18644
18645 #include <asm/alternative-asm.h>
18646
18647+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18648+#define ASM_PAX_OPEN_USERLAND \
18649+ 661: jmp 663f; \
18650+ .pushsection .altinstr_replacement, "a" ; \
18651+ 662: pushq %rax; nop; \
18652+ .popsection ; \
18653+ .pushsection .altinstructions, "a" ; \
18654+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18655+ .popsection ; \
18656+ call __pax_open_userland; \
18657+ popq %rax; \
18658+ 663:
18659+
18660+#define ASM_PAX_CLOSE_USERLAND \
18661+ 661: jmp 663f; \
18662+ .pushsection .altinstr_replacement, "a" ; \
18663+ 662: pushq %rax; nop; \
18664+ .popsection; \
18665+ .pushsection .altinstructions, "a" ; \
18666+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18667+ .popsection; \
18668+ call __pax_close_userland; \
18669+ popq %rax; \
18670+ 663:
18671+#else
18672+#define ASM_PAX_OPEN_USERLAND
18673+#define ASM_PAX_CLOSE_USERLAND
18674+#endif
18675+
18676 #ifdef CONFIG_X86_SMAP
18677
18678 #define ASM_CLAC \
18679 661: ASM_NOP3 ; \
18680- .pushsection .altinstr_replacement, "ax" ; \
18681+ .pushsection .altinstr_replacement, "a" ; \
18682 662: __ASM_CLAC ; \
18683 .popsection ; \
18684 .pushsection .altinstructions, "a" ; \
18685@@ -38,7 +67,7 @@
18686
18687 #define ASM_STAC \
18688 661: ASM_NOP3 ; \
18689- .pushsection .altinstr_replacement, "ax" ; \
18690+ .pushsection .altinstr_replacement, "a" ; \
18691 662: __ASM_STAC ; \
18692 .popsection ; \
18693 .pushsection .altinstructions, "a" ; \
18694@@ -56,6 +85,37 @@
18695
18696 #include <asm/alternative.h>
18697
18698+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18699+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18700+
18701+extern void __pax_open_userland(void);
18702+static __always_inline unsigned long pax_open_userland(void)
18703+{
18704+
18705+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18706+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18707+ :
18708+ : [open] "i" (__pax_open_userland)
18709+ : "memory", "rax");
18710+#endif
18711+
18712+ return 0;
18713+}
18714+
18715+extern void __pax_close_userland(void);
18716+static __always_inline unsigned long pax_close_userland(void)
18717+{
18718+
18719+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18720+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18721+ :
18722+ : [close] "i" (__pax_close_userland)
18723+ : "memory", "rax");
18724+#endif
18725+
18726+ return 0;
18727+}
18728+
18729 #ifdef CONFIG_X86_SMAP
18730
18731 static __always_inline void clac(void)
18732diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18733index 8cd27e0..7f05ec8 100644
18734--- a/arch/x86/include/asm/smp.h
18735+++ b/arch/x86/include/asm/smp.h
18736@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18737 /* cpus sharing the last level cache: */
18738 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18739 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18740-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18741+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18742
18743 static inline struct cpumask *cpu_sibling_mask(int cpu)
18744 {
18745@@ -78,7 +78,7 @@ struct smp_ops {
18746
18747 void (*send_call_func_ipi)(const struct cpumask *mask);
18748 void (*send_call_func_single_ipi)(int cpu);
18749-};
18750+} __no_const;
18751
18752 /* Globals due to paravirt */
18753 extern void set_cpu_sibling_map(int cpu);
18754@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18755 extern int safe_smp_processor_id(void);
18756
18757 #elif defined(CONFIG_X86_64_SMP)
18758-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18759-
18760-#define stack_smp_processor_id() \
18761-({ \
18762- struct thread_info *ti; \
18763- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18764- ti->cpu; \
18765-})
18766+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18767+#define stack_smp_processor_id() raw_smp_processor_id()
18768 #define safe_smp_processor_id() smp_processor_id()
18769
18770 #endif
18771diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18772index 0f62f54..cb5d0dd 100644
18773--- a/arch/x86/include/asm/spinlock.h
18774+++ b/arch/x86/include/asm/spinlock.h
18775@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18776 static inline void arch_read_lock(arch_rwlock_t *rw)
18777 {
18778 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18779+
18780+#ifdef CONFIG_PAX_REFCOUNT
18781+ "jno 0f\n"
18782+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18783+ "int $4\n0:\n"
18784+ _ASM_EXTABLE(0b, 0b)
18785+#endif
18786+
18787 "jns 1f\n"
18788 "call __read_lock_failed\n\t"
18789 "1:\n"
18790@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18791 static inline void arch_write_lock(arch_rwlock_t *rw)
18792 {
18793 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18794+
18795+#ifdef CONFIG_PAX_REFCOUNT
18796+ "jno 0f\n"
18797+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18798+ "int $4\n0:\n"
18799+ _ASM_EXTABLE(0b, 0b)
18800+#endif
18801+
18802 "jz 1f\n"
18803 "call __write_lock_failed\n\t"
18804 "1:\n"
18805@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18806
18807 static inline void arch_read_unlock(arch_rwlock_t *rw)
18808 {
18809- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18810+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18811+
18812+#ifdef CONFIG_PAX_REFCOUNT
18813+ "jno 0f\n"
18814+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18815+ "int $4\n0:\n"
18816+ _ASM_EXTABLE(0b, 0b)
18817+#endif
18818+
18819 :"+m" (rw->lock) : : "memory");
18820 }
18821
18822 static inline void arch_write_unlock(arch_rwlock_t *rw)
18823 {
18824- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18825+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18826+
18827+#ifdef CONFIG_PAX_REFCOUNT
18828+ "jno 0f\n"
18829+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18830+ "int $4\n0:\n"
18831+ _ASM_EXTABLE(0b, 0b)
18832+#endif
18833+
18834 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18835 }
18836
18837diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18838index 6a99859..03cb807 100644
18839--- a/arch/x86/include/asm/stackprotector.h
18840+++ b/arch/x86/include/asm/stackprotector.h
18841@@ -47,7 +47,7 @@
18842 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18843 */
18844 #define GDT_STACK_CANARY_INIT \
18845- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18846+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18847
18848 /*
18849 * Initialize the stackprotector canary value.
18850@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18851
18852 static inline void load_stack_canary_segment(void)
18853 {
18854-#ifdef CONFIG_X86_32
18855+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18856 asm volatile ("mov %0, %%gs" : : "r" (0));
18857 #endif
18858 }
18859diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18860index 70bbe39..4ae2bd4 100644
18861--- a/arch/x86/include/asm/stacktrace.h
18862+++ b/arch/x86/include/asm/stacktrace.h
18863@@ -11,28 +11,20 @@
18864
18865 extern int kstack_depth_to_print;
18866
18867-struct thread_info;
18868+struct task_struct;
18869 struct stacktrace_ops;
18870
18871-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18872- unsigned long *stack,
18873- unsigned long bp,
18874- const struct stacktrace_ops *ops,
18875- void *data,
18876- unsigned long *end,
18877- int *graph);
18878+typedef unsigned long walk_stack_t(struct task_struct *task,
18879+ void *stack_start,
18880+ unsigned long *stack,
18881+ unsigned long bp,
18882+ const struct stacktrace_ops *ops,
18883+ void *data,
18884+ unsigned long *end,
18885+ int *graph);
18886
18887-extern unsigned long
18888-print_context_stack(struct thread_info *tinfo,
18889- unsigned long *stack, unsigned long bp,
18890- const struct stacktrace_ops *ops, void *data,
18891- unsigned long *end, int *graph);
18892-
18893-extern unsigned long
18894-print_context_stack_bp(struct thread_info *tinfo,
18895- unsigned long *stack, unsigned long bp,
18896- const struct stacktrace_ops *ops, void *data,
18897- unsigned long *end, int *graph);
18898+extern walk_stack_t print_context_stack;
18899+extern walk_stack_t print_context_stack_bp;
18900
18901 /* Generic stack tracer with callbacks */
18902
18903@@ -40,7 +32,7 @@ struct stacktrace_ops {
18904 void (*address)(void *data, unsigned long address, int reliable);
18905 /* On negative return stop dumping */
18906 int (*stack)(void *data, char *name);
18907- walk_stack_t walk_stack;
18908+ walk_stack_t *walk_stack;
18909 };
18910
18911 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18912diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18913index d7f3b3b..3cc39f1 100644
18914--- a/arch/x86/include/asm/switch_to.h
18915+++ b/arch/x86/include/asm/switch_to.h
18916@@ -108,7 +108,7 @@ do { \
18917 "call __switch_to\n\t" \
18918 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18919 __switch_canary \
18920- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18921+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18922 "movq %%rax,%%rdi\n\t" \
18923 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18924 "jnz ret_from_fork\n\t" \
18925@@ -119,7 +119,7 @@ do { \
18926 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18927 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18928 [_tif_fork] "i" (_TIF_FORK), \
18929- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18930+ [thread_info] "m" (current_tinfo), \
18931 [current_task] "m" (current_task) \
18932 __switch_canary_iparam \
18933 : "memory", "cc" __EXTRA_CLOBBER)
18934diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18935index e1940c0..ac50dd8 100644
18936--- a/arch/x86/include/asm/thread_info.h
18937+++ b/arch/x86/include/asm/thread_info.h
18938@@ -10,6 +10,7 @@
18939 #include <linux/compiler.h>
18940 #include <asm/page.h>
18941 #include <asm/types.h>
18942+#include <asm/percpu.h>
18943
18944 /*
18945 * low level task data that entry.S needs immediate access to
18946@@ -23,7 +24,6 @@ struct exec_domain;
18947 #include <linux/atomic.h>
18948
18949 struct thread_info {
18950- struct task_struct *task; /* main task structure */
18951 struct exec_domain *exec_domain; /* execution domain */
18952 __u32 flags; /* low level flags */
18953 __u32 status; /* thread synchronous flags */
18954@@ -32,19 +32,13 @@ struct thread_info {
18955 mm_segment_t addr_limit;
18956 struct restart_block restart_block;
18957 void __user *sysenter_return;
18958-#ifdef CONFIG_X86_32
18959- unsigned long previous_esp; /* ESP of the previous stack in
18960- case of nested (IRQ) stacks
18961- */
18962- __u8 supervisor_stack[0];
18963-#endif
18964+ unsigned long lowest_stack;
18965 unsigned int sig_on_uaccess_error:1;
18966 unsigned int uaccess_err:1; /* uaccess failed */
18967 };
18968
18969-#define INIT_THREAD_INFO(tsk) \
18970+#define INIT_THREAD_INFO \
18971 { \
18972- .task = &tsk, \
18973 .exec_domain = &default_exec_domain, \
18974 .flags = 0, \
18975 .cpu = 0, \
18976@@ -55,7 +49,7 @@ struct thread_info {
18977 }, \
18978 }
18979
18980-#define init_thread_info (init_thread_union.thread_info)
18981+#define init_thread_info (init_thread_union.stack)
18982 #define init_stack (init_thread_union.stack)
18983
18984 #else /* !__ASSEMBLY__ */
18985@@ -95,6 +89,7 @@ struct thread_info {
18986 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18987 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18988 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18989+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18990
18991 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18992 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18993@@ -118,17 +113,18 @@ struct thread_info {
18994 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18995 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18996 #define _TIF_X32 (1 << TIF_X32)
18997+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18998
18999 /* work to do in syscall_trace_enter() */
19000 #define _TIF_WORK_SYSCALL_ENTRY \
19001 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19002 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19003- _TIF_NOHZ)
19004+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19005
19006 /* work to do in syscall_trace_leave() */
19007 #define _TIF_WORK_SYSCALL_EXIT \
19008 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19009- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19010+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19011
19012 /* work to do on interrupt/exception return */
19013 #define _TIF_WORK_MASK \
19014@@ -139,7 +135,7 @@ struct thread_info {
19015 /* work to do on any return to user space */
19016 #define _TIF_ALLWORK_MASK \
19017 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19018- _TIF_NOHZ)
19019+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19020
19021 /* Only used for 64 bit */
19022 #define _TIF_DO_NOTIFY_MASK \
19023@@ -153,6 +149,23 @@ struct thread_info {
19024 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19025 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19026
19027+#ifdef __ASSEMBLY__
19028+/* how to get the thread information struct from ASM */
19029+#define GET_THREAD_INFO(reg) \
19030+ mov PER_CPU_VAR(current_tinfo), reg
19031+
19032+/* use this one if reg already contains %esp */
19033+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19034+#else
19035+/* how to get the thread information struct from C */
19036+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19037+
19038+static __always_inline struct thread_info *current_thread_info(void)
19039+{
19040+ return this_cpu_read_stable(current_tinfo);
19041+}
19042+#endif
19043+
19044 #ifdef CONFIG_X86_32
19045
19046 #define STACK_WARN (THREAD_SIZE/8)
19047@@ -169,31 +182,10 @@ struct thread_info {
19048 sp; \
19049 })
19050
19051-/* how to get the thread information struct from C */
19052-static inline struct thread_info *current_thread_info(void)
19053-{
19054- return (struct thread_info *)
19055- (current_stack_pointer & ~(THREAD_SIZE - 1));
19056-}
19057-
19058-#else /* !__ASSEMBLY__ */
19059-
19060-/* how to get the thread information struct from ASM */
19061-#define GET_THREAD_INFO(reg) \
19062- movl $-THREAD_SIZE, reg; \
19063- andl %esp, reg
19064-
19065-/* use this one if reg already contains %esp */
19066-#define GET_THREAD_INFO_WITH_ESP(reg) \
19067- andl $-THREAD_SIZE, reg
19068-
19069 #endif
19070
19071 #else /* X86_32 */
19072
19073-#include <asm/percpu.h>
19074-#define KERNEL_STACK_OFFSET (5*8)
19075-
19076 /*
19077 * macros/functions for gaining access to the thread information structure
19078 * preempt_count needs to be 1 initially, until the scheduler is functional.
19079@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19080 #ifndef __ASSEMBLY__
19081 DECLARE_PER_CPU(unsigned long, kernel_stack);
19082
19083-static inline struct thread_info *current_thread_info(void)
19084-{
19085- struct thread_info *ti;
19086- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19087- KERNEL_STACK_OFFSET - THREAD_SIZE);
19088- return ti;
19089-}
19090-
19091-#else /* !__ASSEMBLY__ */
19092-
19093-/* how to get the thread information struct from ASM */
19094-#define GET_THREAD_INFO(reg) \
19095- movq PER_CPU_VAR(kernel_stack),reg ; \
19096- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19097-
19098-/*
19099- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19100- * a certain register (to be used in assembler memory operands).
19101- */
19102-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19103-
19104+/* how to get the current stack pointer from C */
19105+register unsigned long current_stack_pointer asm("rsp") __used;
19106 #endif
19107
19108 #endif /* !X86_32 */
19109@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19110 extern void arch_task_cache_init(void);
19111 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19112 extern void arch_release_task_struct(struct task_struct *tsk);
19113+
19114+#define __HAVE_THREAD_FUNCTIONS
19115+#define task_thread_info(task) (&(task)->tinfo)
19116+#define task_stack_page(task) ((task)->stack)
19117+#define setup_thread_stack(p, org) do {} while (0)
19118+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19119+
19120 #endif
19121 #endif /* _ASM_X86_THREAD_INFO_H */
19122diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19123index 04905bf..49203ca 100644
19124--- a/arch/x86/include/asm/tlbflush.h
19125+++ b/arch/x86/include/asm/tlbflush.h
19126@@ -17,18 +17,44 @@
19127
19128 static inline void __native_flush_tlb(void)
19129 {
19130+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19131+ u64 descriptor[2];
19132+
19133+ descriptor[0] = PCID_KERNEL;
19134+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19135+ return;
19136+ }
19137+
19138+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19139+ if (static_cpu_has(X86_FEATURE_PCID)) {
19140+ unsigned int cpu = raw_get_cpu();
19141+
19142+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19143+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19144+ raw_put_cpu_no_resched();
19145+ return;
19146+ }
19147+#endif
19148+
19149 native_write_cr3(native_read_cr3());
19150 }
19151
19152 static inline void __native_flush_tlb_global_irq_disabled(void)
19153 {
19154- unsigned long cr4;
19155+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19156+ u64 descriptor[2];
19157
19158- cr4 = native_read_cr4();
19159- /* clear PGE */
19160- native_write_cr4(cr4 & ~X86_CR4_PGE);
19161- /* write old PGE again and flush TLBs */
19162- native_write_cr4(cr4);
19163+ descriptor[0] = PCID_KERNEL;
19164+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19165+ } else {
19166+ unsigned long cr4;
19167+
19168+ cr4 = native_read_cr4();
19169+ /* clear PGE */
19170+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19171+ /* write old PGE again and flush TLBs */
19172+ native_write_cr4(cr4);
19173+ }
19174 }
19175
19176 static inline void __native_flush_tlb_global(void)
19177@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19178
19179 static inline void __native_flush_tlb_single(unsigned long addr)
19180 {
19181+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19182+ u64 descriptor[2];
19183+
19184+ descriptor[0] = PCID_KERNEL;
19185+ descriptor[1] = addr;
19186+
19187+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19188+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19189+ if (addr < TASK_SIZE_MAX)
19190+ descriptor[1] += pax_user_shadow_base;
19191+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19192+ }
19193+
19194+ descriptor[0] = PCID_USER;
19195+ descriptor[1] = addr;
19196+#endif
19197+
19198+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19199+ return;
19200+ }
19201+
19202+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19203+ if (static_cpu_has(X86_FEATURE_PCID)) {
19204+ unsigned int cpu = raw_get_cpu();
19205+
19206+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19207+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19208+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19209+ raw_put_cpu_no_resched();
19210+
19211+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19212+ addr += pax_user_shadow_base;
19213+ }
19214+#endif
19215+
19216 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19217 }
19218
19219diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19220index 0d592e0..f58a222 100644
19221--- a/arch/x86/include/asm/uaccess.h
19222+++ b/arch/x86/include/asm/uaccess.h
19223@@ -7,6 +7,7 @@
19224 #include <linux/compiler.h>
19225 #include <linux/thread_info.h>
19226 #include <linux/string.h>
19227+#include <linux/spinlock.h>
19228 #include <asm/asm.h>
19229 #include <asm/page.h>
19230 #include <asm/smap.h>
19231@@ -29,7 +30,12 @@
19232
19233 #define get_ds() (KERNEL_DS)
19234 #define get_fs() (current_thread_info()->addr_limit)
19235+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19236+void __set_fs(mm_segment_t x);
19237+void set_fs(mm_segment_t x);
19238+#else
19239 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19240+#endif
19241
19242 #define segment_eq(a, b) ((a).seg == (b).seg)
19243
19244@@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19245 * checks that the pointer is in the user space range - after calling
19246 * this function, memory access functions may still return -EFAULT.
19247 */
19248-#define access_ok(type, addr, size) \
19249- likely(!__range_not_ok(addr, size, user_addr_max()))
19250+extern int _cond_resched(void);
19251+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19252+#define access_ok(type, addr, size) \
19253+({ \
19254+ long __size = size; \
19255+ unsigned long __addr = (unsigned long)addr; \
19256+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19257+ unsigned long __end_ao = __addr + __size - 1; \
19258+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19259+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19260+ while(__addr_ao <= __end_ao) { \
19261+ char __c_ao; \
19262+ __addr_ao += PAGE_SIZE; \
19263+ if (__size > PAGE_SIZE) \
19264+ _cond_resched(); \
19265+ if (__get_user(__c_ao, (char __user *)__addr)) \
19266+ break; \
19267+ if (type != VERIFY_WRITE) { \
19268+ __addr = __addr_ao; \
19269+ continue; \
19270+ } \
19271+ if (__put_user(__c_ao, (char __user *)__addr)) \
19272+ break; \
19273+ __addr = __addr_ao; \
19274+ } \
19275+ } \
19276+ __ret_ao; \
19277+})
19278
19279 /*
19280 * The exception table consists of pairs of addresses relative to the
19281@@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19282 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19283 __chk_user_ptr(ptr); \
19284 might_fault(); \
19285+ pax_open_userland(); \
19286 asm volatile("call __get_user_%P3" \
19287 : "=a" (__ret_gu), "=r" (__val_gu) \
19288 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19289 (x) = (__typeof__(*(ptr))) __val_gu; \
19290+ pax_close_userland(); \
19291 __ret_gu; \
19292 })
19293
19294@@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19295 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19296 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19297
19298-
19299+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19300+#define __copyuser_seg "gs;"
19301+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19302+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19303+#else
19304+#define __copyuser_seg
19305+#define __COPYUSER_SET_ES
19306+#define __COPYUSER_RESTORE_ES
19307+#endif
19308
19309 #ifdef CONFIG_X86_32
19310 #define __put_user_asm_u64(x, addr, err, errret) \
19311 asm volatile(ASM_STAC "\n" \
19312- "1: movl %%eax,0(%2)\n" \
19313- "2: movl %%edx,4(%2)\n" \
19314+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19315+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19316 "3: " ASM_CLAC "\n" \
19317 ".section .fixup,\"ax\"\n" \
19318 "4: movl %3,%0\n" \
19319@@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19320
19321 #define __put_user_asm_ex_u64(x, addr) \
19322 asm volatile(ASM_STAC "\n" \
19323- "1: movl %%eax,0(%1)\n" \
19324- "2: movl %%edx,4(%1)\n" \
19325+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19326+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19327 "3: " ASM_CLAC "\n" \
19328 _ASM_EXTABLE_EX(1b, 2b) \
19329 _ASM_EXTABLE_EX(2b, 3b) \
19330@@ -257,7 +299,8 @@ extern void __put_user_8(void);
19331 __typeof__(*(ptr)) __pu_val; \
19332 __chk_user_ptr(ptr); \
19333 might_fault(); \
19334- __pu_val = x; \
19335+ __pu_val = (x); \
19336+ pax_open_userland(); \
19337 switch (sizeof(*(ptr))) { \
19338 case 1: \
19339 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19340@@ -275,6 +318,7 @@ extern void __put_user_8(void);
19341 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19342 break; \
19343 } \
19344+ pax_close_userland(); \
19345 __ret_pu; \
19346 })
19347
19348@@ -355,8 +399,10 @@ do { \
19349 } while (0)
19350
19351 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19352+do { \
19353+ pax_open_userland(); \
19354 asm volatile(ASM_STAC "\n" \
19355- "1: mov"itype" %2,%"rtype"1\n" \
19356+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19357 "2: " ASM_CLAC "\n" \
19358 ".section .fixup,\"ax\"\n" \
19359 "3: mov %3,%0\n" \
19360@@ -364,8 +410,10 @@ do { \
19361 " jmp 2b\n" \
19362 ".previous\n" \
19363 _ASM_EXTABLE(1b, 3b) \
19364- : "=r" (err), ltype(x) \
19365- : "m" (__m(addr)), "i" (errret), "0" (err))
19366+ : "=r" (err), ltype (x) \
19367+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19368+ pax_close_userland(); \
19369+} while (0)
19370
19371 #define __get_user_size_ex(x, ptr, size) \
19372 do { \
19373@@ -389,7 +437,7 @@ do { \
19374 } while (0)
19375
19376 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19377- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19378+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19379 "2:\n" \
19380 _ASM_EXTABLE_EX(1b, 2b) \
19381 : ltype(x) : "m" (__m(addr)))
19382@@ -406,13 +454,24 @@ do { \
19383 int __gu_err; \
19384 unsigned long __gu_val; \
19385 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19386- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19387+ (x) = (__typeof__(*(ptr)))__gu_val; \
19388 __gu_err; \
19389 })
19390
19391 /* FIXME: this hack is definitely wrong -AK */
19392 struct __large_struct { unsigned long buf[100]; };
19393-#define __m(x) (*(struct __large_struct __user *)(x))
19394+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19395+#define ____m(x) \
19396+({ \
19397+ unsigned long ____x = (unsigned long)(x); \
19398+ if (____x < pax_user_shadow_base) \
19399+ ____x += pax_user_shadow_base; \
19400+ (typeof(x))____x; \
19401+})
19402+#else
19403+#define ____m(x) (x)
19404+#endif
19405+#define __m(x) (*(struct __large_struct __user *)____m(x))
19406
19407 /*
19408 * Tell gcc we read from memory instead of writing: this is because
19409@@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19410 * aliasing issues.
19411 */
19412 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19413+do { \
19414+ pax_open_userland(); \
19415 asm volatile(ASM_STAC "\n" \
19416- "1: mov"itype" %"rtype"1,%2\n" \
19417+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19418 "2: " ASM_CLAC "\n" \
19419 ".section .fixup,\"ax\"\n" \
19420 "3: mov %3,%0\n" \
19421@@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19422 ".previous\n" \
19423 _ASM_EXTABLE(1b, 3b) \
19424 : "=r"(err) \
19425- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19426+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19427+ pax_close_userland(); \
19428+} while (0)
19429
19430 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19431- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19432+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19433 "2:\n" \
19434 _ASM_EXTABLE_EX(1b, 2b) \
19435 : : ltype(x), "m" (__m(addr)))
19436@@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19437 */
19438 #define uaccess_try do { \
19439 current_thread_info()->uaccess_err = 0; \
19440+ pax_open_userland(); \
19441 stac(); \
19442 barrier();
19443
19444 #define uaccess_catch(err) \
19445 clac(); \
19446+ pax_close_userland(); \
19447 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19448 } while (0)
19449
19450@@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19451 * On error, the variable @x is set to zero.
19452 */
19453
19454+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19455+#define __get_user(x, ptr) get_user((x), (ptr))
19456+#else
19457 #define __get_user(x, ptr) \
19458 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19459+#endif
19460
19461 /**
19462 * __put_user: - Write a simple value into user space, with less checking.
19463@@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19464 * Returns zero on success, or -EFAULT on error.
19465 */
19466
19467+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19468+#define __put_user(x, ptr) put_user((x), (ptr))
19469+#else
19470 #define __put_user(x, ptr) \
19471 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19472+#endif
19473
19474 #define __get_user_unaligned __get_user
19475 #define __put_user_unaligned __put_user
19476@@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19477 #define get_user_ex(x, ptr) do { \
19478 unsigned long __gue_val; \
19479 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19480- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19481+ (x) = (__typeof__(*(ptr)))__gue_val; \
19482 } while (0)
19483
19484 #define put_user_try uaccess_try
19485@@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19486 __typeof__(ptr) __uval = (uval); \
19487 __typeof__(*(ptr)) __old = (old); \
19488 __typeof__(*(ptr)) __new = (new); \
19489+ pax_open_userland(); \
19490 switch (size) { \
19491 case 1: \
19492 { \
19493 asm volatile("\t" ASM_STAC "\n" \
19494- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19495+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19496 "2:\t" ASM_CLAC "\n" \
19497 "\t.section .fixup, \"ax\"\n" \
19498 "3:\tmov %3, %0\n" \
19499 "\tjmp 2b\n" \
19500 "\t.previous\n" \
19501 _ASM_EXTABLE(1b, 3b) \
19502- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19503+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19504 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19505 : "memory" \
19506 ); \
19507@@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19508 case 2: \
19509 { \
19510 asm volatile("\t" ASM_STAC "\n" \
19511- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19512+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19513 "2:\t" ASM_CLAC "\n" \
19514 "\t.section .fixup, \"ax\"\n" \
19515 "3:\tmov %3, %0\n" \
19516 "\tjmp 2b\n" \
19517 "\t.previous\n" \
19518 _ASM_EXTABLE(1b, 3b) \
19519- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19520+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19521 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19522 : "memory" \
19523 ); \
19524@@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19525 case 4: \
19526 { \
19527 asm volatile("\t" ASM_STAC "\n" \
19528- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19529+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19530 "2:\t" ASM_CLAC "\n" \
19531 "\t.section .fixup, \"ax\"\n" \
19532 "3:\tmov %3, %0\n" \
19533 "\tjmp 2b\n" \
19534 "\t.previous\n" \
19535 _ASM_EXTABLE(1b, 3b) \
19536- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19537+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19538 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19539 : "memory" \
19540 ); \
19541@@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19542 __cmpxchg_wrong_size(); \
19543 \
19544 asm volatile("\t" ASM_STAC "\n" \
19545- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19546+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19547 "2:\t" ASM_CLAC "\n" \
19548 "\t.section .fixup, \"ax\"\n" \
19549 "3:\tmov %3, %0\n" \
19550 "\tjmp 2b\n" \
19551 "\t.previous\n" \
19552 _ASM_EXTABLE(1b, 3b) \
19553- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19554+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19555 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19556 : "memory" \
19557 ); \
19558@@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19559 default: \
19560 __cmpxchg_wrong_size(); \
19561 } \
19562+ pax_close_userland(); \
19563 *__uval = __old; \
19564 __ret; \
19565 })
19566@@ -636,17 +711,6 @@ extern struct movsl_mask {
19567
19568 #define ARCH_HAS_NOCACHE_UACCESS 1
19569
19570-#ifdef CONFIG_X86_32
19571-# include <asm/uaccess_32.h>
19572-#else
19573-# include <asm/uaccess_64.h>
19574-#endif
19575-
19576-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19577- unsigned n);
19578-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19579- unsigned n);
19580-
19581 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19582 # define copy_user_diag __compiletime_error
19583 #else
19584@@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19585 extern void copy_user_diag("copy_from_user() buffer size is too small")
19586 copy_from_user_overflow(void);
19587 extern void copy_user_diag("copy_to_user() buffer size is too small")
19588-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19589+copy_to_user_overflow(void);
19590
19591 #undef copy_user_diag
19592
19593@@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19594
19595 extern void
19596 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19597-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19598+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19599 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19600
19601 #else
19602@@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19603
19604 #endif
19605
19606+#ifdef CONFIG_X86_32
19607+# include <asm/uaccess_32.h>
19608+#else
19609+# include <asm/uaccess_64.h>
19610+#endif
19611+
19612 static inline unsigned long __must_check
19613 copy_from_user(void *to, const void __user *from, unsigned long n)
19614 {
19615- int sz = __compiletime_object_size(to);
19616+ size_t sz = __compiletime_object_size(to);
19617
19618 might_fault();
19619
19620@@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19621 * case, and do only runtime checking for non-constant sizes.
19622 */
19623
19624- if (likely(sz < 0 || sz >= n))
19625- n = _copy_from_user(to, from, n);
19626- else if(__builtin_constant_p(n))
19627- copy_from_user_overflow();
19628- else
19629- __copy_from_user_overflow(sz, n);
19630+ if (likely(sz != (size_t)-1 && sz < n)) {
19631+ if(__builtin_constant_p(n))
19632+ copy_from_user_overflow();
19633+ else
19634+ __copy_from_user_overflow(sz, n);
19635+ } if (access_ok(VERIFY_READ, from, n))
19636+ n = __copy_from_user(to, from, n);
19637+ else if ((long)n > 0)
19638+ memset(to, 0, n);
19639
19640 return n;
19641 }
19642@@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19643 static inline unsigned long __must_check
19644 copy_to_user(void __user *to, const void *from, unsigned long n)
19645 {
19646- int sz = __compiletime_object_size(from);
19647+ size_t sz = __compiletime_object_size(from);
19648
19649 might_fault();
19650
19651 /* See the comment in copy_from_user() above. */
19652- if (likely(sz < 0 || sz >= n))
19653- n = _copy_to_user(to, from, n);
19654- else if(__builtin_constant_p(n))
19655- copy_to_user_overflow();
19656- else
19657- __copy_to_user_overflow(sz, n);
19658+ if (likely(sz != (size_t)-1 && sz < n)) {
19659+ if(__builtin_constant_p(n))
19660+ copy_to_user_overflow();
19661+ else
19662+ __copy_to_user_overflow(sz, n);
19663+ } else if (access_ok(VERIFY_WRITE, to, n))
19664+ n = __copy_to_user(to, from, n);
19665
19666 return n;
19667 }
19668diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19669index 3c03a5d..1071638 100644
19670--- a/arch/x86/include/asm/uaccess_32.h
19671+++ b/arch/x86/include/asm/uaccess_32.h
19672@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19673 static __always_inline unsigned long __must_check
19674 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19675 {
19676+ if ((long)n < 0)
19677+ return n;
19678+
19679+ check_object_size(from, n, true);
19680+
19681 if (__builtin_constant_p(n)) {
19682 unsigned long ret;
19683
19684@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19685 __copy_to_user(void __user *to, const void *from, unsigned long n)
19686 {
19687 might_fault();
19688+
19689 return __copy_to_user_inatomic(to, from, n);
19690 }
19691
19692 static __always_inline unsigned long
19693 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19694 {
19695+ if ((long)n < 0)
19696+ return n;
19697+
19698 /* Avoid zeroing the tail if the copy fails..
19699 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19700 * but as the zeroing behaviour is only significant when n is not
19701@@ -137,6 +146,12 @@ static __always_inline unsigned long
19702 __copy_from_user(void *to, const void __user *from, unsigned long n)
19703 {
19704 might_fault();
19705+
19706+ if ((long)n < 0)
19707+ return n;
19708+
19709+ check_object_size(to, n, false);
19710+
19711 if (__builtin_constant_p(n)) {
19712 unsigned long ret;
19713
19714@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19715 const void __user *from, unsigned long n)
19716 {
19717 might_fault();
19718+
19719+ if ((long)n < 0)
19720+ return n;
19721+
19722 if (__builtin_constant_p(n)) {
19723 unsigned long ret;
19724
19725@@ -181,7 +200,10 @@ static __always_inline unsigned long
19726 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19727 unsigned long n)
19728 {
19729- return __copy_from_user_ll_nocache_nozero(to, from, n);
19730+ if ((long)n < 0)
19731+ return n;
19732+
19733+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19734 }
19735
19736 #endif /* _ASM_X86_UACCESS_32_H */
19737diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19738index 12a26b9..206c200 100644
19739--- a/arch/x86/include/asm/uaccess_64.h
19740+++ b/arch/x86/include/asm/uaccess_64.h
19741@@ -10,6 +10,9 @@
19742 #include <asm/alternative.h>
19743 #include <asm/cpufeature.h>
19744 #include <asm/page.h>
19745+#include <asm/pgtable.h>
19746+
19747+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19748
19749 /*
19750 * Copy To/From Userspace
19751@@ -17,14 +20,14 @@
19752
19753 /* Handles exceptions in both to and from, but doesn't do access_ok */
19754 __must_check unsigned long
19755-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19756+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19757 __must_check unsigned long
19758-copy_user_generic_string(void *to, const void *from, unsigned len);
19759+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19760 __must_check unsigned long
19761-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19762+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19763
19764 static __always_inline __must_check unsigned long
19765-copy_user_generic(void *to, const void *from, unsigned len)
19766+copy_user_generic(void *to, const void *from, unsigned long len)
19767 {
19768 unsigned ret;
19769
19770@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19771 }
19772
19773 __must_check unsigned long
19774-copy_in_user(void __user *to, const void __user *from, unsigned len);
19775+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19776
19777 static __always_inline __must_check
19778-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19779+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19780 {
19781- int ret = 0;
19782+ size_t sz = __compiletime_object_size(dst);
19783+ unsigned ret = 0;
19784+
19785+ if (size > INT_MAX)
19786+ return size;
19787+
19788+ check_object_size(dst, size, false);
19789+
19790+#ifdef CONFIG_PAX_MEMORY_UDEREF
19791+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19792+ return size;
19793+#endif
19794+
19795+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19796+ if(__builtin_constant_p(size))
19797+ copy_from_user_overflow();
19798+ else
19799+ __copy_from_user_overflow(sz, size);
19800+ return size;
19801+ }
19802
19803 if (!__builtin_constant_p(size))
19804- return copy_user_generic(dst, (__force void *)src, size);
19805+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19806 switch (size) {
19807- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19808+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19809 ret, "b", "b", "=q", 1);
19810 return ret;
19811- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19812+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19813 ret, "w", "w", "=r", 2);
19814 return ret;
19815- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19816+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19817 ret, "l", "k", "=r", 4);
19818 return ret;
19819- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19820+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19821 ret, "q", "", "=r", 8);
19822 return ret;
19823 case 10:
19824- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19825+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19826 ret, "q", "", "=r", 10);
19827 if (unlikely(ret))
19828 return ret;
19829 __get_user_asm(*(u16 *)(8 + (char *)dst),
19830- (u16 __user *)(8 + (char __user *)src),
19831+ (const u16 __user *)(8 + (const char __user *)src),
19832 ret, "w", "w", "=r", 2);
19833 return ret;
19834 case 16:
19835- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19836+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19837 ret, "q", "", "=r", 16);
19838 if (unlikely(ret))
19839 return ret;
19840 __get_user_asm(*(u64 *)(8 + (char *)dst),
19841- (u64 __user *)(8 + (char __user *)src),
19842+ (const u64 __user *)(8 + (const char __user *)src),
19843 ret, "q", "", "=r", 8);
19844 return ret;
19845 default:
19846- return copy_user_generic(dst, (__force void *)src, size);
19847+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19848 }
19849 }
19850
19851 static __always_inline __must_check
19852-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19853+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19854 {
19855 might_fault();
19856 return __copy_from_user_nocheck(dst, src, size);
19857 }
19858
19859 static __always_inline __must_check
19860-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19861+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19862 {
19863- int ret = 0;
19864+ size_t sz = __compiletime_object_size(src);
19865+ unsigned ret = 0;
19866+
19867+ if (size > INT_MAX)
19868+ return size;
19869+
19870+ check_object_size(src, size, true);
19871+
19872+#ifdef CONFIG_PAX_MEMORY_UDEREF
19873+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19874+ return size;
19875+#endif
19876+
19877+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19878+ if(__builtin_constant_p(size))
19879+ copy_to_user_overflow();
19880+ else
19881+ __copy_to_user_overflow(sz, size);
19882+ return size;
19883+ }
19884
19885 if (!__builtin_constant_p(size))
19886- return copy_user_generic((__force void *)dst, src, size);
19887+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19888 switch (size) {
19889- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19890+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19891 ret, "b", "b", "iq", 1);
19892 return ret;
19893- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19894+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19895 ret, "w", "w", "ir", 2);
19896 return ret;
19897- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19898+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19899 ret, "l", "k", "ir", 4);
19900 return ret;
19901- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19902+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19903 ret, "q", "", "er", 8);
19904 return ret;
19905 case 10:
19906- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19907+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19908 ret, "q", "", "er", 10);
19909 if (unlikely(ret))
19910 return ret;
19911 asm("":::"memory");
19912- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19913+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19914 ret, "w", "w", "ir", 2);
19915 return ret;
19916 case 16:
19917- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19918+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19919 ret, "q", "", "er", 16);
19920 if (unlikely(ret))
19921 return ret;
19922 asm("":::"memory");
19923- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19924+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19925 ret, "q", "", "er", 8);
19926 return ret;
19927 default:
19928- return copy_user_generic((__force void *)dst, src, size);
19929+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19930 }
19931 }
19932
19933 static __always_inline __must_check
19934-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19935+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19936 {
19937 might_fault();
19938 return __copy_to_user_nocheck(dst, src, size);
19939 }
19940
19941 static __always_inline __must_check
19942-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19943+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19944 {
19945- int ret = 0;
19946+ unsigned ret = 0;
19947
19948 might_fault();
19949+
19950+ if (size > INT_MAX)
19951+ return size;
19952+
19953+#ifdef CONFIG_PAX_MEMORY_UDEREF
19954+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19955+ return size;
19956+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19957+ return size;
19958+#endif
19959+
19960 if (!__builtin_constant_p(size))
19961- return copy_user_generic((__force void *)dst,
19962- (__force void *)src, size);
19963+ return copy_user_generic((__force_kernel void *)____m(dst),
19964+ (__force_kernel const void *)____m(src), size);
19965 switch (size) {
19966 case 1: {
19967 u8 tmp;
19968- __get_user_asm(tmp, (u8 __user *)src,
19969+ __get_user_asm(tmp, (const u8 __user *)src,
19970 ret, "b", "b", "=q", 1);
19971 if (likely(!ret))
19972 __put_user_asm(tmp, (u8 __user *)dst,
19973@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19974 }
19975 case 2: {
19976 u16 tmp;
19977- __get_user_asm(tmp, (u16 __user *)src,
19978+ __get_user_asm(tmp, (const u16 __user *)src,
19979 ret, "w", "w", "=r", 2);
19980 if (likely(!ret))
19981 __put_user_asm(tmp, (u16 __user *)dst,
19982@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19983
19984 case 4: {
19985 u32 tmp;
19986- __get_user_asm(tmp, (u32 __user *)src,
19987+ __get_user_asm(tmp, (const u32 __user *)src,
19988 ret, "l", "k", "=r", 4);
19989 if (likely(!ret))
19990 __put_user_asm(tmp, (u32 __user *)dst,
19991@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19992 }
19993 case 8: {
19994 u64 tmp;
19995- __get_user_asm(tmp, (u64 __user *)src,
19996+ __get_user_asm(tmp, (const u64 __user *)src,
19997 ret, "q", "", "=r", 8);
19998 if (likely(!ret))
19999 __put_user_asm(tmp, (u64 __user *)dst,
20000@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20001 return ret;
20002 }
20003 default:
20004- return copy_user_generic((__force void *)dst,
20005- (__force void *)src, size);
20006+ return copy_user_generic((__force_kernel void *)____m(dst),
20007+ (__force_kernel const void *)____m(src), size);
20008 }
20009 }
20010
20011-static __must_check __always_inline int
20012-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20013+static __must_check __always_inline unsigned long
20014+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20015 {
20016 return __copy_from_user_nocheck(dst, src, size);
20017 }
20018
20019-static __must_check __always_inline int
20020-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20021+static __must_check __always_inline unsigned long
20022+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20023 {
20024 return __copy_to_user_nocheck(dst, src, size);
20025 }
20026
20027-extern long __copy_user_nocache(void *dst, const void __user *src,
20028- unsigned size, int zerorest);
20029+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20030+ unsigned long size, int zerorest);
20031
20032-static inline int
20033-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20034+static inline unsigned long
20035+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20036 {
20037 might_fault();
20038+
20039+ if (size > INT_MAX)
20040+ return size;
20041+
20042+#ifdef CONFIG_PAX_MEMORY_UDEREF
20043+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20044+ return size;
20045+#endif
20046+
20047 return __copy_user_nocache(dst, src, size, 1);
20048 }
20049
20050-static inline int
20051+static inline unsigned long
20052 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20053- unsigned size)
20054+ unsigned long size)
20055 {
20056+ if (size > INT_MAX)
20057+ return size;
20058+
20059+#ifdef CONFIG_PAX_MEMORY_UDEREF
20060+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20061+ return size;
20062+#endif
20063+
20064 return __copy_user_nocache(dst, src, size, 0);
20065 }
20066
20067 unsigned long
20068-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20069+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20070
20071 #endif /* _ASM_X86_UACCESS_64_H */
20072diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20073index 5b238981..77fdd78 100644
20074--- a/arch/x86/include/asm/word-at-a-time.h
20075+++ b/arch/x86/include/asm/word-at-a-time.h
20076@@ -11,7 +11,7 @@
20077 * and shift, for example.
20078 */
20079 struct word_at_a_time {
20080- const unsigned long one_bits, high_bits;
20081+ unsigned long one_bits, high_bits;
20082 };
20083
20084 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20085diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20086index e45e4da..44e8572 100644
20087--- a/arch/x86/include/asm/x86_init.h
20088+++ b/arch/x86/include/asm/x86_init.h
20089@@ -129,7 +129,7 @@ struct x86_init_ops {
20090 struct x86_init_timers timers;
20091 struct x86_init_iommu iommu;
20092 struct x86_init_pci pci;
20093-};
20094+} __no_const;
20095
20096 /**
20097 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20098@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20099 void (*setup_percpu_clockev)(void);
20100 void (*early_percpu_clock_init)(void);
20101 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20102-};
20103+} __no_const;
20104
20105 struct timespec;
20106
20107@@ -168,7 +168,7 @@ struct x86_platform_ops {
20108 void (*save_sched_clock_state)(void);
20109 void (*restore_sched_clock_state)(void);
20110 void (*apic_post_init)(void);
20111-};
20112+} __no_const;
20113
20114 struct pci_dev;
20115 struct msi_msg;
20116@@ -185,7 +185,7 @@ struct x86_msi_ops {
20117 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20118 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20119 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20120-};
20121+} __no_const;
20122
20123 struct IO_APIC_route_entry;
20124 struct io_apic_irq_attr;
20125@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20126 unsigned int destination, int vector,
20127 struct io_apic_irq_attr *attr);
20128 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20129-};
20130+} __no_const;
20131
20132 extern struct x86_init_ops x86_init;
20133 extern struct x86_cpuinit_ops x86_cpuinit;
20134diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20135index 3e276eb..2eb3c30 100644
20136--- a/arch/x86/include/asm/xen/page.h
20137+++ b/arch/x86/include/asm/xen/page.h
20138@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20139 extern struct page *m2p_find_override(unsigned long mfn);
20140 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20141
20142-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20143+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20144 {
20145 unsigned long mfn;
20146
20147diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20148index 6c1d741..39e6ecf 100644
20149--- a/arch/x86/include/asm/xsave.h
20150+++ b/arch/x86/include/asm/xsave.h
20151@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20152 if (unlikely(err))
20153 return -EFAULT;
20154
20155+ pax_open_userland();
20156 __asm__ __volatile__(ASM_STAC "\n"
20157- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20158+ "1:"
20159+ __copyuser_seg
20160+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20161 "2: " ASM_CLAC "\n"
20162 ".section .fixup,\"ax\"\n"
20163 "3: movl $-1,%[err]\n"
20164@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20165 : [err] "=r" (err)
20166 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20167 : "memory");
20168+ pax_close_userland();
20169 return err;
20170 }
20171
20172 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20173 {
20174 int err;
20175- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20176+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20177 u32 lmask = mask;
20178 u32 hmask = mask >> 32;
20179
20180+ pax_open_userland();
20181 __asm__ __volatile__(ASM_STAC "\n"
20182- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20183+ "1:"
20184+ __copyuser_seg
20185+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20186 "2: " ASM_CLAC "\n"
20187 ".section .fixup,\"ax\"\n"
20188 "3: movl $-1,%[err]\n"
20189@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20190 : [err] "=r" (err)
20191 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20192 : "memory"); /* memory required? */
20193+ pax_close_userland();
20194 return err;
20195 }
20196
20197diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20198index bbae024..e1528f9 100644
20199--- a/arch/x86/include/uapi/asm/e820.h
20200+++ b/arch/x86/include/uapi/asm/e820.h
20201@@ -63,7 +63,7 @@ struct e820map {
20202 #define ISA_START_ADDRESS 0xa0000
20203 #define ISA_END_ADDRESS 0x100000
20204
20205-#define BIOS_BEGIN 0x000a0000
20206+#define BIOS_BEGIN 0x000c0000
20207 #define BIOS_END 0x00100000
20208
20209 #define BIOS_ROM_BASE 0xffe00000
20210diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20211index 7b0a55a..ad115bf 100644
20212--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20213+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20214@@ -49,7 +49,6 @@
20215 #define EFLAGS 144
20216 #define RSP 152
20217 #define SS 160
20218-#define ARGOFFSET R11
20219 #endif /* __ASSEMBLY__ */
20220
20221 /* top of stack page */
20222diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20223index cb648c8..91cb07e 100644
20224--- a/arch/x86/kernel/Makefile
20225+++ b/arch/x86/kernel/Makefile
20226@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20227 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20228 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20229 obj-y += probe_roms.o
20230-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20231+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20232 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20233 obj-y += syscall_$(BITS).o
20234 obj-$(CONFIG_X86_64) += vsyscall_64.o
20235diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20236index 1dac942..19c8b0c 100644
20237--- a/arch/x86/kernel/acpi/boot.c
20238+++ b/arch/x86/kernel/acpi/boot.c
20239@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20240 * If your system is blacklisted here, but you find that acpi=force
20241 * works for you, please contact linux-acpi@vger.kernel.org
20242 */
20243-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20244+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20245 /*
20246 * Boxes that need ACPI disabled
20247 */
20248@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20249 };
20250
20251 /* second table for DMI checks that should run after early-quirks */
20252-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20253+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20254 /*
20255 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20256 * which includes some code which overrides all temperature
20257diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20258index 3a2ae4c..9db31d6 100644
20259--- a/arch/x86/kernel/acpi/sleep.c
20260+++ b/arch/x86/kernel/acpi/sleep.c
20261@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20262 #else /* CONFIG_64BIT */
20263 #ifdef CONFIG_SMP
20264 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20265+
20266+ pax_open_kernel();
20267 early_gdt_descr.address =
20268 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20269+ pax_close_kernel();
20270+
20271 initial_gs = per_cpu_offset(smp_processor_id());
20272 #endif
20273 initial_code = (unsigned long)wakeup_long64;
20274diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20275index 665c6b7..eae4d56 100644
20276--- a/arch/x86/kernel/acpi/wakeup_32.S
20277+++ b/arch/x86/kernel/acpi/wakeup_32.S
20278@@ -29,13 +29,11 @@ wakeup_pmode_return:
20279 # and restore the stack ... but you need gdt for this to work
20280 movl saved_context_esp, %esp
20281
20282- movl %cs:saved_magic, %eax
20283- cmpl $0x12345678, %eax
20284+ cmpl $0x12345678, saved_magic
20285 jne bogus_magic
20286
20287 # jump to place where we left off
20288- movl saved_eip, %eax
20289- jmp *%eax
20290+ jmp *(saved_eip)
20291
20292 bogus_magic:
20293 jmp bogus_magic
20294diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20295index df94598..f3b29bf 100644
20296--- a/arch/x86/kernel/alternative.c
20297+++ b/arch/x86/kernel/alternative.c
20298@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20299 */
20300 for (a = start; a < end; a++) {
20301 instr = (u8 *)&a->instr_offset + a->instr_offset;
20302+
20303+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20304+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20305+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20306+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20307+#endif
20308+
20309 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20310 BUG_ON(a->replacementlen > a->instrlen);
20311 BUG_ON(a->instrlen > sizeof(insnbuf));
20312@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20313 for (poff = start; poff < end; poff++) {
20314 u8 *ptr = (u8 *)poff + *poff;
20315
20316+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20317+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20318+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20319+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20320+#endif
20321+
20322 if (!*poff || ptr < text || ptr >= text_end)
20323 continue;
20324 /* turn DS segment override prefix into lock prefix */
20325- if (*ptr == 0x3e)
20326+ if (*ktla_ktva(ptr) == 0x3e)
20327 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20328 }
20329 mutex_unlock(&text_mutex);
20330@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20331 for (poff = start; poff < end; poff++) {
20332 u8 *ptr = (u8 *)poff + *poff;
20333
20334+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20335+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20336+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20337+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20338+#endif
20339+
20340 if (!*poff || ptr < text || ptr >= text_end)
20341 continue;
20342 /* turn lock prefix into DS segment override prefix */
20343- if (*ptr == 0xf0)
20344+ if (*ktla_ktva(ptr) == 0xf0)
20345 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20346 }
20347 mutex_unlock(&text_mutex);
20348@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20349
20350 BUG_ON(p->len > MAX_PATCH_LEN);
20351 /* prep the buffer with the original instructions */
20352- memcpy(insnbuf, p->instr, p->len);
20353+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20354 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20355 (unsigned long)p->instr, p->len);
20356
20357@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20358 if (!uniproc_patched || num_possible_cpus() == 1)
20359 free_init_pages("SMP alternatives",
20360 (unsigned long)__smp_locks,
20361- (unsigned long)__smp_locks_end);
20362+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20363 #endif
20364
20365 apply_paravirt(__parainstructions, __parainstructions_end);
20366@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20367 * instructions. And on the local CPU you need to be protected again NMI or MCE
20368 * handlers seeing an inconsistent instruction while you patch.
20369 */
20370-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20371+void *__kprobes text_poke_early(void *addr, const void *opcode,
20372 size_t len)
20373 {
20374 unsigned long flags;
20375 local_irq_save(flags);
20376- memcpy(addr, opcode, len);
20377+
20378+ pax_open_kernel();
20379+ memcpy(ktla_ktva(addr), opcode, len);
20380 sync_core();
20381+ pax_close_kernel();
20382+
20383 local_irq_restore(flags);
20384 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20385 that causes hangs on some VIA CPUs. */
20386@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20387 */
20388 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20389 {
20390- unsigned long flags;
20391- char *vaddr;
20392+ unsigned char *vaddr = ktla_ktva(addr);
20393 struct page *pages[2];
20394- int i;
20395+ size_t i;
20396
20397 if (!core_kernel_text((unsigned long)addr)) {
20398- pages[0] = vmalloc_to_page(addr);
20399- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20400+ pages[0] = vmalloc_to_page(vaddr);
20401+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20402 } else {
20403- pages[0] = virt_to_page(addr);
20404+ pages[0] = virt_to_page(vaddr);
20405 WARN_ON(!PageReserved(pages[0]));
20406- pages[1] = virt_to_page(addr + PAGE_SIZE);
20407+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20408 }
20409 BUG_ON(!pages[0]);
20410- local_irq_save(flags);
20411- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20412- if (pages[1])
20413- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20414- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20415- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20416- clear_fixmap(FIX_TEXT_POKE0);
20417- if (pages[1])
20418- clear_fixmap(FIX_TEXT_POKE1);
20419- local_flush_tlb();
20420- sync_core();
20421- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20422- that causes hangs on some VIA CPUs. */
20423+ text_poke_early(addr, opcode, len);
20424 for (i = 0; i < len; i++)
20425- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20426- local_irq_restore(flags);
20427+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20428 return addr;
20429 }
20430
20431@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20432 if (likely(!bp_patching_in_progress))
20433 return 0;
20434
20435- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20436+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20437 return 0;
20438
20439 /* set up the specified breakpoint handler */
20440@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20441 */
20442 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20443 {
20444- unsigned char int3 = 0xcc;
20445+ const unsigned char int3 = 0xcc;
20446
20447 bp_int3_handler = handler;
20448 bp_int3_addr = (u8 *)addr + sizeof(int3);
20449diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20450index 7f26c9a..694544e 100644
20451--- a/arch/x86/kernel/apic/apic.c
20452+++ b/arch/x86/kernel/apic/apic.c
20453@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20454 /*
20455 * Debug level, exported for io_apic.c
20456 */
20457-unsigned int apic_verbosity;
20458+int apic_verbosity;
20459
20460 int pic_mode;
20461
20462@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20463 apic_write(APIC_ESR, 0);
20464 v = apic_read(APIC_ESR);
20465 ack_APIC_irq();
20466- atomic_inc(&irq_err_count);
20467+ atomic_inc_unchecked(&irq_err_count);
20468
20469 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20470 smp_processor_id(), v);
20471diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20472index 2c621a6..fa2b1ae 100644
20473--- a/arch/x86/kernel/apic/apic_flat_64.c
20474+++ b/arch/x86/kernel/apic/apic_flat_64.c
20475@@ -154,7 +154,7 @@ static int flat_probe(void)
20476 return 1;
20477 }
20478
20479-static struct apic apic_flat = {
20480+static struct apic apic_flat __read_only = {
20481 .name = "flat",
20482 .probe = flat_probe,
20483 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20484@@ -268,7 +268,7 @@ static int physflat_probe(void)
20485 return 0;
20486 }
20487
20488-static struct apic apic_physflat = {
20489+static struct apic apic_physflat __read_only = {
20490
20491 .name = "physical flat",
20492 .probe = physflat_probe,
20493diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20494index 191ce75..2db6d63 100644
20495--- a/arch/x86/kernel/apic/apic_noop.c
20496+++ b/arch/x86/kernel/apic/apic_noop.c
20497@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20498 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20499 }
20500
20501-struct apic apic_noop = {
20502+struct apic apic_noop __read_only = {
20503 .name = "noop",
20504 .probe = noop_probe,
20505 .acpi_madt_oem_check = NULL,
20506diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20507index d50e364..543bee3 100644
20508--- a/arch/x86/kernel/apic/bigsmp_32.c
20509+++ b/arch/x86/kernel/apic/bigsmp_32.c
20510@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20511 return dmi_bigsmp;
20512 }
20513
20514-static struct apic apic_bigsmp = {
20515+static struct apic apic_bigsmp __read_only = {
20516
20517 .name = "bigsmp",
20518 .probe = probe_bigsmp,
20519diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20520index c552247..587a316 100644
20521--- a/arch/x86/kernel/apic/es7000_32.c
20522+++ b/arch/x86/kernel/apic/es7000_32.c
20523@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20524 return ret && es7000_apic_is_cluster();
20525 }
20526
20527-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20528-static struct apic __refdata apic_es7000_cluster = {
20529+static struct apic apic_es7000_cluster __read_only = {
20530
20531 .name = "es7000",
20532 .probe = probe_es7000,
20533@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20534 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20535 };
20536
20537-static struct apic __refdata apic_es7000 = {
20538+static struct apic apic_es7000 __read_only = {
20539
20540 .name = "es7000",
20541 .probe = probe_es7000,
20542diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20543index 6ad4658..38a7b5c 100644
20544--- a/arch/x86/kernel/apic/io_apic.c
20545+++ b/arch/x86/kernel/apic/io_apic.c
20546@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20547 }
20548 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20549
20550-void lock_vector_lock(void)
20551+void lock_vector_lock(void) __acquires(vector_lock)
20552 {
20553 /* Used to the online set of cpus does not change
20554 * during assign_irq_vector.
20555@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20556 raw_spin_lock(&vector_lock);
20557 }
20558
20559-void unlock_vector_lock(void)
20560+void unlock_vector_lock(void) __releases(vector_lock)
20561 {
20562 raw_spin_unlock(&vector_lock);
20563 }
20564@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20565 ack_APIC_irq();
20566 }
20567
20568-atomic_t irq_mis_count;
20569+atomic_unchecked_t irq_mis_count;
20570
20571 #ifdef CONFIG_GENERIC_PENDING_IRQ
20572 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20573@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20574 * at the cpu.
20575 */
20576 if (!(v & (1 << (i & 0x1f)))) {
20577- atomic_inc(&irq_mis_count);
20578+ atomic_inc_unchecked(&irq_mis_count);
20579
20580 eoi_ioapic_irq(irq, cfg);
20581 }
20582diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20583index 1e42e8f..daacf44 100644
20584--- a/arch/x86/kernel/apic/numaq_32.c
20585+++ b/arch/x86/kernel/apic/numaq_32.c
20586@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20587 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20588 }
20589
20590-/* Use __refdata to keep false positive warning calm. */
20591-static struct apic __refdata apic_numaq = {
20592+static struct apic apic_numaq __read_only = {
20593
20594 .name = "NUMAQ",
20595 .probe = probe_numaq,
20596diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20597index eb35ef9..f184a21 100644
20598--- a/arch/x86/kernel/apic/probe_32.c
20599+++ b/arch/x86/kernel/apic/probe_32.c
20600@@ -72,7 +72,7 @@ static int probe_default(void)
20601 return 1;
20602 }
20603
20604-static struct apic apic_default = {
20605+static struct apic apic_default __read_only = {
20606
20607 .name = "default",
20608 .probe = probe_default,
20609diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20610index 00146f9..5e299b8 100644
20611--- a/arch/x86/kernel/apic/summit_32.c
20612+++ b/arch/x86/kernel/apic/summit_32.c
20613@@ -485,7 +485,7 @@ void setup_summit(void)
20614 }
20615 #endif
20616
20617-static struct apic apic_summit = {
20618+static struct apic apic_summit __read_only = {
20619
20620 .name = "summit",
20621 .probe = probe_summit,
20622diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20623index cac85ee..01fa741 100644
20624--- a/arch/x86/kernel/apic/x2apic_cluster.c
20625+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20626@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20627 return notifier_from_errno(err);
20628 }
20629
20630-static struct notifier_block __refdata x2apic_cpu_notifier = {
20631+static struct notifier_block x2apic_cpu_notifier = {
20632 .notifier_call = update_clusterinfo,
20633 };
20634
20635@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20636 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20637 }
20638
20639-static struct apic apic_x2apic_cluster = {
20640+static struct apic apic_x2apic_cluster __read_only = {
20641
20642 .name = "cluster x2apic",
20643 .probe = x2apic_cluster_probe,
20644diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20645index de231e3..1d1b2ee 100644
20646--- a/arch/x86/kernel/apic/x2apic_phys.c
20647+++ b/arch/x86/kernel/apic/x2apic_phys.c
20648@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20649 return apic == &apic_x2apic_phys;
20650 }
20651
20652-static struct apic apic_x2apic_phys = {
20653+static struct apic apic_x2apic_phys __read_only = {
20654
20655 .name = "physical x2apic",
20656 .probe = x2apic_phys_probe,
20657diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20658index d263b13..963258b 100644
20659--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20660+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20661@@ -350,7 +350,7 @@ static int uv_probe(void)
20662 return apic == &apic_x2apic_uv_x;
20663 }
20664
20665-static struct apic __refdata apic_x2apic_uv_x = {
20666+static struct apic apic_x2apic_uv_x __read_only = {
20667
20668 .name = "UV large system",
20669 .probe = uv_probe,
20670diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20671index 3ab0343..814c4787 100644
20672--- a/arch/x86/kernel/apm_32.c
20673+++ b/arch/x86/kernel/apm_32.c
20674@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20675 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20676 * even though they are called in protected mode.
20677 */
20678-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20679+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20680 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20681
20682 static const char driver_version[] = "1.16ac"; /* no spaces */
20683@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20684 BUG_ON(cpu != 0);
20685 gdt = get_cpu_gdt_table(cpu);
20686 save_desc_40 = gdt[0x40 / 8];
20687+
20688+ pax_open_kernel();
20689 gdt[0x40 / 8] = bad_bios_desc;
20690+ pax_close_kernel();
20691
20692 apm_irq_save(flags);
20693 APM_DO_SAVE_SEGS;
20694@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20695 &call->esi);
20696 APM_DO_RESTORE_SEGS;
20697 apm_irq_restore(flags);
20698+
20699+ pax_open_kernel();
20700 gdt[0x40 / 8] = save_desc_40;
20701+ pax_close_kernel();
20702+
20703 put_cpu();
20704
20705 return call->eax & 0xff;
20706@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20707 BUG_ON(cpu != 0);
20708 gdt = get_cpu_gdt_table(cpu);
20709 save_desc_40 = gdt[0x40 / 8];
20710+
20711+ pax_open_kernel();
20712 gdt[0x40 / 8] = bad_bios_desc;
20713+ pax_close_kernel();
20714
20715 apm_irq_save(flags);
20716 APM_DO_SAVE_SEGS;
20717@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20718 &call->eax);
20719 APM_DO_RESTORE_SEGS;
20720 apm_irq_restore(flags);
20721+
20722+ pax_open_kernel();
20723 gdt[0x40 / 8] = save_desc_40;
20724+ pax_close_kernel();
20725+
20726 put_cpu();
20727 return error;
20728 }
20729@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20730 * code to that CPU.
20731 */
20732 gdt = get_cpu_gdt_table(0);
20733+
20734+ pax_open_kernel();
20735 set_desc_base(&gdt[APM_CS >> 3],
20736 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20737 set_desc_base(&gdt[APM_CS_16 >> 3],
20738 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20739 set_desc_base(&gdt[APM_DS >> 3],
20740 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20741+ pax_close_kernel();
20742
20743 proc_create("apm", 0, NULL, &apm_file_ops);
20744
20745diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20746index 9f6b934..cf5ffb3 100644
20747--- a/arch/x86/kernel/asm-offsets.c
20748+++ b/arch/x86/kernel/asm-offsets.c
20749@@ -32,6 +32,8 @@ void common(void) {
20750 OFFSET(TI_flags, thread_info, flags);
20751 OFFSET(TI_status, thread_info, status);
20752 OFFSET(TI_addr_limit, thread_info, addr_limit);
20753+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20754+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20755
20756 BLANK();
20757 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20758@@ -52,8 +54,26 @@ void common(void) {
20759 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20760 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20761 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20762+
20763+#ifdef CONFIG_PAX_KERNEXEC
20764+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20765 #endif
20766
20767+#ifdef CONFIG_PAX_MEMORY_UDEREF
20768+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20769+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20770+#ifdef CONFIG_X86_64
20771+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20772+#endif
20773+#endif
20774+
20775+#endif
20776+
20777+ BLANK();
20778+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20779+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20780+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20781+
20782 #ifdef CONFIG_XEN
20783 BLANK();
20784 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20785diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20786index e7c798b..2b2019b 100644
20787--- a/arch/x86/kernel/asm-offsets_64.c
20788+++ b/arch/x86/kernel/asm-offsets_64.c
20789@@ -77,6 +77,7 @@ int main(void)
20790 BLANK();
20791 #undef ENTRY
20792
20793+ DEFINE(TSS_size, sizeof(struct tss_struct));
20794 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20795 BLANK();
20796
20797diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20798index 7fd54f0..0691410 100644
20799--- a/arch/x86/kernel/cpu/Makefile
20800+++ b/arch/x86/kernel/cpu/Makefile
20801@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20802 CFLAGS_REMOVE_perf_event.o = -pg
20803 endif
20804
20805-# Make sure load_percpu_segment has no stackprotector
20806-nostackp := $(call cc-option, -fno-stack-protector)
20807-CFLAGS_common.o := $(nostackp)
20808-
20809 obj-y := intel_cacheinfo.o scattered.o topology.o
20810 obj-y += proc.o capflags.o powerflags.o common.o
20811 obj-y += rdrand.o
20812diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20813index c67ffa6..f41fbbf 100644
20814--- a/arch/x86/kernel/cpu/amd.c
20815+++ b/arch/x86/kernel/cpu/amd.c
20816@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20817 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20818 {
20819 /* AMD errata T13 (order #21922) */
20820- if ((c->x86 == 6)) {
20821+ if (c->x86 == 6) {
20822 /* Duron Rev A0 */
20823 if (c->x86_model == 3 && c->x86_mask == 0)
20824 size = 64;
20825diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20826index 8e28bf2..bf5c0d2 100644
20827--- a/arch/x86/kernel/cpu/common.c
20828+++ b/arch/x86/kernel/cpu/common.c
20829@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20830
20831 static const struct cpu_dev *this_cpu = &default_cpu;
20832
20833-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20834-#ifdef CONFIG_X86_64
20835- /*
20836- * We need valid kernel segments for data and code in long mode too
20837- * IRET will check the segment types kkeil 2000/10/28
20838- * Also sysret mandates a special GDT layout
20839- *
20840- * TLS descriptors are currently at a different place compared to i386.
20841- * Hopefully nobody expects them at a fixed place (Wine?)
20842- */
20843- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20844- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20845- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20846- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20847- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20848- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20849-#else
20850- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20851- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20852- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20853- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20854- /*
20855- * Segments used for calling PnP BIOS have byte granularity.
20856- * They code segments and data segments have fixed 64k limits,
20857- * the transfer segment sizes are set at run time.
20858- */
20859- /* 32-bit code */
20860- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20861- /* 16-bit code */
20862- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20863- /* 16-bit data */
20864- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20865- /* 16-bit data */
20866- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20867- /* 16-bit data */
20868- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20869- /*
20870- * The APM segments have byte granularity and their bases
20871- * are set at run time. All have 64k limits.
20872- */
20873- /* 32-bit code */
20874- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20875- /* 16-bit code */
20876- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20877- /* data */
20878- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20879-
20880- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20881- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20882- GDT_STACK_CANARY_INIT
20883-#endif
20884-} };
20885-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20886-
20887 static int __init x86_xsave_setup(char *s)
20888 {
20889 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20890@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20891 }
20892 }
20893
20894+#ifdef CONFIG_X86_64
20895+static __init int setup_disable_pcid(char *arg)
20896+{
20897+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20898+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20899+
20900+#ifdef CONFIG_PAX_MEMORY_UDEREF
20901+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20902+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20903+#endif
20904+
20905+ return 1;
20906+}
20907+__setup("nopcid", setup_disable_pcid);
20908+
20909+static void setup_pcid(struct cpuinfo_x86 *c)
20910+{
20911+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20912+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20913+
20914+#ifdef CONFIG_PAX_MEMORY_UDEREF
20915+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20916+ pax_open_kernel();
20917+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20918+ pax_close_kernel();
20919+ printk("PAX: slow and weak UDEREF enabled\n");
20920+ } else
20921+ printk("PAX: UDEREF disabled\n");
20922+#endif
20923+
20924+ return;
20925+ }
20926+
20927+ printk("PAX: PCID detected\n");
20928+ set_in_cr4(X86_CR4_PCIDE);
20929+
20930+#ifdef CONFIG_PAX_MEMORY_UDEREF
20931+ pax_open_kernel();
20932+ clone_pgd_mask = ~(pgdval_t)0UL;
20933+ pax_close_kernel();
20934+ if (pax_user_shadow_base)
20935+ printk("PAX: weak UDEREF enabled\n");
20936+ else {
20937+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20938+ printk("PAX: strong UDEREF enabled\n");
20939+ }
20940+#endif
20941+
20942+ if (cpu_has(c, X86_FEATURE_INVPCID))
20943+ printk("PAX: INVPCID detected\n");
20944+}
20945+#endif
20946+
20947 /*
20948 * Some CPU features depend on higher CPUID levels, which may not always
20949 * be available due to CPUID level capping or broken virtualization
20950@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20951 {
20952 struct desc_ptr gdt_descr;
20953
20954- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20955+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20956 gdt_descr.size = GDT_SIZE - 1;
20957 load_gdt(&gdt_descr);
20958 /* Reload the per-cpu base */
20959@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20960 setup_smep(c);
20961 setup_smap(c);
20962
20963+#ifdef CONFIG_X86_64
20964+ setup_pcid(c);
20965+#endif
20966+
20967 /*
20968 * The vendor-specific functions might have changed features.
20969 * Now we do "generic changes."
20970@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20971 /* Filter out anything that depends on CPUID levels we don't have */
20972 filter_cpuid_features(c, true);
20973
20974+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20975+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20976+#endif
20977+
20978 /* If the model name is still unset, do table lookup. */
20979 if (!c->x86_model_id[0]) {
20980 const char *p;
20981@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
20982 }
20983 __setup("clearcpuid=", setup_disablecpuid);
20984
20985+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20986+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20987+
20988 #ifdef CONFIG_X86_64
20989-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20990-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20991- (unsigned long) debug_idt_table };
20992+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20993+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20994
20995 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20996 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20997@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20998 EXPORT_PER_CPU_SYMBOL(current_task);
20999
21000 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21001- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21002+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21003 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21004
21005 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21006@@ -1245,7 +1254,7 @@ void cpu_init(void)
21007 load_ucode_ap();
21008
21009 cpu = stack_smp_processor_id();
21010- t = &per_cpu(init_tss, cpu);
21011+ t = init_tss + cpu;
21012 oist = &per_cpu(orig_ist, cpu);
21013
21014 #ifdef CONFIG_NUMA
21015@@ -1280,7 +1289,6 @@ void cpu_init(void)
21016 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21017 barrier();
21018
21019- x86_configure_nx();
21020 enable_x2apic();
21021
21022 /*
21023@@ -1332,7 +1340,7 @@ void cpu_init(void)
21024 {
21025 int cpu = smp_processor_id();
21026 struct task_struct *curr = current;
21027- struct tss_struct *t = &per_cpu(init_tss, cpu);
21028+ struct tss_struct *t = init_tss + cpu;
21029 struct thread_struct *thread = &curr->thread;
21030
21031 show_ucode_info_early();
21032diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21033index 0641113..06f5ba4 100644
21034--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21035+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21036@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21037 };
21038
21039 #ifdef CONFIG_AMD_NB
21040+static struct attribute *default_attrs_amd_nb[] = {
21041+ &type.attr,
21042+ &level.attr,
21043+ &coherency_line_size.attr,
21044+ &physical_line_partition.attr,
21045+ &ways_of_associativity.attr,
21046+ &number_of_sets.attr,
21047+ &size.attr,
21048+ &shared_cpu_map.attr,
21049+ &shared_cpu_list.attr,
21050+ NULL,
21051+ NULL,
21052+ NULL,
21053+ NULL
21054+};
21055+
21056 static struct attribute **amd_l3_attrs(void)
21057 {
21058 static struct attribute **attrs;
21059@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21060
21061 n = ARRAY_SIZE(default_attrs);
21062
21063- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21064- n += 2;
21065-
21066- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21067- n += 1;
21068-
21069- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21070- if (attrs == NULL)
21071- return attrs = default_attrs;
21072-
21073- for (n = 0; default_attrs[n]; n++)
21074- attrs[n] = default_attrs[n];
21075+ attrs = default_attrs_amd_nb;
21076
21077 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21078 attrs[n++] = &cache_disable_0.attr;
21079@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21080 .default_attrs = default_attrs,
21081 };
21082
21083+#ifdef CONFIG_AMD_NB
21084+static struct kobj_type ktype_cache_amd_nb = {
21085+ .sysfs_ops = &sysfs_ops,
21086+ .default_attrs = default_attrs_amd_nb,
21087+};
21088+#endif
21089+
21090 static struct kobj_type ktype_percpu_entry = {
21091 .sysfs_ops = &sysfs_ops,
21092 };
21093@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21094 return retval;
21095 }
21096
21097+#ifdef CONFIG_AMD_NB
21098+ amd_l3_attrs();
21099+#endif
21100+
21101 for (i = 0; i < num_cache_leaves; i++) {
21102+ struct kobj_type *ktype;
21103+
21104 this_object = INDEX_KOBJECT_PTR(cpu, i);
21105 this_object->cpu = cpu;
21106 this_object->index = i;
21107
21108 this_leaf = CPUID4_INFO_IDX(cpu, i);
21109
21110- ktype_cache.default_attrs = default_attrs;
21111+ ktype = &ktype_cache;
21112 #ifdef CONFIG_AMD_NB
21113 if (this_leaf->base.nb)
21114- ktype_cache.default_attrs = amd_l3_attrs();
21115+ ktype = &ktype_cache_amd_nb;
21116 #endif
21117 retval = kobject_init_and_add(&(this_object->kobj),
21118- &ktype_cache,
21119+ ktype,
21120 per_cpu(ici_cache_kobject, cpu),
21121 "index%1lu", i);
21122 if (unlikely(retval)) {
21123diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21124index 4d5419b..95f11bb 100644
21125--- a/arch/x86/kernel/cpu/mcheck/mce.c
21126+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21127@@ -45,6 +45,7 @@
21128 #include <asm/processor.h>
21129 #include <asm/mce.h>
21130 #include <asm/msr.h>
21131+#include <asm/local.h>
21132
21133 #include "mce-internal.h"
21134
21135@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21136 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21137 m->cs, m->ip);
21138
21139- if (m->cs == __KERNEL_CS)
21140+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21141 print_symbol("{%s}", m->ip);
21142 pr_cont("\n");
21143 }
21144@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21145
21146 #define PANIC_TIMEOUT 5 /* 5 seconds */
21147
21148-static atomic_t mce_paniced;
21149+static atomic_unchecked_t mce_paniced;
21150
21151 static int fake_panic;
21152-static atomic_t mce_fake_paniced;
21153+static atomic_unchecked_t mce_fake_paniced;
21154
21155 /* Panic in progress. Enable interrupts and wait for final IPI */
21156 static void wait_for_panic(void)
21157@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21158 /*
21159 * Make sure only one CPU runs in machine check panic
21160 */
21161- if (atomic_inc_return(&mce_paniced) > 1)
21162+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21163 wait_for_panic();
21164 barrier();
21165
21166@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21167 console_verbose();
21168 } else {
21169 /* Don't log too much for fake panic */
21170- if (atomic_inc_return(&mce_fake_paniced) > 1)
21171+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21172 return;
21173 }
21174 /* First print corrected ones that are still unlogged */
21175@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21176 if (!fake_panic) {
21177 if (panic_timeout == 0)
21178 panic_timeout = mca_cfg.panic_timeout;
21179- panic(msg);
21180+ panic("%s", msg);
21181 } else
21182 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21183 }
21184@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21185 * might have been modified by someone else.
21186 */
21187 rmb();
21188- if (atomic_read(&mce_paniced))
21189+ if (atomic_read_unchecked(&mce_paniced))
21190 wait_for_panic();
21191 if (!mca_cfg.monarch_timeout)
21192 goto out;
21193@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21194 }
21195
21196 /* Call the installed machine check handler for this CPU setup. */
21197-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21198+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21199 unexpected_machine_check;
21200
21201 /*
21202@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21203 return;
21204 }
21205
21206+ pax_open_kernel();
21207 machine_check_vector = do_machine_check;
21208+ pax_close_kernel();
21209
21210 __mcheck_cpu_init_generic();
21211 __mcheck_cpu_init_vendor(c);
21212@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21213 */
21214
21215 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21216-static int mce_chrdev_open_count; /* #times opened */
21217+static local_t mce_chrdev_open_count; /* #times opened */
21218 static int mce_chrdev_open_exclu; /* already open exclusive? */
21219
21220 static int mce_chrdev_open(struct inode *inode, struct file *file)
21221@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21222 spin_lock(&mce_chrdev_state_lock);
21223
21224 if (mce_chrdev_open_exclu ||
21225- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21226+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21227 spin_unlock(&mce_chrdev_state_lock);
21228
21229 return -EBUSY;
21230@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21231
21232 if (file->f_flags & O_EXCL)
21233 mce_chrdev_open_exclu = 1;
21234- mce_chrdev_open_count++;
21235+ local_inc(&mce_chrdev_open_count);
21236
21237 spin_unlock(&mce_chrdev_state_lock);
21238
21239@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21240 {
21241 spin_lock(&mce_chrdev_state_lock);
21242
21243- mce_chrdev_open_count--;
21244+ local_dec(&mce_chrdev_open_count);
21245 mce_chrdev_open_exclu = 0;
21246
21247 spin_unlock(&mce_chrdev_state_lock);
21248@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21249
21250 for (i = 0; i < mca_cfg.banks; i++) {
21251 struct mce_bank *b = &mce_banks[i];
21252- struct device_attribute *a = &b->attr;
21253+ device_attribute_no_const *a = &b->attr;
21254
21255 sysfs_attr_init(&a->attr);
21256 a->attr.name = b->attrname;
21257@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21258 static void mce_reset(void)
21259 {
21260 cpu_missing = 0;
21261- atomic_set(&mce_fake_paniced, 0);
21262+ atomic_set_unchecked(&mce_fake_paniced, 0);
21263 atomic_set(&mce_executing, 0);
21264 atomic_set(&mce_callin, 0);
21265 atomic_set(&global_nwo, 0);
21266diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21267index a304298..49b6d06 100644
21268--- a/arch/x86/kernel/cpu/mcheck/p5.c
21269+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21270@@ -10,6 +10,7 @@
21271 #include <asm/processor.h>
21272 #include <asm/mce.h>
21273 #include <asm/msr.h>
21274+#include <asm/pgtable.h>
21275
21276 /* By default disabled */
21277 int mce_p5_enabled __read_mostly;
21278@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21279 if (!cpu_has(c, X86_FEATURE_MCE))
21280 return;
21281
21282+ pax_open_kernel();
21283 machine_check_vector = pentium_machine_check;
21284+ pax_close_kernel();
21285 /* Make sure the vector pointer is visible before we enable MCEs: */
21286 wmb();
21287
21288diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21289index 7dc5564..1273569 100644
21290--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21291+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21292@@ -9,6 +9,7 @@
21293 #include <asm/processor.h>
21294 #include <asm/mce.h>
21295 #include <asm/msr.h>
21296+#include <asm/pgtable.h>
21297
21298 /* Machine check handler for WinChip C6: */
21299 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21300@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21301 {
21302 u32 lo, hi;
21303
21304+ pax_open_kernel();
21305 machine_check_vector = winchip_machine_check;
21306+ pax_close_kernel();
21307 /* Make sure the vector pointer is visible before we enable MCEs: */
21308 wmb();
21309
21310diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21311index 15c9876..0a43909 100644
21312--- a/arch/x86/kernel/cpu/microcode/core.c
21313+++ b/arch/x86/kernel/cpu/microcode/core.c
21314@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21315 return NOTIFY_OK;
21316 }
21317
21318-static struct notifier_block __refdata mc_cpu_notifier = {
21319+static struct notifier_block mc_cpu_notifier = {
21320 .notifier_call = mc_cpu_callback,
21321 };
21322
21323diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21324index a276fa7..e66810f 100644
21325--- a/arch/x86/kernel/cpu/microcode/intel.c
21326+++ b/arch/x86/kernel/cpu/microcode/intel.c
21327@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21328
21329 static int get_ucode_user(void *to, const void *from, size_t n)
21330 {
21331- return copy_from_user(to, from, n);
21332+ return copy_from_user(to, (const void __force_user *)from, n);
21333 }
21334
21335 static enum ucode_state
21336 request_microcode_user(int cpu, const void __user *buf, size_t size)
21337 {
21338- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21339+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21340 }
21341
21342 static void microcode_fini_cpu(int cpu)
21343diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21344index f961de9..8a9d332 100644
21345--- a/arch/x86/kernel/cpu/mtrr/main.c
21346+++ b/arch/x86/kernel/cpu/mtrr/main.c
21347@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21348 u64 size_or_mask, size_and_mask;
21349 static bool mtrr_aps_delayed_init;
21350
21351-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21352+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21353
21354 const struct mtrr_ops *mtrr_if;
21355
21356diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21357index df5e41f..816c719 100644
21358--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21359+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21360@@ -25,7 +25,7 @@ struct mtrr_ops {
21361 int (*validate_add_page)(unsigned long base, unsigned long size,
21362 unsigned int type);
21363 int (*have_wrcomb)(void);
21364-};
21365+} __do_const;
21366
21367 extern int generic_get_free_region(unsigned long base, unsigned long size,
21368 int replace_reg);
21369diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21370index 79f9f84..38ace52 100644
21371--- a/arch/x86/kernel/cpu/perf_event.c
21372+++ b/arch/x86/kernel/cpu/perf_event.c
21373@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21374 pr_info("no hardware sampling interrupt available.\n");
21375 }
21376
21377-static struct attribute_group x86_pmu_format_group = {
21378+static attribute_group_no_const x86_pmu_format_group = {
21379 .name = "format",
21380 .attrs = NULL,
21381 };
21382@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21383 NULL,
21384 };
21385
21386-static struct attribute_group x86_pmu_events_group = {
21387+static attribute_group_no_const x86_pmu_events_group = {
21388 .name = "events",
21389 .attrs = events_attr,
21390 };
21391@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21392 if (idx > GDT_ENTRIES)
21393 return 0;
21394
21395- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21396+ desc = get_cpu_gdt_table(smp_processor_id());
21397 }
21398
21399 return get_desc_base(desc + idx);
21400@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21401 break;
21402
21403 perf_callchain_store(entry, frame.return_address);
21404- fp = frame.next_frame;
21405+ fp = (const void __force_user *)frame.next_frame;
21406 }
21407 }
21408
21409diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21410index 639d128..e92d7e5 100644
21411--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21412+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21413@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21414 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21415 {
21416 struct attribute **attrs;
21417- struct attribute_group *attr_group;
21418+ attribute_group_no_const *attr_group;
21419 int i = 0, j;
21420
21421 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21422diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21423index aa333d9..f9db700 100644
21424--- a/arch/x86/kernel/cpu/perf_event_intel.c
21425+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21426@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21427 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21428
21429 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21430- u64 capabilities;
21431+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21432
21433- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21434- x86_pmu.intel_cap.capabilities = capabilities;
21435+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21436+ x86_pmu.intel_cap.capabilities = capabilities;
21437 }
21438
21439 intel_ds_init();
21440diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21441index 5ad35ad..e0a3960 100644
21442--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21443+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21444@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21445 NULL,
21446 };
21447
21448-static struct attribute_group rapl_pmu_events_group = {
21449+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21450 .name = "events",
21451 .attrs = NULL, /* patched at runtime */
21452 };
21453diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21454index 047f540..afdeba0 100644
21455--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21456+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21457@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21458 static int __init uncore_type_init(struct intel_uncore_type *type)
21459 {
21460 struct intel_uncore_pmu *pmus;
21461- struct attribute_group *attr_group;
21462+ attribute_group_no_const *attr_group;
21463 struct attribute **attrs;
21464 int i, j;
21465
21466diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21467index a80ab71..4089da5 100644
21468--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21469+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21470@@ -498,7 +498,7 @@ struct intel_uncore_box {
21471 struct uncore_event_desc {
21472 struct kobj_attribute attr;
21473 const char *config;
21474-};
21475+} __do_const;
21476
21477 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21478 { \
21479diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21480index 7d9481c..99c7e4b 100644
21481--- a/arch/x86/kernel/cpuid.c
21482+++ b/arch/x86/kernel/cpuid.c
21483@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21484 return notifier_from_errno(err);
21485 }
21486
21487-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21488+static struct notifier_block cpuid_class_cpu_notifier =
21489 {
21490 .notifier_call = cpuid_class_cpu_callback,
21491 };
21492diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21493index a57902e..ebaae2a 100644
21494--- a/arch/x86/kernel/crash.c
21495+++ b/arch/x86/kernel/crash.c
21496@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21497 {
21498 #ifdef CONFIG_X86_32
21499 struct pt_regs fixed_regs;
21500-#endif
21501
21502-#ifdef CONFIG_X86_32
21503- if (!user_mode_vm(regs)) {
21504+ if (!user_mode(regs)) {
21505 crash_fixup_ss_esp(&fixed_regs, regs);
21506 regs = &fixed_regs;
21507 }
21508diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21509index afa64ad..dce67dd 100644
21510--- a/arch/x86/kernel/crash_dump_64.c
21511+++ b/arch/x86/kernel/crash_dump_64.c
21512@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21513 return -ENOMEM;
21514
21515 if (userbuf) {
21516- if (copy_to_user(buf, vaddr + offset, csize)) {
21517+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21518 iounmap(vaddr);
21519 return -EFAULT;
21520 }
21521diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21522index f6dfd93..892ade4 100644
21523--- a/arch/x86/kernel/doublefault.c
21524+++ b/arch/x86/kernel/doublefault.c
21525@@ -12,7 +12,7 @@
21526
21527 #define DOUBLEFAULT_STACKSIZE (1024)
21528 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21529-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21530+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21531
21532 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21533
21534@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21535 unsigned long gdt, tss;
21536
21537 native_store_gdt(&gdt_desc);
21538- gdt = gdt_desc.address;
21539+ gdt = (unsigned long)gdt_desc.address;
21540
21541 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21542
21543@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21544 /* 0x2 bit is always set */
21545 .flags = X86_EFLAGS_SF | 0x2,
21546 .sp = STACK_START,
21547- .es = __USER_DS,
21548+ .es = __KERNEL_DS,
21549 .cs = __KERNEL_CS,
21550 .ss = __KERNEL_DS,
21551- .ds = __USER_DS,
21552+ .ds = __KERNEL_DS,
21553 .fs = __KERNEL_PERCPU,
21554
21555 .__cr3 = __pa_nodebug(swapper_pg_dir),
21556diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21557index d9c12d3..7858b62 100644
21558--- a/arch/x86/kernel/dumpstack.c
21559+++ b/arch/x86/kernel/dumpstack.c
21560@@ -2,6 +2,9 @@
21561 * Copyright (C) 1991, 1992 Linus Torvalds
21562 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21563 */
21564+#ifdef CONFIG_GRKERNSEC_HIDESYM
21565+#define __INCLUDED_BY_HIDESYM 1
21566+#endif
21567 #include <linux/kallsyms.h>
21568 #include <linux/kprobes.h>
21569 #include <linux/uaccess.h>
21570@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21571 static void
21572 print_ftrace_graph_addr(unsigned long addr, void *data,
21573 const struct stacktrace_ops *ops,
21574- struct thread_info *tinfo, int *graph)
21575+ struct task_struct *task, int *graph)
21576 {
21577- struct task_struct *task;
21578 unsigned long ret_addr;
21579 int index;
21580
21581 if (addr != (unsigned long)return_to_handler)
21582 return;
21583
21584- task = tinfo->task;
21585 index = task->curr_ret_stack;
21586
21587 if (!task->ret_stack || index < *graph)
21588@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21589 static inline void
21590 print_ftrace_graph_addr(unsigned long addr, void *data,
21591 const struct stacktrace_ops *ops,
21592- struct thread_info *tinfo, int *graph)
21593+ struct task_struct *task, int *graph)
21594 { }
21595 #endif
21596
21597@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21598 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21599 */
21600
21601-static inline int valid_stack_ptr(struct thread_info *tinfo,
21602- void *p, unsigned int size, void *end)
21603+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21604 {
21605- void *t = tinfo;
21606 if (end) {
21607 if (p < end && p >= (end-THREAD_SIZE))
21608 return 1;
21609@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21610 }
21611
21612 unsigned long
21613-print_context_stack(struct thread_info *tinfo,
21614+print_context_stack(struct task_struct *task, void *stack_start,
21615 unsigned long *stack, unsigned long bp,
21616 const struct stacktrace_ops *ops, void *data,
21617 unsigned long *end, int *graph)
21618 {
21619 struct stack_frame *frame = (struct stack_frame *)bp;
21620
21621- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21622+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21623 unsigned long addr;
21624
21625 addr = *stack;
21626@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21627 } else {
21628 ops->address(data, addr, 0);
21629 }
21630- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21631+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21632 }
21633 stack++;
21634 }
21635@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21636 EXPORT_SYMBOL_GPL(print_context_stack);
21637
21638 unsigned long
21639-print_context_stack_bp(struct thread_info *tinfo,
21640+print_context_stack_bp(struct task_struct *task, void *stack_start,
21641 unsigned long *stack, unsigned long bp,
21642 const struct stacktrace_ops *ops, void *data,
21643 unsigned long *end, int *graph)
21644@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21645 struct stack_frame *frame = (struct stack_frame *)bp;
21646 unsigned long *ret_addr = &frame->return_address;
21647
21648- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21649+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21650 unsigned long addr = *ret_addr;
21651
21652 if (!__kernel_text_address(addr))
21653@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21654 ops->address(data, addr, 1);
21655 frame = frame->next_frame;
21656 ret_addr = &frame->return_address;
21657- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21658+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21659 }
21660
21661 return (unsigned long)frame;
21662@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21663 static void print_trace_address(void *data, unsigned long addr, int reliable)
21664 {
21665 touch_nmi_watchdog();
21666- printk(data);
21667+ printk("%s", (char *)data);
21668 printk_stack_address(addr, reliable);
21669 }
21670
21671@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21672 }
21673 EXPORT_SYMBOL_GPL(oops_begin);
21674
21675+extern void gr_handle_kernel_exploit(void);
21676+
21677 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21678 {
21679 if (regs && kexec_should_crash(current))
21680@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21681 panic("Fatal exception in interrupt");
21682 if (panic_on_oops)
21683 panic("Fatal exception");
21684- do_exit(signr);
21685+
21686+ gr_handle_kernel_exploit();
21687+
21688+ do_group_exit(signr);
21689 }
21690
21691 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21692@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21693 print_modules();
21694 show_regs(regs);
21695 #ifdef CONFIG_X86_32
21696- if (user_mode_vm(regs)) {
21697+ if (user_mode(regs)) {
21698 sp = regs->sp;
21699 ss = regs->ss & 0xffff;
21700 } else {
21701@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21702 unsigned long flags = oops_begin();
21703 int sig = SIGSEGV;
21704
21705- if (!user_mode_vm(regs))
21706+ if (!user_mode(regs))
21707 report_bug(regs->ip, regs);
21708
21709 if (__die(str, regs, err))
21710diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21711index f2a1770..10fa52d 100644
21712--- a/arch/x86/kernel/dumpstack_32.c
21713+++ b/arch/x86/kernel/dumpstack_32.c
21714@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21715 bp = stack_frame(task, regs);
21716
21717 for (;;) {
21718- struct thread_info *context;
21719+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21720
21721- context = (struct thread_info *)
21722- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21723- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21724+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21725
21726- stack = (unsigned long *)context->previous_esp;
21727- if (!stack)
21728+ if (stack_start == task_stack_page(task))
21729 break;
21730+ stack = *(unsigned long **)stack_start;
21731 if (ops->stack(data, "IRQ") < 0)
21732 break;
21733 touch_nmi_watchdog();
21734@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21735 int i;
21736
21737 show_regs_print_info(KERN_EMERG);
21738- __show_regs(regs, !user_mode_vm(regs));
21739+ __show_regs(regs, !user_mode(regs));
21740
21741 /*
21742 * When in-kernel, we also print out the stack and code at the
21743 * time of the fault..
21744 */
21745- if (!user_mode_vm(regs)) {
21746+ if (!user_mode(regs)) {
21747 unsigned int code_prologue = code_bytes * 43 / 64;
21748 unsigned int code_len = code_bytes;
21749 unsigned char c;
21750 u8 *ip;
21751+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21752
21753 pr_emerg("Stack:\n");
21754 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21755
21756 pr_emerg("Code:");
21757
21758- ip = (u8 *)regs->ip - code_prologue;
21759+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21760 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21761 /* try starting at IP */
21762- ip = (u8 *)regs->ip;
21763+ ip = (u8 *)regs->ip + cs_base;
21764 code_len = code_len - code_prologue + 1;
21765 }
21766 for (i = 0; i < code_len; i++, ip++) {
21767@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21768 pr_cont(" Bad EIP value.");
21769 break;
21770 }
21771- if (ip == (u8 *)regs->ip)
21772+ if (ip == (u8 *)regs->ip + cs_base)
21773 pr_cont(" <%02x>", c);
21774 else
21775 pr_cont(" %02x", c);
21776@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21777 {
21778 unsigned short ud2;
21779
21780+ ip = ktla_ktva(ip);
21781 if (ip < PAGE_OFFSET)
21782 return 0;
21783 if (probe_kernel_address((unsigned short *)ip, ud2))
21784@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21785
21786 return ud2 == 0x0b0f;
21787 }
21788+
21789+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21790+void pax_check_alloca(unsigned long size)
21791+{
21792+ unsigned long sp = (unsigned long)&sp, stack_left;
21793+
21794+ /* all kernel stacks are of the same size */
21795+ stack_left = sp & (THREAD_SIZE - 1);
21796+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21797+}
21798+EXPORT_SYMBOL(pax_check_alloca);
21799+#endif
21800diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21801index addb207..921706b 100644
21802--- a/arch/x86/kernel/dumpstack_64.c
21803+++ b/arch/x86/kernel/dumpstack_64.c
21804@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21805 unsigned long *irq_stack_end =
21806 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21807 unsigned used = 0;
21808- struct thread_info *tinfo;
21809 int graph = 0;
21810 unsigned long dummy;
21811+ void *stack_start;
21812
21813 if (!task)
21814 task = current;
21815@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21816 * current stack address. If the stacks consist of nested
21817 * exceptions
21818 */
21819- tinfo = task_thread_info(task);
21820 for (;;) {
21821 char *id;
21822 unsigned long *estack_end;
21823+
21824 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21825 &used, &id);
21826
21827@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21828 if (ops->stack(data, id) < 0)
21829 break;
21830
21831- bp = ops->walk_stack(tinfo, stack, bp, ops,
21832+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21833 data, estack_end, &graph);
21834 ops->stack(data, "<EOE>");
21835 /*
21836@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21837 * second-to-last pointer (index -2 to end) in the
21838 * exception stack:
21839 */
21840+ if ((u16)estack_end[-1] != __KERNEL_DS)
21841+ goto out;
21842 stack = (unsigned long *) estack_end[-2];
21843 continue;
21844 }
21845@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21846 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21847 if (ops->stack(data, "IRQ") < 0)
21848 break;
21849- bp = ops->walk_stack(tinfo, stack, bp,
21850+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21851 ops, data, irq_stack_end, &graph);
21852 /*
21853 * We link to the next stack (which would be
21854@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21855 /*
21856 * This handles the process stack:
21857 */
21858- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21859+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21860+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21861+out:
21862 put_cpu();
21863 }
21864 EXPORT_SYMBOL(dump_trace);
21865@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21866
21867 return ud2 == 0x0b0f;
21868 }
21869+
21870+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21871+void pax_check_alloca(unsigned long size)
21872+{
21873+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21874+ unsigned cpu, used;
21875+ char *id;
21876+
21877+ /* check the process stack first */
21878+ stack_start = (unsigned long)task_stack_page(current);
21879+ stack_end = stack_start + THREAD_SIZE;
21880+ if (likely(stack_start <= sp && sp < stack_end)) {
21881+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21882+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21883+ return;
21884+ }
21885+
21886+ cpu = get_cpu();
21887+
21888+ /* check the irq stacks */
21889+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21890+ stack_start = stack_end - IRQ_STACK_SIZE;
21891+ if (stack_start <= sp && sp < stack_end) {
21892+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21893+ put_cpu();
21894+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21895+ return;
21896+ }
21897+
21898+ /* check the exception stacks */
21899+ used = 0;
21900+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21901+ stack_start = stack_end - EXCEPTION_STKSZ;
21902+ if (stack_end && stack_start <= sp && sp < stack_end) {
21903+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21904+ put_cpu();
21905+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21906+ return;
21907+ }
21908+
21909+ put_cpu();
21910+
21911+ /* unknown stack */
21912+ BUG();
21913+}
21914+EXPORT_SYMBOL(pax_check_alloca);
21915+#endif
21916diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21917index 988c00a..4f673b6 100644
21918--- a/arch/x86/kernel/e820.c
21919+++ b/arch/x86/kernel/e820.c
21920@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21921
21922 static void early_panic(char *msg)
21923 {
21924- early_printk(msg);
21925- panic(msg);
21926+ early_printk("%s", msg);
21927+ panic("%s", msg);
21928 }
21929
21930 static int userdef __initdata;
21931diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21932index 01d1c18..8073693 100644
21933--- a/arch/x86/kernel/early_printk.c
21934+++ b/arch/x86/kernel/early_printk.c
21935@@ -7,6 +7,7 @@
21936 #include <linux/pci_regs.h>
21937 #include <linux/pci_ids.h>
21938 #include <linux/errno.h>
21939+#include <linux/sched.h>
21940 #include <asm/io.h>
21941 #include <asm/processor.h>
21942 #include <asm/fcntl.h>
21943diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21944index a2a4f46..6cab058 100644
21945--- a/arch/x86/kernel/entry_32.S
21946+++ b/arch/x86/kernel/entry_32.S
21947@@ -177,13 +177,153 @@
21948 /*CFI_REL_OFFSET gs, PT_GS*/
21949 .endm
21950 .macro SET_KERNEL_GS reg
21951+
21952+#ifdef CONFIG_CC_STACKPROTECTOR
21953 movl $(__KERNEL_STACK_CANARY), \reg
21954+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21955+ movl $(__USER_DS), \reg
21956+#else
21957+ xorl \reg, \reg
21958+#endif
21959+
21960 movl \reg, %gs
21961 .endm
21962
21963 #endif /* CONFIG_X86_32_LAZY_GS */
21964
21965-.macro SAVE_ALL
21966+.macro pax_enter_kernel
21967+#ifdef CONFIG_PAX_KERNEXEC
21968+ call pax_enter_kernel
21969+#endif
21970+.endm
21971+
21972+.macro pax_exit_kernel
21973+#ifdef CONFIG_PAX_KERNEXEC
21974+ call pax_exit_kernel
21975+#endif
21976+.endm
21977+
21978+#ifdef CONFIG_PAX_KERNEXEC
21979+ENTRY(pax_enter_kernel)
21980+#ifdef CONFIG_PARAVIRT
21981+ pushl %eax
21982+ pushl %ecx
21983+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21984+ mov %eax, %esi
21985+#else
21986+ mov %cr0, %esi
21987+#endif
21988+ bts $16, %esi
21989+ jnc 1f
21990+ mov %cs, %esi
21991+ cmp $__KERNEL_CS, %esi
21992+ jz 3f
21993+ ljmp $__KERNEL_CS, $3f
21994+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21995+2:
21996+#ifdef CONFIG_PARAVIRT
21997+ mov %esi, %eax
21998+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21999+#else
22000+ mov %esi, %cr0
22001+#endif
22002+3:
22003+#ifdef CONFIG_PARAVIRT
22004+ popl %ecx
22005+ popl %eax
22006+#endif
22007+ ret
22008+ENDPROC(pax_enter_kernel)
22009+
22010+ENTRY(pax_exit_kernel)
22011+#ifdef CONFIG_PARAVIRT
22012+ pushl %eax
22013+ pushl %ecx
22014+#endif
22015+ mov %cs, %esi
22016+ cmp $__KERNEXEC_KERNEL_CS, %esi
22017+ jnz 2f
22018+#ifdef CONFIG_PARAVIRT
22019+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22020+ mov %eax, %esi
22021+#else
22022+ mov %cr0, %esi
22023+#endif
22024+ btr $16, %esi
22025+ ljmp $__KERNEL_CS, $1f
22026+1:
22027+#ifdef CONFIG_PARAVIRT
22028+ mov %esi, %eax
22029+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22030+#else
22031+ mov %esi, %cr0
22032+#endif
22033+2:
22034+#ifdef CONFIG_PARAVIRT
22035+ popl %ecx
22036+ popl %eax
22037+#endif
22038+ ret
22039+ENDPROC(pax_exit_kernel)
22040+#endif
22041+
22042+ .macro pax_erase_kstack
22043+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22044+ call pax_erase_kstack
22045+#endif
22046+ .endm
22047+
22048+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22049+/*
22050+ * ebp: thread_info
22051+ */
22052+ENTRY(pax_erase_kstack)
22053+ pushl %edi
22054+ pushl %ecx
22055+ pushl %eax
22056+
22057+ mov TI_lowest_stack(%ebp), %edi
22058+ mov $-0xBEEF, %eax
22059+ std
22060+
22061+1: mov %edi, %ecx
22062+ and $THREAD_SIZE_asm - 1, %ecx
22063+ shr $2, %ecx
22064+ repne scasl
22065+ jecxz 2f
22066+
22067+ cmp $2*16, %ecx
22068+ jc 2f
22069+
22070+ mov $2*16, %ecx
22071+ repe scasl
22072+ jecxz 2f
22073+ jne 1b
22074+
22075+2: cld
22076+ mov %esp, %ecx
22077+ sub %edi, %ecx
22078+
22079+ cmp $THREAD_SIZE_asm, %ecx
22080+ jb 3f
22081+ ud2
22082+3:
22083+
22084+ shr $2, %ecx
22085+ rep stosl
22086+
22087+ mov TI_task_thread_sp0(%ebp), %edi
22088+ sub $128, %edi
22089+ mov %edi, TI_lowest_stack(%ebp)
22090+
22091+ popl %eax
22092+ popl %ecx
22093+ popl %edi
22094+ ret
22095+ENDPROC(pax_erase_kstack)
22096+#endif
22097+
22098+.macro __SAVE_ALL _DS
22099 cld
22100 PUSH_GS
22101 pushl_cfi %fs
22102@@ -206,7 +346,7 @@
22103 CFI_REL_OFFSET ecx, 0
22104 pushl_cfi %ebx
22105 CFI_REL_OFFSET ebx, 0
22106- movl $(__USER_DS), %edx
22107+ movl $\_DS, %edx
22108 movl %edx, %ds
22109 movl %edx, %es
22110 movl $(__KERNEL_PERCPU), %edx
22111@@ -214,6 +354,15 @@
22112 SET_KERNEL_GS %edx
22113 .endm
22114
22115+.macro SAVE_ALL
22116+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22117+ __SAVE_ALL __KERNEL_DS
22118+ pax_enter_kernel
22119+#else
22120+ __SAVE_ALL __USER_DS
22121+#endif
22122+.endm
22123+
22124 .macro RESTORE_INT_REGS
22125 popl_cfi %ebx
22126 CFI_RESTORE ebx
22127@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22128 popfl_cfi
22129 jmp syscall_exit
22130 CFI_ENDPROC
22131-END(ret_from_fork)
22132+ENDPROC(ret_from_fork)
22133
22134 ENTRY(ret_from_kernel_thread)
22135 CFI_STARTPROC
22136@@ -344,7 +493,15 @@ ret_from_intr:
22137 andl $SEGMENT_RPL_MASK, %eax
22138 #endif
22139 cmpl $USER_RPL, %eax
22140+
22141+#ifdef CONFIG_PAX_KERNEXEC
22142+ jae resume_userspace
22143+
22144+ pax_exit_kernel
22145+ jmp resume_kernel
22146+#else
22147 jb resume_kernel # not returning to v8086 or userspace
22148+#endif
22149
22150 ENTRY(resume_userspace)
22151 LOCKDEP_SYS_EXIT
22152@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22153 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22154 # int/exception return?
22155 jne work_pending
22156- jmp restore_all
22157-END(ret_from_exception)
22158+ jmp restore_all_pax
22159+ENDPROC(ret_from_exception)
22160
22161 #ifdef CONFIG_PREEMPT
22162 ENTRY(resume_kernel)
22163@@ -369,7 +526,7 @@ need_resched:
22164 jz restore_all
22165 call preempt_schedule_irq
22166 jmp need_resched
22167-END(resume_kernel)
22168+ENDPROC(resume_kernel)
22169 #endif
22170 CFI_ENDPROC
22171 /*
22172@@ -403,30 +560,45 @@ sysenter_past_esp:
22173 /*CFI_REL_OFFSET cs, 0*/
22174 /*
22175 * Push current_thread_info()->sysenter_return to the stack.
22176- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22177- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22178 */
22179- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22180+ pushl_cfi $0
22181 CFI_REL_OFFSET eip, 0
22182
22183 pushl_cfi %eax
22184 SAVE_ALL
22185+ GET_THREAD_INFO(%ebp)
22186+ movl TI_sysenter_return(%ebp),%ebp
22187+ movl %ebp,PT_EIP(%esp)
22188 ENABLE_INTERRUPTS(CLBR_NONE)
22189
22190 /*
22191 * Load the potential sixth argument from user stack.
22192 * Careful about security.
22193 */
22194+ movl PT_OLDESP(%esp),%ebp
22195+
22196+#ifdef CONFIG_PAX_MEMORY_UDEREF
22197+ mov PT_OLDSS(%esp),%ds
22198+1: movl %ds:(%ebp),%ebp
22199+ push %ss
22200+ pop %ds
22201+#else
22202 cmpl $__PAGE_OFFSET-3,%ebp
22203 jae syscall_fault
22204 ASM_STAC
22205 1: movl (%ebp),%ebp
22206 ASM_CLAC
22207+#endif
22208+
22209 movl %ebp,PT_EBP(%esp)
22210 _ASM_EXTABLE(1b,syscall_fault)
22211
22212 GET_THREAD_INFO(%ebp)
22213
22214+#ifdef CONFIG_PAX_RANDKSTACK
22215+ pax_erase_kstack
22216+#endif
22217+
22218 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22219 jnz sysenter_audit
22220 sysenter_do_call:
22221@@ -441,12 +613,24 @@ sysenter_do_call:
22222 testl $_TIF_ALLWORK_MASK, %ecx
22223 jne sysexit_audit
22224 sysenter_exit:
22225+
22226+#ifdef CONFIG_PAX_RANDKSTACK
22227+ pushl_cfi %eax
22228+ movl %esp, %eax
22229+ call pax_randomize_kstack
22230+ popl_cfi %eax
22231+#endif
22232+
22233+ pax_erase_kstack
22234+
22235 /* if something modifies registers it must also disable sysexit */
22236 movl PT_EIP(%esp), %edx
22237 movl PT_OLDESP(%esp), %ecx
22238 xorl %ebp,%ebp
22239 TRACE_IRQS_ON
22240 1: mov PT_FS(%esp), %fs
22241+2: mov PT_DS(%esp), %ds
22242+3: mov PT_ES(%esp), %es
22243 PTGS_TO_GS
22244 ENABLE_INTERRUPTS_SYSEXIT
22245
22246@@ -463,6 +647,9 @@ sysenter_audit:
22247 movl %eax,%edx /* 2nd arg: syscall number */
22248 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22249 call __audit_syscall_entry
22250+
22251+ pax_erase_kstack
22252+
22253 pushl_cfi %ebx
22254 movl PT_EAX(%esp),%eax /* reload syscall number */
22255 jmp sysenter_do_call
22256@@ -488,10 +675,16 @@ sysexit_audit:
22257
22258 CFI_ENDPROC
22259 .pushsection .fixup,"ax"
22260-2: movl $0,PT_FS(%esp)
22261+4: movl $0,PT_FS(%esp)
22262+ jmp 1b
22263+5: movl $0,PT_DS(%esp)
22264+ jmp 1b
22265+6: movl $0,PT_ES(%esp)
22266 jmp 1b
22267 .popsection
22268- _ASM_EXTABLE(1b,2b)
22269+ _ASM_EXTABLE(1b,4b)
22270+ _ASM_EXTABLE(2b,5b)
22271+ _ASM_EXTABLE(3b,6b)
22272 PTGS_TO_GS_EX
22273 ENDPROC(ia32_sysenter_target)
22274
22275@@ -506,6 +699,11 @@ ENTRY(system_call)
22276 pushl_cfi %eax # save orig_eax
22277 SAVE_ALL
22278 GET_THREAD_INFO(%ebp)
22279+
22280+#ifdef CONFIG_PAX_RANDKSTACK
22281+ pax_erase_kstack
22282+#endif
22283+
22284 # system call tracing in operation / emulation
22285 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22286 jnz syscall_trace_entry
22287@@ -524,6 +722,15 @@ syscall_exit:
22288 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22289 jne syscall_exit_work
22290
22291+restore_all_pax:
22292+
22293+#ifdef CONFIG_PAX_RANDKSTACK
22294+ movl %esp, %eax
22295+ call pax_randomize_kstack
22296+#endif
22297+
22298+ pax_erase_kstack
22299+
22300 restore_all:
22301 TRACE_IRQS_IRET
22302 restore_all_notrace:
22303@@ -580,14 +787,34 @@ ldt_ss:
22304 * compensating for the offset by changing to the ESPFIX segment with
22305 * a base address that matches for the difference.
22306 */
22307-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22308+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22309 mov %esp, %edx /* load kernel esp */
22310 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22311 mov %dx, %ax /* eax: new kernel esp */
22312 sub %eax, %edx /* offset (low word is 0) */
22313+#ifdef CONFIG_SMP
22314+ movl PER_CPU_VAR(cpu_number), %ebx
22315+ shll $PAGE_SHIFT_asm, %ebx
22316+ addl $cpu_gdt_table, %ebx
22317+#else
22318+ movl $cpu_gdt_table, %ebx
22319+#endif
22320 shr $16, %edx
22321- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22322- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22323+
22324+#ifdef CONFIG_PAX_KERNEXEC
22325+ mov %cr0, %esi
22326+ btr $16, %esi
22327+ mov %esi, %cr0
22328+#endif
22329+
22330+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22331+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22332+
22333+#ifdef CONFIG_PAX_KERNEXEC
22334+ bts $16, %esi
22335+ mov %esi, %cr0
22336+#endif
22337+
22338 pushl_cfi $__ESPFIX_SS
22339 pushl_cfi %eax /* new kernel esp */
22340 /* Disable interrupts, but do not irqtrace this section: we
22341@@ -616,20 +843,18 @@ work_resched:
22342 movl TI_flags(%ebp), %ecx
22343 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22344 # than syscall tracing?
22345- jz restore_all
22346+ jz restore_all_pax
22347 testb $_TIF_NEED_RESCHED, %cl
22348 jnz work_resched
22349
22350 work_notifysig: # deal with pending signals and
22351 # notify-resume requests
22352+ movl %esp, %eax
22353 #ifdef CONFIG_VM86
22354 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22355- movl %esp, %eax
22356 jne work_notifysig_v86 # returning to kernel-space or
22357 # vm86-space
22358 1:
22359-#else
22360- movl %esp, %eax
22361 #endif
22362 TRACE_IRQS_ON
22363 ENABLE_INTERRUPTS(CLBR_NONE)
22364@@ -650,7 +875,7 @@ work_notifysig_v86:
22365 movl %eax, %esp
22366 jmp 1b
22367 #endif
22368-END(work_pending)
22369+ENDPROC(work_pending)
22370
22371 # perform syscall exit tracing
22372 ALIGN
22373@@ -658,11 +883,14 @@ syscall_trace_entry:
22374 movl $-ENOSYS,PT_EAX(%esp)
22375 movl %esp, %eax
22376 call syscall_trace_enter
22377+
22378+ pax_erase_kstack
22379+
22380 /* What it returned is what we'll actually use. */
22381 cmpl $(NR_syscalls), %eax
22382 jnae syscall_call
22383 jmp syscall_exit
22384-END(syscall_trace_entry)
22385+ENDPROC(syscall_trace_entry)
22386
22387 # perform syscall exit tracing
22388 ALIGN
22389@@ -675,21 +903,25 @@ syscall_exit_work:
22390 movl %esp, %eax
22391 call syscall_trace_leave
22392 jmp resume_userspace
22393-END(syscall_exit_work)
22394+ENDPROC(syscall_exit_work)
22395 CFI_ENDPROC
22396
22397 RING0_INT_FRAME # can't unwind into user space anyway
22398 syscall_fault:
22399+#ifdef CONFIG_PAX_MEMORY_UDEREF
22400+ push %ss
22401+ pop %ds
22402+#endif
22403 ASM_CLAC
22404 GET_THREAD_INFO(%ebp)
22405 movl $-EFAULT,PT_EAX(%esp)
22406 jmp resume_userspace
22407-END(syscall_fault)
22408+ENDPROC(syscall_fault)
22409
22410 syscall_badsys:
22411 movl $-ENOSYS,PT_EAX(%esp)
22412 jmp resume_userspace
22413-END(syscall_badsys)
22414+ENDPROC(syscall_badsys)
22415 CFI_ENDPROC
22416 /*
22417 * End of kprobes section
22418@@ -705,8 +937,15 @@ END(syscall_badsys)
22419 * normal stack and adjusts ESP with the matching offset.
22420 */
22421 /* fixup the stack */
22422- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22423- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22424+#ifdef CONFIG_SMP
22425+ movl PER_CPU_VAR(cpu_number), %ebx
22426+ shll $PAGE_SHIFT_asm, %ebx
22427+ addl $cpu_gdt_table, %ebx
22428+#else
22429+ movl $cpu_gdt_table, %ebx
22430+#endif
22431+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22432+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22433 shl $16, %eax
22434 addl %esp, %eax /* the adjusted stack pointer */
22435 pushl_cfi $__KERNEL_DS
22436@@ -759,7 +998,7 @@ vector=vector+1
22437 .endr
22438 2: jmp common_interrupt
22439 .endr
22440-END(irq_entries_start)
22441+ENDPROC(irq_entries_start)
22442
22443 .previous
22444 END(interrupt)
22445@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22446 pushl_cfi $do_coprocessor_error
22447 jmp error_code
22448 CFI_ENDPROC
22449-END(coprocessor_error)
22450+ENDPROC(coprocessor_error)
22451
22452 ENTRY(simd_coprocessor_error)
22453 RING0_INT_FRAME
22454@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22455 .section .altinstructions,"a"
22456 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22457 .previous
22458-.section .altinstr_replacement,"ax"
22459+.section .altinstr_replacement,"a"
22460 663: pushl $do_simd_coprocessor_error
22461 664:
22462 .previous
22463@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22464 #endif
22465 jmp error_code
22466 CFI_ENDPROC
22467-END(simd_coprocessor_error)
22468+ENDPROC(simd_coprocessor_error)
22469
22470 ENTRY(device_not_available)
22471 RING0_INT_FRAME
22472@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22473 pushl_cfi $do_device_not_available
22474 jmp error_code
22475 CFI_ENDPROC
22476-END(device_not_available)
22477+ENDPROC(device_not_available)
22478
22479 #ifdef CONFIG_PARAVIRT
22480 ENTRY(native_iret)
22481 iret
22482 _ASM_EXTABLE(native_iret, iret_exc)
22483-END(native_iret)
22484+ENDPROC(native_iret)
22485
22486 ENTRY(native_irq_enable_sysexit)
22487 sti
22488 sysexit
22489-END(native_irq_enable_sysexit)
22490+ENDPROC(native_irq_enable_sysexit)
22491 #endif
22492
22493 ENTRY(overflow)
22494@@ -872,7 +1111,7 @@ ENTRY(overflow)
22495 pushl_cfi $do_overflow
22496 jmp error_code
22497 CFI_ENDPROC
22498-END(overflow)
22499+ENDPROC(overflow)
22500
22501 ENTRY(bounds)
22502 RING0_INT_FRAME
22503@@ -881,7 +1120,7 @@ ENTRY(bounds)
22504 pushl_cfi $do_bounds
22505 jmp error_code
22506 CFI_ENDPROC
22507-END(bounds)
22508+ENDPROC(bounds)
22509
22510 ENTRY(invalid_op)
22511 RING0_INT_FRAME
22512@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22513 pushl_cfi $do_invalid_op
22514 jmp error_code
22515 CFI_ENDPROC
22516-END(invalid_op)
22517+ENDPROC(invalid_op)
22518
22519 ENTRY(coprocessor_segment_overrun)
22520 RING0_INT_FRAME
22521@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22522 pushl_cfi $do_coprocessor_segment_overrun
22523 jmp error_code
22524 CFI_ENDPROC
22525-END(coprocessor_segment_overrun)
22526+ENDPROC(coprocessor_segment_overrun)
22527
22528 ENTRY(invalid_TSS)
22529 RING0_EC_FRAME
22530@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22531 pushl_cfi $do_invalid_TSS
22532 jmp error_code
22533 CFI_ENDPROC
22534-END(invalid_TSS)
22535+ENDPROC(invalid_TSS)
22536
22537 ENTRY(segment_not_present)
22538 RING0_EC_FRAME
22539@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22540 pushl_cfi $do_segment_not_present
22541 jmp error_code
22542 CFI_ENDPROC
22543-END(segment_not_present)
22544+ENDPROC(segment_not_present)
22545
22546 ENTRY(stack_segment)
22547 RING0_EC_FRAME
22548@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22549 pushl_cfi $do_stack_segment
22550 jmp error_code
22551 CFI_ENDPROC
22552-END(stack_segment)
22553+ENDPROC(stack_segment)
22554
22555 ENTRY(alignment_check)
22556 RING0_EC_FRAME
22557@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22558 pushl_cfi $do_alignment_check
22559 jmp error_code
22560 CFI_ENDPROC
22561-END(alignment_check)
22562+ENDPROC(alignment_check)
22563
22564 ENTRY(divide_error)
22565 RING0_INT_FRAME
22566@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22567 pushl_cfi $do_divide_error
22568 jmp error_code
22569 CFI_ENDPROC
22570-END(divide_error)
22571+ENDPROC(divide_error)
22572
22573 #ifdef CONFIG_X86_MCE
22574 ENTRY(machine_check)
22575@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22576 pushl_cfi machine_check_vector
22577 jmp error_code
22578 CFI_ENDPROC
22579-END(machine_check)
22580+ENDPROC(machine_check)
22581 #endif
22582
22583 ENTRY(spurious_interrupt_bug)
22584@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22585 pushl_cfi $do_spurious_interrupt_bug
22586 jmp error_code
22587 CFI_ENDPROC
22588-END(spurious_interrupt_bug)
22589+ENDPROC(spurious_interrupt_bug)
22590 /*
22591 * End of kprobes section
22592 */
22593@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22594
22595 ENTRY(mcount)
22596 ret
22597-END(mcount)
22598+ENDPROC(mcount)
22599
22600 ENTRY(ftrace_caller)
22601 cmpl $0, function_trace_stop
22602@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22603 .globl ftrace_stub
22604 ftrace_stub:
22605 ret
22606-END(ftrace_caller)
22607+ENDPROC(ftrace_caller)
22608
22609 ENTRY(ftrace_regs_caller)
22610 pushf /* push flags before compare (in cs location) */
22611@@ -1207,7 +1446,7 @@ trace:
22612 popl %ecx
22613 popl %eax
22614 jmp ftrace_stub
22615-END(mcount)
22616+ENDPROC(mcount)
22617 #endif /* CONFIG_DYNAMIC_FTRACE */
22618 #endif /* CONFIG_FUNCTION_TRACER */
22619
22620@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22621 popl %ecx
22622 popl %eax
22623 ret
22624-END(ftrace_graph_caller)
22625+ENDPROC(ftrace_graph_caller)
22626
22627 .globl return_to_handler
22628 return_to_handler:
22629@@ -1291,15 +1530,18 @@ error_code:
22630 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22631 REG_TO_PTGS %ecx
22632 SET_KERNEL_GS %ecx
22633- movl $(__USER_DS), %ecx
22634+ movl $(__KERNEL_DS), %ecx
22635 movl %ecx, %ds
22636 movl %ecx, %es
22637+
22638+ pax_enter_kernel
22639+
22640 TRACE_IRQS_OFF
22641 movl %esp,%eax # pt_regs pointer
22642 call *%edi
22643 jmp ret_from_exception
22644 CFI_ENDPROC
22645-END(page_fault)
22646+ENDPROC(page_fault)
22647
22648 /*
22649 * Debug traps and NMI can happen at the one SYSENTER instruction
22650@@ -1342,7 +1584,7 @@ debug_stack_correct:
22651 call do_debug
22652 jmp ret_from_exception
22653 CFI_ENDPROC
22654-END(debug)
22655+ENDPROC(debug)
22656
22657 /*
22658 * NMI is doubly nasty. It can happen _while_ we're handling
22659@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22660 xorl %edx,%edx # zero error code
22661 movl %esp,%eax # pt_regs pointer
22662 call do_nmi
22663+
22664+ pax_exit_kernel
22665+
22666 jmp restore_all_notrace
22667 CFI_ENDPROC
22668
22669@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22670 FIXUP_ESPFIX_STACK # %eax == %esp
22671 xorl %edx,%edx # zero error code
22672 call do_nmi
22673+
22674+ pax_exit_kernel
22675+
22676 RESTORE_REGS
22677 lss 12+4(%esp), %esp # back to espfix stack
22678 CFI_ADJUST_CFA_OFFSET -24
22679 jmp irq_return
22680 CFI_ENDPROC
22681-END(nmi)
22682+ENDPROC(nmi)
22683
22684 ENTRY(int3)
22685 RING0_INT_FRAME
22686@@ -1434,14 +1682,14 @@ ENTRY(int3)
22687 call do_int3
22688 jmp ret_from_exception
22689 CFI_ENDPROC
22690-END(int3)
22691+ENDPROC(int3)
22692
22693 ENTRY(general_protection)
22694 RING0_EC_FRAME
22695 pushl_cfi $do_general_protection
22696 jmp error_code
22697 CFI_ENDPROC
22698-END(general_protection)
22699+ENDPROC(general_protection)
22700
22701 #ifdef CONFIG_KVM_GUEST
22702 ENTRY(async_page_fault)
22703@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22704 pushl_cfi $do_async_page_fault
22705 jmp error_code
22706 CFI_ENDPROC
22707-END(async_page_fault)
22708+ENDPROC(async_page_fault)
22709 #endif
22710
22711 /*
22712diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22713index 1e96c36..3ff710a 100644
22714--- a/arch/x86/kernel/entry_64.S
22715+++ b/arch/x86/kernel/entry_64.S
22716@@ -59,6 +59,8 @@
22717 #include <asm/context_tracking.h>
22718 #include <asm/smap.h>
22719 #include <linux/err.h>
22720+#include <asm/pgtable.h>
22721+#include <asm/alternative-asm.h>
22722
22723 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22724 #include <linux/elf-em.h>
22725@@ -80,8 +82,9 @@
22726 #ifdef CONFIG_DYNAMIC_FTRACE
22727
22728 ENTRY(function_hook)
22729+ pax_force_retaddr
22730 retq
22731-END(function_hook)
22732+ENDPROC(function_hook)
22733
22734 /* skip is set if stack has been adjusted */
22735 .macro ftrace_caller_setup skip=0
22736@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22737 #endif
22738
22739 GLOBAL(ftrace_stub)
22740+ pax_force_retaddr
22741 retq
22742-END(ftrace_caller)
22743+ENDPROC(ftrace_caller)
22744
22745 ENTRY(ftrace_regs_caller)
22746 /* Save the current flags before compare (in SS location)*/
22747@@ -191,7 +195,7 @@ ftrace_restore_flags:
22748 popfq
22749 jmp ftrace_stub
22750
22751-END(ftrace_regs_caller)
22752+ENDPROC(ftrace_regs_caller)
22753
22754
22755 #else /* ! CONFIG_DYNAMIC_FTRACE */
22756@@ -212,6 +216,7 @@ ENTRY(function_hook)
22757 #endif
22758
22759 GLOBAL(ftrace_stub)
22760+ pax_force_retaddr
22761 retq
22762
22763 trace:
22764@@ -225,12 +230,13 @@ trace:
22765 #endif
22766 subq $MCOUNT_INSN_SIZE, %rdi
22767
22768+ pax_force_fptr ftrace_trace_function
22769 call *ftrace_trace_function
22770
22771 MCOUNT_RESTORE_FRAME
22772
22773 jmp ftrace_stub
22774-END(function_hook)
22775+ENDPROC(function_hook)
22776 #endif /* CONFIG_DYNAMIC_FTRACE */
22777 #endif /* CONFIG_FUNCTION_TRACER */
22778
22779@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22780
22781 MCOUNT_RESTORE_FRAME
22782
22783+ pax_force_retaddr
22784 retq
22785-END(ftrace_graph_caller)
22786+ENDPROC(ftrace_graph_caller)
22787
22788 GLOBAL(return_to_handler)
22789 subq $24, %rsp
22790@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22791 movq 8(%rsp), %rdx
22792 movq (%rsp), %rax
22793 addq $24, %rsp
22794+ pax_force_fptr %rdi
22795 jmp *%rdi
22796+ENDPROC(return_to_handler)
22797 #endif
22798
22799
22800@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22801 ENDPROC(native_usergs_sysret64)
22802 #endif /* CONFIG_PARAVIRT */
22803
22804+ .macro ljmpq sel, off
22805+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22806+ .byte 0x48; ljmp *1234f(%rip)
22807+ .pushsection .rodata
22808+ .align 16
22809+ 1234: .quad \off; .word \sel
22810+ .popsection
22811+#else
22812+ pushq $\sel
22813+ pushq $\off
22814+ lretq
22815+#endif
22816+ .endm
22817+
22818+ .macro pax_enter_kernel
22819+ pax_set_fptr_mask
22820+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22821+ call pax_enter_kernel
22822+#endif
22823+ .endm
22824+
22825+ .macro pax_exit_kernel
22826+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22827+ call pax_exit_kernel
22828+#endif
22829+
22830+ .endm
22831+
22832+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22833+ENTRY(pax_enter_kernel)
22834+ pushq %rdi
22835+
22836+#ifdef CONFIG_PARAVIRT
22837+ PV_SAVE_REGS(CLBR_RDI)
22838+#endif
22839+
22840+#ifdef CONFIG_PAX_KERNEXEC
22841+ GET_CR0_INTO_RDI
22842+ bts $16,%rdi
22843+ jnc 3f
22844+ mov %cs,%edi
22845+ cmp $__KERNEL_CS,%edi
22846+ jnz 2f
22847+1:
22848+#endif
22849+
22850+#ifdef CONFIG_PAX_MEMORY_UDEREF
22851+ 661: jmp 111f
22852+ .pushsection .altinstr_replacement, "a"
22853+ 662: ASM_NOP2
22854+ .popsection
22855+ .pushsection .altinstructions, "a"
22856+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22857+ .popsection
22858+ GET_CR3_INTO_RDI
22859+ cmp $0,%dil
22860+ jnz 112f
22861+ mov $__KERNEL_DS,%edi
22862+ mov %edi,%ss
22863+ jmp 111f
22864+112: cmp $1,%dil
22865+ jz 113f
22866+ ud2
22867+113: sub $4097,%rdi
22868+ bts $63,%rdi
22869+ SET_RDI_INTO_CR3
22870+ mov $__UDEREF_KERNEL_DS,%edi
22871+ mov %edi,%ss
22872+111:
22873+#endif
22874+
22875+#ifdef CONFIG_PARAVIRT
22876+ PV_RESTORE_REGS(CLBR_RDI)
22877+#endif
22878+
22879+ popq %rdi
22880+ pax_force_retaddr
22881+ retq
22882+
22883+#ifdef CONFIG_PAX_KERNEXEC
22884+2: ljmpq __KERNEL_CS,1b
22885+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22886+4: SET_RDI_INTO_CR0
22887+ jmp 1b
22888+#endif
22889+ENDPROC(pax_enter_kernel)
22890+
22891+ENTRY(pax_exit_kernel)
22892+ pushq %rdi
22893+
22894+#ifdef CONFIG_PARAVIRT
22895+ PV_SAVE_REGS(CLBR_RDI)
22896+#endif
22897+
22898+#ifdef CONFIG_PAX_KERNEXEC
22899+ mov %cs,%rdi
22900+ cmp $__KERNEXEC_KERNEL_CS,%edi
22901+ jz 2f
22902+ GET_CR0_INTO_RDI
22903+ bts $16,%rdi
22904+ jnc 4f
22905+1:
22906+#endif
22907+
22908+#ifdef CONFIG_PAX_MEMORY_UDEREF
22909+ 661: jmp 111f
22910+ .pushsection .altinstr_replacement, "a"
22911+ 662: ASM_NOP2
22912+ .popsection
22913+ .pushsection .altinstructions, "a"
22914+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22915+ .popsection
22916+ mov %ss,%edi
22917+ cmp $__UDEREF_KERNEL_DS,%edi
22918+ jnz 111f
22919+ GET_CR3_INTO_RDI
22920+ cmp $0,%dil
22921+ jz 112f
22922+ ud2
22923+112: add $4097,%rdi
22924+ bts $63,%rdi
22925+ SET_RDI_INTO_CR3
22926+ mov $__KERNEL_DS,%edi
22927+ mov %edi,%ss
22928+111:
22929+#endif
22930+
22931+#ifdef CONFIG_PARAVIRT
22932+ PV_RESTORE_REGS(CLBR_RDI);
22933+#endif
22934+
22935+ popq %rdi
22936+ pax_force_retaddr
22937+ retq
22938+
22939+#ifdef CONFIG_PAX_KERNEXEC
22940+2: GET_CR0_INTO_RDI
22941+ btr $16,%rdi
22942+ jnc 4f
22943+ ljmpq __KERNEL_CS,3f
22944+3: SET_RDI_INTO_CR0
22945+ jmp 1b
22946+4: ud2
22947+ jmp 4b
22948+#endif
22949+ENDPROC(pax_exit_kernel)
22950+#endif
22951+
22952+ .macro pax_enter_kernel_user
22953+ pax_set_fptr_mask
22954+#ifdef CONFIG_PAX_MEMORY_UDEREF
22955+ call pax_enter_kernel_user
22956+#endif
22957+ .endm
22958+
22959+ .macro pax_exit_kernel_user
22960+#ifdef CONFIG_PAX_MEMORY_UDEREF
22961+ call pax_exit_kernel_user
22962+#endif
22963+#ifdef CONFIG_PAX_RANDKSTACK
22964+ pushq %rax
22965+ pushq %r11
22966+ call pax_randomize_kstack
22967+ popq %r11
22968+ popq %rax
22969+#endif
22970+ .endm
22971+
22972+#ifdef CONFIG_PAX_MEMORY_UDEREF
22973+ENTRY(pax_enter_kernel_user)
22974+ pushq %rdi
22975+ pushq %rbx
22976+
22977+#ifdef CONFIG_PARAVIRT
22978+ PV_SAVE_REGS(CLBR_RDI)
22979+#endif
22980+
22981+ 661: jmp 111f
22982+ .pushsection .altinstr_replacement, "a"
22983+ 662: ASM_NOP2
22984+ .popsection
22985+ .pushsection .altinstructions, "a"
22986+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22987+ .popsection
22988+ GET_CR3_INTO_RDI
22989+ cmp $1,%dil
22990+ jnz 4f
22991+ sub $4097,%rdi
22992+ bts $63,%rdi
22993+ SET_RDI_INTO_CR3
22994+ jmp 3f
22995+111:
22996+
22997+ GET_CR3_INTO_RDI
22998+ mov %rdi,%rbx
22999+ add $__START_KERNEL_map,%rbx
23000+ sub phys_base(%rip),%rbx
23001+
23002+#ifdef CONFIG_PARAVIRT
23003+ cmpl $0, pv_info+PARAVIRT_enabled
23004+ jz 1f
23005+ pushq %rdi
23006+ i = 0
23007+ .rept USER_PGD_PTRS
23008+ mov i*8(%rbx),%rsi
23009+ mov $0,%sil
23010+ lea i*8(%rbx),%rdi
23011+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23012+ i = i + 1
23013+ .endr
23014+ popq %rdi
23015+ jmp 2f
23016+1:
23017+#endif
23018+
23019+ i = 0
23020+ .rept USER_PGD_PTRS
23021+ movb $0,i*8(%rbx)
23022+ i = i + 1
23023+ .endr
23024+
23025+2: SET_RDI_INTO_CR3
23026+
23027+#ifdef CONFIG_PAX_KERNEXEC
23028+ GET_CR0_INTO_RDI
23029+ bts $16,%rdi
23030+ SET_RDI_INTO_CR0
23031+#endif
23032+
23033+3:
23034+
23035+#ifdef CONFIG_PARAVIRT
23036+ PV_RESTORE_REGS(CLBR_RDI)
23037+#endif
23038+
23039+ popq %rbx
23040+ popq %rdi
23041+ pax_force_retaddr
23042+ retq
23043+4: ud2
23044+ENDPROC(pax_enter_kernel_user)
23045+
23046+ENTRY(pax_exit_kernel_user)
23047+ pushq %rdi
23048+ pushq %rbx
23049+
23050+#ifdef CONFIG_PARAVIRT
23051+ PV_SAVE_REGS(CLBR_RDI)
23052+#endif
23053+
23054+ GET_CR3_INTO_RDI
23055+ 661: jmp 1f
23056+ .pushsection .altinstr_replacement, "a"
23057+ 662: ASM_NOP2
23058+ .popsection
23059+ .pushsection .altinstructions, "a"
23060+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23061+ .popsection
23062+ cmp $0,%dil
23063+ jnz 3f
23064+ add $4097,%rdi
23065+ bts $63,%rdi
23066+ SET_RDI_INTO_CR3
23067+ jmp 2f
23068+1:
23069+
23070+ mov %rdi,%rbx
23071+
23072+#ifdef CONFIG_PAX_KERNEXEC
23073+ GET_CR0_INTO_RDI
23074+ btr $16,%rdi
23075+ jnc 3f
23076+ SET_RDI_INTO_CR0
23077+#endif
23078+
23079+ add $__START_KERNEL_map,%rbx
23080+ sub phys_base(%rip),%rbx
23081+
23082+#ifdef CONFIG_PARAVIRT
23083+ cmpl $0, pv_info+PARAVIRT_enabled
23084+ jz 1f
23085+ i = 0
23086+ .rept USER_PGD_PTRS
23087+ mov i*8(%rbx),%rsi
23088+ mov $0x67,%sil
23089+ lea i*8(%rbx),%rdi
23090+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23091+ i = i + 1
23092+ .endr
23093+ jmp 2f
23094+1:
23095+#endif
23096+
23097+ i = 0
23098+ .rept USER_PGD_PTRS
23099+ movb $0x67,i*8(%rbx)
23100+ i = i + 1
23101+ .endr
23102+2:
23103+
23104+#ifdef CONFIG_PARAVIRT
23105+ PV_RESTORE_REGS(CLBR_RDI)
23106+#endif
23107+
23108+ popq %rbx
23109+ popq %rdi
23110+ pax_force_retaddr
23111+ retq
23112+3: ud2
23113+ENDPROC(pax_exit_kernel_user)
23114+#endif
23115+
23116+ .macro pax_enter_kernel_nmi
23117+ pax_set_fptr_mask
23118+
23119+#ifdef CONFIG_PAX_KERNEXEC
23120+ GET_CR0_INTO_RDI
23121+ bts $16,%rdi
23122+ jc 110f
23123+ SET_RDI_INTO_CR0
23124+ or $2,%ebx
23125+110:
23126+#endif
23127+
23128+#ifdef CONFIG_PAX_MEMORY_UDEREF
23129+ 661: jmp 111f
23130+ .pushsection .altinstr_replacement, "a"
23131+ 662: ASM_NOP2
23132+ .popsection
23133+ .pushsection .altinstructions, "a"
23134+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23135+ .popsection
23136+ GET_CR3_INTO_RDI
23137+ cmp $0,%dil
23138+ jz 111f
23139+ sub $4097,%rdi
23140+ or $4,%ebx
23141+ bts $63,%rdi
23142+ SET_RDI_INTO_CR3
23143+ mov $__UDEREF_KERNEL_DS,%edi
23144+ mov %edi,%ss
23145+111:
23146+#endif
23147+ .endm
23148+
23149+ .macro pax_exit_kernel_nmi
23150+#ifdef CONFIG_PAX_KERNEXEC
23151+ btr $1,%ebx
23152+ jnc 110f
23153+ GET_CR0_INTO_RDI
23154+ btr $16,%rdi
23155+ SET_RDI_INTO_CR0
23156+110:
23157+#endif
23158+
23159+#ifdef CONFIG_PAX_MEMORY_UDEREF
23160+ btr $2,%ebx
23161+ jnc 111f
23162+ GET_CR3_INTO_RDI
23163+ add $4097,%rdi
23164+ bts $63,%rdi
23165+ SET_RDI_INTO_CR3
23166+ mov $__KERNEL_DS,%edi
23167+ mov %edi,%ss
23168+111:
23169+#endif
23170+ .endm
23171+
23172+ .macro pax_erase_kstack
23173+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23174+ call pax_erase_kstack
23175+#endif
23176+ .endm
23177+
23178+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23179+ENTRY(pax_erase_kstack)
23180+ pushq %rdi
23181+ pushq %rcx
23182+ pushq %rax
23183+ pushq %r11
23184+
23185+ GET_THREAD_INFO(%r11)
23186+ mov TI_lowest_stack(%r11), %rdi
23187+ mov $-0xBEEF, %rax
23188+ std
23189+
23190+1: mov %edi, %ecx
23191+ and $THREAD_SIZE_asm - 1, %ecx
23192+ shr $3, %ecx
23193+ repne scasq
23194+ jecxz 2f
23195+
23196+ cmp $2*8, %ecx
23197+ jc 2f
23198+
23199+ mov $2*8, %ecx
23200+ repe scasq
23201+ jecxz 2f
23202+ jne 1b
23203+
23204+2: cld
23205+ mov %esp, %ecx
23206+ sub %edi, %ecx
23207+
23208+ cmp $THREAD_SIZE_asm, %rcx
23209+ jb 3f
23210+ ud2
23211+3:
23212+
23213+ shr $3, %ecx
23214+ rep stosq
23215+
23216+ mov TI_task_thread_sp0(%r11), %rdi
23217+ sub $256, %rdi
23218+ mov %rdi, TI_lowest_stack(%r11)
23219+
23220+ popq %r11
23221+ popq %rax
23222+ popq %rcx
23223+ popq %rdi
23224+ pax_force_retaddr
23225+ ret
23226+ENDPROC(pax_erase_kstack)
23227+#endif
23228
23229 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23230 #ifdef CONFIG_TRACE_IRQFLAGS
23231@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23232 .endm
23233
23234 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23235- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23236+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23237 jnc 1f
23238 TRACE_IRQS_ON_DEBUG
23239 1:
23240@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23241 movq \tmp,R11+\offset(%rsp)
23242 .endm
23243
23244- .macro FAKE_STACK_FRAME child_rip
23245- /* push in order ss, rsp, eflags, cs, rip */
23246- xorl %eax, %eax
23247- pushq_cfi $__KERNEL_DS /* ss */
23248- /*CFI_REL_OFFSET ss,0*/
23249- pushq_cfi %rax /* rsp */
23250- CFI_REL_OFFSET rsp,0
23251- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23252- /*CFI_REL_OFFSET rflags,0*/
23253- pushq_cfi $__KERNEL_CS /* cs */
23254- /*CFI_REL_OFFSET cs,0*/
23255- pushq_cfi \child_rip /* rip */
23256- CFI_REL_OFFSET rip,0
23257- pushq_cfi %rax /* orig rax */
23258- .endm
23259-
23260- .macro UNFAKE_STACK_FRAME
23261- addq $8*6, %rsp
23262- CFI_ADJUST_CFA_OFFSET -(6*8)
23263- .endm
23264-
23265 /*
23266 * initial frame state for interrupts (and exceptions without error code)
23267 */
23268@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23269 /* save partial stack frame */
23270 .macro SAVE_ARGS_IRQ
23271 cld
23272- /* start from rbp in pt_regs and jump over */
23273- movq_cfi rdi, (RDI-RBP)
23274- movq_cfi rsi, (RSI-RBP)
23275- movq_cfi rdx, (RDX-RBP)
23276- movq_cfi rcx, (RCX-RBP)
23277- movq_cfi rax, (RAX-RBP)
23278- movq_cfi r8, (R8-RBP)
23279- movq_cfi r9, (R9-RBP)
23280- movq_cfi r10, (R10-RBP)
23281- movq_cfi r11, (R11-RBP)
23282+ /* start from r15 in pt_regs and jump over */
23283+ movq_cfi rdi, RDI
23284+ movq_cfi rsi, RSI
23285+ movq_cfi rdx, RDX
23286+ movq_cfi rcx, RCX
23287+ movq_cfi rax, RAX
23288+ movq_cfi r8, R8
23289+ movq_cfi r9, R9
23290+ movq_cfi r10, R10
23291+ movq_cfi r11, R11
23292+ movq_cfi r12, R12
23293
23294 /* Save rbp so that we can unwind from get_irq_regs() */
23295- movq_cfi rbp, 0
23296+ movq_cfi rbp, RBP
23297
23298 /* Save previous stack value */
23299 movq %rsp, %rsi
23300
23301- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23302- testl $3, CS-RBP(%rsi)
23303+ movq %rsp,%rdi /* arg1 for handler */
23304+ testb $3, CS(%rsi)
23305 je 1f
23306 SWAPGS
23307 /*
23308@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23309 0x06 /* DW_OP_deref */, \
23310 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23311 0x22 /* DW_OP_plus */
23312+
23313+#ifdef CONFIG_PAX_MEMORY_UDEREF
23314+ testb $3, CS(%rdi)
23315+ jnz 1f
23316+ pax_enter_kernel
23317+ jmp 2f
23318+1: pax_enter_kernel_user
23319+2:
23320+#else
23321+ pax_enter_kernel
23322+#endif
23323+
23324 /* We entered an interrupt context - irqs are off: */
23325 TRACE_IRQS_OFF
23326 .endm
23327@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23328 js 1f /* negative -> in kernel */
23329 SWAPGS
23330 xorl %ebx,%ebx
23331-1: ret
23332+1:
23333+#ifdef CONFIG_PAX_MEMORY_UDEREF
23334+ testb $3, CS+8(%rsp)
23335+ jnz 1f
23336+ pax_enter_kernel
23337+ jmp 2f
23338+1: pax_enter_kernel_user
23339+2:
23340+#else
23341+ pax_enter_kernel
23342+#endif
23343+ pax_force_retaddr
23344+ ret
23345 CFI_ENDPROC
23346-END(save_paranoid)
23347+ENDPROC(save_paranoid)
23348+
23349+ENTRY(save_paranoid_nmi)
23350+ XCPT_FRAME 1 RDI+8
23351+ cld
23352+ movq_cfi rdi, RDI+8
23353+ movq_cfi rsi, RSI+8
23354+ movq_cfi rdx, RDX+8
23355+ movq_cfi rcx, RCX+8
23356+ movq_cfi rax, RAX+8
23357+ movq_cfi r8, R8+8
23358+ movq_cfi r9, R9+8
23359+ movq_cfi r10, R10+8
23360+ movq_cfi r11, R11+8
23361+ movq_cfi rbx, RBX+8
23362+ movq_cfi rbp, RBP+8
23363+ movq_cfi r12, R12+8
23364+ movq_cfi r13, R13+8
23365+ movq_cfi r14, R14+8
23366+ movq_cfi r15, R15+8
23367+ movl $1,%ebx
23368+ movl $MSR_GS_BASE,%ecx
23369+ rdmsr
23370+ testl %edx,%edx
23371+ js 1f /* negative -> in kernel */
23372+ SWAPGS
23373+ xorl %ebx,%ebx
23374+1: pax_enter_kernel_nmi
23375+ pax_force_retaddr
23376+ ret
23377+ CFI_ENDPROC
23378+ENDPROC(save_paranoid_nmi)
23379 .popsection
23380
23381 /*
23382@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23383
23384 RESTORE_REST
23385
23386- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23387+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23388 jz 1f
23389
23390 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23391@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23392 jmp ret_from_sys_call # go to the SYSRET fastpath
23393
23394 1:
23395- subq $REST_SKIP, %rsp # leave space for volatiles
23396- CFI_ADJUST_CFA_OFFSET REST_SKIP
23397 movq %rbp, %rdi
23398 call *%rbx
23399 movl $0, RAX(%rsp)
23400 RESTORE_REST
23401 jmp int_ret_from_sys_call
23402 CFI_ENDPROC
23403-END(ret_from_fork)
23404+ENDPROC(ret_from_fork)
23405
23406 /*
23407 * System call entry. Up to 6 arguments in registers are supported.
23408@@ -593,7 +1059,7 @@ END(ret_from_fork)
23409 ENTRY(system_call)
23410 CFI_STARTPROC simple
23411 CFI_SIGNAL_FRAME
23412- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23413+ CFI_DEF_CFA rsp,0
23414 CFI_REGISTER rip,rcx
23415 /*CFI_REGISTER rflags,r11*/
23416 SWAPGS_UNSAFE_STACK
23417@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23418
23419 movq %rsp,PER_CPU_VAR(old_rsp)
23420 movq PER_CPU_VAR(kernel_stack),%rsp
23421+ SAVE_ARGS 8*6,0
23422+ pax_enter_kernel_user
23423+
23424+#ifdef CONFIG_PAX_RANDKSTACK
23425+ pax_erase_kstack
23426+#endif
23427+
23428 /*
23429 * No need to follow this irqs off/on section - it's straight
23430 * and short:
23431 */
23432 ENABLE_INTERRUPTS(CLBR_NONE)
23433- SAVE_ARGS 8,0
23434 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23435 movq %rcx,RIP-ARGOFFSET(%rsp)
23436 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23437- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23438+ GET_THREAD_INFO(%rcx)
23439+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23440 jnz tracesys
23441 system_call_fastpath:
23442 #if __SYSCALL_MASK == ~0
23443@@ -639,10 +1112,13 @@ sysret_check:
23444 LOCKDEP_SYS_EXIT
23445 DISABLE_INTERRUPTS(CLBR_NONE)
23446 TRACE_IRQS_OFF
23447- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23448+ GET_THREAD_INFO(%rcx)
23449+ movl TI_flags(%rcx),%edx
23450 andl %edi,%edx
23451 jnz sysret_careful
23452 CFI_REMEMBER_STATE
23453+ pax_exit_kernel_user
23454+ pax_erase_kstack
23455 /*
23456 * sysretq will re-enable interrupts:
23457 */
23458@@ -701,6 +1177,9 @@ auditsys:
23459 movq %rax,%rsi /* 2nd arg: syscall number */
23460 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23461 call __audit_syscall_entry
23462+
23463+ pax_erase_kstack
23464+
23465 LOAD_ARGS 0 /* reload call-clobbered registers */
23466 jmp system_call_fastpath
23467
23468@@ -722,7 +1201,7 @@ sysret_audit:
23469 /* Do syscall tracing */
23470 tracesys:
23471 #ifdef CONFIG_AUDITSYSCALL
23472- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23473+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23474 jz auditsys
23475 #endif
23476 SAVE_REST
23477@@ -730,12 +1209,15 @@ tracesys:
23478 FIXUP_TOP_OF_STACK %rdi
23479 movq %rsp,%rdi
23480 call syscall_trace_enter
23481+
23482+ pax_erase_kstack
23483+
23484 /*
23485 * Reload arg registers from stack in case ptrace changed them.
23486 * We don't reload %rax because syscall_trace_enter() returned
23487 * the value it wants us to use in the table lookup.
23488 */
23489- LOAD_ARGS ARGOFFSET, 1
23490+ LOAD_ARGS 1
23491 RESTORE_REST
23492 #if __SYSCALL_MASK == ~0
23493 cmpq $__NR_syscall_max,%rax
23494@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23495 andl %edi,%edx
23496 jnz int_careful
23497 andl $~TS_COMPAT,TI_status(%rcx)
23498- jmp retint_swapgs
23499+ pax_exit_kernel_user
23500+ pax_erase_kstack
23501+ jmp retint_swapgs_pax
23502
23503 /* Either reschedule or signal or syscall exit tracking needed. */
23504 /* First do a reschedule test. */
23505@@ -811,7 +1295,7 @@ int_restore_rest:
23506 TRACE_IRQS_OFF
23507 jmp int_with_check
23508 CFI_ENDPROC
23509-END(system_call)
23510+ENDPROC(system_call)
23511
23512 .macro FORK_LIKE func
23513 ENTRY(stub_\func)
23514@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23515 DEFAULT_FRAME 0 8 /* offset 8: return address */
23516 call sys_\func
23517 RESTORE_TOP_OF_STACK %r11, 8
23518- ret $REST_SKIP /* pop extended registers */
23519+ pax_force_retaddr
23520+ ret
23521 CFI_ENDPROC
23522-END(stub_\func)
23523+ENDPROC(stub_\func)
23524 .endm
23525
23526 .macro FIXED_FRAME label,func
23527@@ -836,9 +1321,10 @@ ENTRY(\label)
23528 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23529 call \func
23530 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23531+ pax_force_retaddr
23532 ret
23533 CFI_ENDPROC
23534-END(\label)
23535+ENDPROC(\label)
23536 .endm
23537
23538 FORK_LIKE clone
23539@@ -846,19 +1332,6 @@ END(\label)
23540 FORK_LIKE vfork
23541 FIXED_FRAME stub_iopl, sys_iopl
23542
23543-ENTRY(ptregscall_common)
23544- DEFAULT_FRAME 1 8 /* offset 8: return address */
23545- RESTORE_TOP_OF_STACK %r11, 8
23546- movq_cfi_restore R15+8, r15
23547- movq_cfi_restore R14+8, r14
23548- movq_cfi_restore R13+8, r13
23549- movq_cfi_restore R12+8, r12
23550- movq_cfi_restore RBP+8, rbp
23551- movq_cfi_restore RBX+8, rbx
23552- ret $REST_SKIP /* pop extended registers */
23553- CFI_ENDPROC
23554-END(ptregscall_common)
23555-
23556 ENTRY(stub_execve)
23557 CFI_STARTPROC
23558 addq $8, %rsp
23559@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23560 RESTORE_REST
23561 jmp int_ret_from_sys_call
23562 CFI_ENDPROC
23563-END(stub_execve)
23564+ENDPROC(stub_execve)
23565
23566 /*
23567 * sigreturn is special because it needs to restore all registers on return.
23568@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23569 RESTORE_REST
23570 jmp int_ret_from_sys_call
23571 CFI_ENDPROC
23572-END(stub_rt_sigreturn)
23573+ENDPROC(stub_rt_sigreturn)
23574
23575 #ifdef CONFIG_X86_X32_ABI
23576 ENTRY(stub_x32_rt_sigreturn)
23577@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23578 RESTORE_REST
23579 jmp int_ret_from_sys_call
23580 CFI_ENDPROC
23581-END(stub_x32_rt_sigreturn)
23582+ENDPROC(stub_x32_rt_sigreturn)
23583
23584 ENTRY(stub_x32_execve)
23585 CFI_STARTPROC
23586@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23587 RESTORE_REST
23588 jmp int_ret_from_sys_call
23589 CFI_ENDPROC
23590-END(stub_x32_execve)
23591+ENDPROC(stub_x32_execve)
23592
23593 #endif
23594
23595@@ -952,7 +1425,7 @@ vector=vector+1
23596 2: jmp common_interrupt
23597 .endr
23598 CFI_ENDPROC
23599-END(irq_entries_start)
23600+ENDPROC(irq_entries_start)
23601
23602 .previous
23603 END(interrupt)
23604@@ -969,8 +1442,8 @@ END(interrupt)
23605 /* 0(%rsp): ~(interrupt number) */
23606 .macro interrupt func
23607 /* reserve pt_regs for scratch regs and rbp */
23608- subq $ORIG_RAX-RBP, %rsp
23609- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23610+ subq $ORIG_RAX, %rsp
23611+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23612 SAVE_ARGS_IRQ
23613 call \func
23614 .endm
23615@@ -997,14 +1470,14 @@ ret_from_intr:
23616
23617 /* Restore saved previous stack */
23618 popq %rsi
23619- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23620- leaq ARGOFFSET-RBP(%rsi), %rsp
23621+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23622+ movq %rsi, %rsp
23623 CFI_DEF_CFA_REGISTER rsp
23624- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23625+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23626
23627 exit_intr:
23628 GET_THREAD_INFO(%rcx)
23629- testl $3,CS-ARGOFFSET(%rsp)
23630+ testb $3,CS-ARGOFFSET(%rsp)
23631 je retint_kernel
23632
23633 /* Interrupt came from user space */
23634@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23635 * The iretq could re-enable interrupts:
23636 */
23637 DISABLE_INTERRUPTS(CLBR_ANY)
23638+ pax_exit_kernel_user
23639+retint_swapgs_pax:
23640 TRACE_IRQS_IRETQ
23641 SWAPGS
23642 jmp restore_args
23643
23644 retint_restore_args: /* return to kernel space */
23645 DISABLE_INTERRUPTS(CLBR_ANY)
23646+ pax_exit_kernel
23647+ pax_force_retaddr (RIP-ARGOFFSET)
23648 /*
23649 * The iretq could re-enable interrupts:
23650 */
23651@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23652 #endif
23653
23654 CFI_ENDPROC
23655-END(common_interrupt)
23656+ENDPROC(common_interrupt)
23657 /*
23658 * End of kprobes section
23659 */
23660@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23661 interrupt \do_sym
23662 jmp ret_from_intr
23663 CFI_ENDPROC
23664-END(\sym)
23665+ENDPROC(\sym)
23666 .endm
23667
23668 #ifdef CONFIG_TRACING
23669@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23670 call \do_sym
23671 jmp error_exit /* %ebx: no swapgs flag */
23672 CFI_ENDPROC
23673-END(\sym)
23674+ENDPROC(\sym)
23675 .endm
23676
23677 .macro paranoidzeroentry sym do_sym
23678@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23679 call \do_sym
23680 jmp paranoid_exit /* %ebx: no swapgs flag */
23681 CFI_ENDPROC
23682-END(\sym)
23683+ENDPROC(\sym)
23684 .endm
23685
23686-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23687+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23688 .macro paranoidzeroentry_ist sym do_sym ist
23689 ENTRY(\sym)
23690 INTR_FRAME
23691@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23692 TRACE_IRQS_OFF_DEBUG
23693 movq %rsp,%rdi /* pt_regs pointer */
23694 xorl %esi,%esi /* no error code */
23695+#ifdef CONFIG_SMP
23696+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23697+ lea init_tss(%r13), %r13
23698+#else
23699+ lea init_tss(%rip), %r13
23700+#endif
23701 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23702 call \do_sym
23703 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23704 jmp paranoid_exit /* %ebx: no swapgs flag */
23705 CFI_ENDPROC
23706-END(\sym)
23707+ENDPROC(\sym)
23708 .endm
23709
23710 .macro errorentry sym do_sym
23711@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23712 call \do_sym
23713 jmp error_exit /* %ebx: no swapgs flag */
23714 CFI_ENDPROC
23715-END(\sym)
23716+ENDPROC(\sym)
23717 .endm
23718
23719 #ifdef CONFIG_TRACING
23720@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23721 call \do_sym
23722 jmp paranoid_exit /* %ebx: no swapgs flag */
23723 CFI_ENDPROC
23724-END(\sym)
23725+ENDPROC(\sym)
23726 .endm
23727
23728 zeroentry divide_error do_divide_error
23729@@ -1336,9 +1819,10 @@ gs_change:
23730 2: mfence /* workaround */
23731 SWAPGS
23732 popfq_cfi
23733+ pax_force_retaddr
23734 ret
23735 CFI_ENDPROC
23736-END(native_load_gs_index)
23737+ENDPROC(native_load_gs_index)
23738
23739 _ASM_EXTABLE(gs_change,bad_gs)
23740 .section .fixup,"ax"
23741@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23742 CFI_DEF_CFA_REGISTER rsp
23743 CFI_ADJUST_CFA_OFFSET -8
23744 decl PER_CPU_VAR(irq_count)
23745+ pax_force_retaddr
23746 ret
23747 CFI_ENDPROC
23748-END(do_softirq_own_stack)
23749+ENDPROC(do_softirq_own_stack)
23750
23751 #ifdef CONFIG_XEN
23752 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23753@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23754 decl PER_CPU_VAR(irq_count)
23755 jmp error_exit
23756 CFI_ENDPROC
23757-END(xen_do_hypervisor_callback)
23758+ENDPROC(xen_do_hypervisor_callback)
23759
23760 /*
23761 * Hypervisor uses this for application faults while it executes.
23762@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23763 SAVE_ALL
23764 jmp error_exit
23765 CFI_ENDPROC
23766-END(xen_failsafe_callback)
23767+ENDPROC(xen_failsafe_callback)
23768
23769 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23770 xen_hvm_callback_vector xen_evtchn_do_upcall
23771@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23772 DEFAULT_FRAME
23773 DISABLE_INTERRUPTS(CLBR_NONE)
23774 TRACE_IRQS_OFF_DEBUG
23775- testl %ebx,%ebx /* swapgs needed? */
23776+ testl $1,%ebx /* swapgs needed? */
23777 jnz paranoid_restore
23778- testl $3,CS(%rsp)
23779+ testb $3,CS(%rsp)
23780 jnz paranoid_userspace
23781+#ifdef CONFIG_PAX_MEMORY_UDEREF
23782+ pax_exit_kernel
23783+ TRACE_IRQS_IRETQ 0
23784+ SWAPGS_UNSAFE_STACK
23785+ RESTORE_ALL 8
23786+ pax_force_retaddr_bts
23787+ jmp irq_return
23788+#endif
23789 paranoid_swapgs:
23790+#ifdef CONFIG_PAX_MEMORY_UDEREF
23791+ pax_exit_kernel_user
23792+#else
23793+ pax_exit_kernel
23794+#endif
23795 TRACE_IRQS_IRETQ 0
23796 SWAPGS_UNSAFE_STACK
23797 RESTORE_ALL 8
23798 jmp irq_return
23799 paranoid_restore:
23800+ pax_exit_kernel
23801 TRACE_IRQS_IRETQ_DEBUG 0
23802 RESTORE_ALL 8
23803+ pax_force_retaddr_bts
23804 jmp irq_return
23805 paranoid_userspace:
23806 GET_THREAD_INFO(%rcx)
23807@@ -1557,7 +2057,7 @@ paranoid_schedule:
23808 TRACE_IRQS_OFF
23809 jmp paranoid_userspace
23810 CFI_ENDPROC
23811-END(paranoid_exit)
23812+ENDPROC(paranoid_exit)
23813
23814 /*
23815 * Exception entry point. This expects an error code/orig_rax on the stack.
23816@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23817 movq_cfi r14, R14+8
23818 movq_cfi r15, R15+8
23819 xorl %ebx,%ebx
23820- testl $3,CS+8(%rsp)
23821+ testb $3,CS+8(%rsp)
23822 je error_kernelspace
23823 error_swapgs:
23824 SWAPGS
23825 error_sti:
23826+#ifdef CONFIG_PAX_MEMORY_UDEREF
23827+ testb $3, CS+8(%rsp)
23828+ jnz 1f
23829+ pax_enter_kernel
23830+ jmp 2f
23831+1: pax_enter_kernel_user
23832+2:
23833+#else
23834+ pax_enter_kernel
23835+#endif
23836 TRACE_IRQS_OFF
23837+ pax_force_retaddr
23838 ret
23839
23840 /*
23841@@ -1616,7 +2127,7 @@ bstep_iret:
23842 movq %rcx,RIP+8(%rsp)
23843 jmp error_swapgs
23844 CFI_ENDPROC
23845-END(error_entry)
23846+ENDPROC(error_entry)
23847
23848
23849 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23850@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23851 DISABLE_INTERRUPTS(CLBR_NONE)
23852 TRACE_IRQS_OFF
23853 GET_THREAD_INFO(%rcx)
23854- testl %eax,%eax
23855+ testl $1,%eax
23856 jne retint_kernel
23857 LOCKDEP_SYS_EXIT_IRQ
23858 movl TI_flags(%rcx),%edx
23859@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23860 jnz retint_careful
23861 jmp retint_swapgs
23862 CFI_ENDPROC
23863-END(error_exit)
23864+ENDPROC(error_exit)
23865
23866 /*
23867 * Test if a given stack is an NMI stack or not.
23868@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23869 * If %cs was not the kernel segment, then the NMI triggered in user
23870 * space, which means it is definitely not nested.
23871 */
23872+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23873+ je 1f
23874 cmpl $__KERNEL_CS, 16(%rsp)
23875 jne first_nmi
23876-
23877+1:
23878 /*
23879 * Check the special variable on the stack to see if NMIs are
23880 * executing.
23881@@ -1730,8 +2243,7 @@ nested_nmi:
23882
23883 1:
23884 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23885- leaq -1*8(%rsp), %rdx
23886- movq %rdx, %rsp
23887+ subq $8, %rsp
23888 CFI_ADJUST_CFA_OFFSET 1*8
23889 leaq -10*8(%rsp), %rdx
23890 pushq_cfi $__KERNEL_DS
23891@@ -1749,6 +2261,7 @@ nested_nmi_out:
23892 CFI_RESTORE rdx
23893
23894 /* No need to check faults here */
23895+# pax_force_retaddr_bts
23896 INTERRUPT_RETURN
23897
23898 CFI_RESTORE_STATE
23899@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23900 subq $ORIG_RAX-R15, %rsp
23901 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23902 /*
23903- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23904+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23905 * as we should not be calling schedule in NMI context.
23906 * Even with normal interrupts enabled. An NMI should not be
23907 * setting NEED_RESCHED or anything that normal interrupts and
23908 * exceptions might do.
23909 */
23910- call save_paranoid
23911+ call save_paranoid_nmi
23912 DEFAULT_FRAME 0
23913
23914 /*
23915@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23916 * NMI itself takes a page fault, the page fault that was preempted
23917 * will read the information from the NMI page fault and not the
23918 * origin fault. Save it off and restore it if it changes.
23919- * Use the r12 callee-saved register.
23920+ * Use the r13 callee-saved register.
23921 */
23922- movq %cr2, %r12
23923+ movq %cr2, %r13
23924
23925 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23926 movq %rsp,%rdi
23927@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23928
23929 /* Did the NMI take a page fault? Restore cr2 if it did */
23930 movq %cr2, %rcx
23931- cmpq %rcx, %r12
23932+ cmpq %rcx, %r13
23933 je 1f
23934- movq %r12, %cr2
23935+ movq %r13, %cr2
23936 1:
23937
23938- testl %ebx,%ebx /* swapgs needed? */
23939+ testl $1,%ebx /* swapgs needed? */
23940 jnz nmi_restore
23941 nmi_swapgs:
23942 SWAPGS_UNSAFE_STACK
23943 nmi_restore:
23944+ pax_exit_kernel_nmi
23945 /* Pop the extra iret frame at once */
23946 RESTORE_ALL 6*8
23947+ testb $3, 8(%rsp)
23948+ jnz 1f
23949+ pax_force_retaddr_bts
23950+1:
23951
23952 /* Clear the NMI executing stack variable */
23953 movq $0, 5*8(%rsp)
23954 jmp irq_return
23955 CFI_ENDPROC
23956-END(nmi)
23957+ENDPROC(nmi)
23958
23959 ENTRY(ignore_sysret)
23960 CFI_STARTPROC
23961 mov $-ENOSYS,%eax
23962 sysret
23963 CFI_ENDPROC
23964-END(ignore_sysret)
23965+ENDPROC(ignore_sysret)
23966
23967 /*
23968 * End of kprobes section
23969diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23970index 1ffc32d..e52c745 100644
23971--- a/arch/x86/kernel/ftrace.c
23972+++ b/arch/x86/kernel/ftrace.c
23973@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23974 {
23975 unsigned char replaced[MCOUNT_INSN_SIZE];
23976
23977+ ip = ktla_ktva(ip);
23978+
23979 /*
23980 * Note: Due to modules and __init, code can
23981 * disappear and change, we need to protect against faulting
23982@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23983 unsigned char old[MCOUNT_INSN_SIZE];
23984 int ret;
23985
23986- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23987+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23988
23989 ftrace_update_func = ip;
23990 /* Make sure the breakpoints see the ftrace_update_func update */
23991@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23992 * kernel identity mapping to modify code.
23993 */
23994 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23995- ip = (unsigned long)__va(__pa_symbol(ip));
23996+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23997
23998 return probe_kernel_write((void *)ip, val, size);
23999 }
24000@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
24001 unsigned char replaced[MCOUNT_INSN_SIZE];
24002 unsigned char brk = BREAKPOINT_INSTRUCTION;
24003
24004- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24005+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24006 return -EFAULT;
24007
24008 /* Make sure it is what we expect it to be */
24009@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
24010 return ret;
24011
24012 fail_update:
24013- probe_kernel_write((void *)ip, &old_code[0], 1);
24014+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
24015 goto out;
24016 }
24017
24018diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24019index 85126cc..1bbce17 100644
24020--- a/arch/x86/kernel/head64.c
24021+++ b/arch/x86/kernel/head64.c
24022@@ -67,12 +67,12 @@ again:
24023 pgd = *pgd_p;
24024
24025 /*
24026- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24027- * critical -- __PAGE_OFFSET would point us back into the dynamic
24028+ * The use of __early_va rather than __va here is critical:
24029+ * __va would point us back into the dynamic
24030 * range and we might end up looping forever...
24031 */
24032 if (pgd)
24033- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24034+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24035 else {
24036 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24037 reset_early_page_tables();
24038@@ -82,13 +82,13 @@ again:
24039 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24040 for (i = 0; i < PTRS_PER_PUD; i++)
24041 pud_p[i] = 0;
24042- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24043+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24044 }
24045 pud_p += pud_index(address);
24046 pud = *pud_p;
24047
24048 if (pud)
24049- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24050+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24051 else {
24052 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24053 reset_early_page_tables();
24054@@ -98,7 +98,7 @@ again:
24055 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24056 for (i = 0; i < PTRS_PER_PMD; i++)
24057 pmd_p[i] = 0;
24058- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24059+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24060 }
24061 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24062 pmd_p[pmd_index(address)] = pmd;
24063@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24064 if (console_loglevel == 10)
24065 early_printk("Kernel alive\n");
24066
24067- clear_page(init_level4_pgt);
24068 /* set init_level4_pgt kernel high mapping*/
24069 init_level4_pgt[511] = early_level4_pgt[511];
24070
24071diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24072index f36bd42..56ee1534 100644
24073--- a/arch/x86/kernel/head_32.S
24074+++ b/arch/x86/kernel/head_32.S
24075@@ -26,6 +26,12 @@
24076 /* Physical address */
24077 #define pa(X) ((X) - __PAGE_OFFSET)
24078
24079+#ifdef CONFIG_PAX_KERNEXEC
24080+#define ta(X) (X)
24081+#else
24082+#define ta(X) ((X) - __PAGE_OFFSET)
24083+#endif
24084+
24085 /*
24086 * References to members of the new_cpu_data structure.
24087 */
24088@@ -55,11 +61,7 @@
24089 * and small than max_low_pfn, otherwise will waste some page table entries
24090 */
24091
24092-#if PTRS_PER_PMD > 1
24093-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24094-#else
24095-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24096-#endif
24097+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24098
24099 /* Number of possible pages in the lowmem region */
24100 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24101@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24102 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24103
24104 /*
24105+ * Real beginning of normal "text" segment
24106+ */
24107+ENTRY(stext)
24108+ENTRY(_stext)
24109+
24110+/*
24111 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24112 * %esi points to the real-mode code as a 32-bit pointer.
24113 * CS and DS must be 4 GB flat segments, but we don't depend on
24114@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24115 * can.
24116 */
24117 __HEAD
24118+
24119+#ifdef CONFIG_PAX_KERNEXEC
24120+ jmp startup_32
24121+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24122+.fill PAGE_SIZE-5,1,0xcc
24123+#endif
24124+
24125 ENTRY(startup_32)
24126 movl pa(stack_start),%ecx
24127
24128@@ -106,6 +121,59 @@ ENTRY(startup_32)
24129 2:
24130 leal -__PAGE_OFFSET(%ecx),%esp
24131
24132+#ifdef CONFIG_SMP
24133+ movl $pa(cpu_gdt_table),%edi
24134+ movl $__per_cpu_load,%eax
24135+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24136+ rorl $16,%eax
24137+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24138+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24139+ movl $__per_cpu_end - 1,%eax
24140+ subl $__per_cpu_start,%eax
24141+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24142+#endif
24143+
24144+#ifdef CONFIG_PAX_MEMORY_UDEREF
24145+ movl $NR_CPUS,%ecx
24146+ movl $pa(cpu_gdt_table),%edi
24147+1:
24148+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24149+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24150+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24151+ addl $PAGE_SIZE_asm,%edi
24152+ loop 1b
24153+#endif
24154+
24155+#ifdef CONFIG_PAX_KERNEXEC
24156+ movl $pa(boot_gdt),%edi
24157+ movl $__LOAD_PHYSICAL_ADDR,%eax
24158+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24159+ rorl $16,%eax
24160+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24161+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24162+ rorl $16,%eax
24163+
24164+ ljmp $(__BOOT_CS),$1f
24165+1:
24166+
24167+ movl $NR_CPUS,%ecx
24168+ movl $pa(cpu_gdt_table),%edi
24169+ addl $__PAGE_OFFSET,%eax
24170+1:
24171+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24172+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24173+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24174+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24175+ rorl $16,%eax
24176+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24177+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24178+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24179+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24180+ rorl $16,%eax
24181+ addl $PAGE_SIZE_asm,%edi
24182+ loop 1b
24183+#endif
24184+
24185 /*
24186 * Clear BSS first so that there are no surprises...
24187 */
24188@@ -201,8 +269,11 @@ ENTRY(startup_32)
24189 movl %eax, pa(max_pfn_mapped)
24190
24191 /* Do early initialization of the fixmap area */
24192- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24193- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24194+#ifdef CONFIG_COMPAT_VDSO
24195+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24196+#else
24197+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24198+#endif
24199 #else /* Not PAE */
24200
24201 page_pde_offset = (__PAGE_OFFSET >> 20);
24202@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24203 movl %eax, pa(max_pfn_mapped)
24204
24205 /* Do early initialization of the fixmap area */
24206- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24207- movl %eax,pa(initial_page_table+0xffc)
24208+#ifdef CONFIG_COMPAT_VDSO
24209+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24210+#else
24211+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24212+#endif
24213 #endif
24214
24215 #ifdef CONFIG_PARAVIRT
24216@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24217 cmpl $num_subarch_entries, %eax
24218 jae bad_subarch
24219
24220- movl pa(subarch_entries)(,%eax,4), %eax
24221- subl $__PAGE_OFFSET, %eax
24222- jmp *%eax
24223+ jmp *pa(subarch_entries)(,%eax,4)
24224
24225 bad_subarch:
24226 WEAK(lguest_entry)
24227@@ -261,10 +333,10 @@ WEAK(xen_entry)
24228 __INITDATA
24229
24230 subarch_entries:
24231- .long default_entry /* normal x86/PC */
24232- .long lguest_entry /* lguest hypervisor */
24233- .long xen_entry /* Xen hypervisor */
24234- .long default_entry /* Moorestown MID */
24235+ .long ta(default_entry) /* normal x86/PC */
24236+ .long ta(lguest_entry) /* lguest hypervisor */
24237+ .long ta(xen_entry) /* Xen hypervisor */
24238+ .long ta(default_entry) /* Moorestown MID */
24239 num_subarch_entries = (. - subarch_entries) / 4
24240 .previous
24241 #else
24242@@ -354,6 +426,7 @@ default_entry:
24243 movl pa(mmu_cr4_features),%eax
24244 movl %eax,%cr4
24245
24246+#ifdef CONFIG_X86_PAE
24247 testb $X86_CR4_PAE, %al # check if PAE is enabled
24248 jz enable_paging
24249
24250@@ -382,6 +455,9 @@ default_entry:
24251 /* Make changes effective */
24252 wrmsr
24253
24254+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24255+#endif
24256+
24257 enable_paging:
24258
24259 /*
24260@@ -449,14 +525,20 @@ is486:
24261 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24262 movl %eax,%ss # after changing gdt.
24263
24264- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24265+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24266 movl %eax,%ds
24267 movl %eax,%es
24268
24269 movl $(__KERNEL_PERCPU), %eax
24270 movl %eax,%fs # set this cpu's percpu
24271
24272+#ifdef CONFIG_CC_STACKPROTECTOR
24273 movl $(__KERNEL_STACK_CANARY),%eax
24274+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24275+ movl $(__USER_DS),%eax
24276+#else
24277+ xorl %eax,%eax
24278+#endif
24279 movl %eax,%gs
24280
24281 xorl %eax,%eax # Clear LDT
24282@@ -512,8 +594,11 @@ setup_once:
24283 * relocation. Manually set base address in stack canary
24284 * segment descriptor.
24285 */
24286- movl $gdt_page,%eax
24287+ movl $cpu_gdt_table,%eax
24288 movl $stack_canary,%ecx
24289+#ifdef CONFIG_SMP
24290+ addl $__per_cpu_load,%ecx
24291+#endif
24292 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24293 shrl $16, %ecx
24294 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24295@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24296 cmpl $2,(%esp) # X86_TRAP_NMI
24297 je is_nmi # Ignore NMI
24298
24299- cmpl $2,%ss:early_recursion_flag
24300+ cmpl $1,%ss:early_recursion_flag
24301 je hlt_loop
24302 incl %ss:early_recursion_flag
24303
24304@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24305 pushl (20+6*4)(%esp) /* trapno */
24306 pushl $fault_msg
24307 call printk
24308-#endif
24309 call dump_stack
24310+#endif
24311 hlt_loop:
24312 hlt
24313 jmp hlt_loop
24314@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24315 /* This is the default interrupt "handler" :-) */
24316 ALIGN
24317 ignore_int:
24318- cld
24319 #ifdef CONFIG_PRINTK
24320+ cmpl $2,%ss:early_recursion_flag
24321+ je hlt_loop
24322+ incl %ss:early_recursion_flag
24323+ cld
24324 pushl %eax
24325 pushl %ecx
24326 pushl %edx
24327@@ -617,9 +705,6 @@ ignore_int:
24328 movl $(__KERNEL_DS),%eax
24329 movl %eax,%ds
24330 movl %eax,%es
24331- cmpl $2,early_recursion_flag
24332- je hlt_loop
24333- incl early_recursion_flag
24334 pushl 16(%esp)
24335 pushl 24(%esp)
24336 pushl 32(%esp)
24337@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24338 /*
24339 * BSS section
24340 */
24341-__PAGE_ALIGNED_BSS
24342- .align PAGE_SIZE
24343 #ifdef CONFIG_X86_PAE
24344+.section .initial_pg_pmd,"a",@progbits
24345 initial_pg_pmd:
24346 .fill 1024*KPMDS,4,0
24347 #else
24348+.section .initial_page_table,"a",@progbits
24349 ENTRY(initial_page_table)
24350 .fill 1024,4,0
24351 #endif
24352+.section .initial_pg_fixmap,"a",@progbits
24353 initial_pg_fixmap:
24354 .fill 1024,4,0
24355+.section .empty_zero_page,"a",@progbits
24356 ENTRY(empty_zero_page)
24357 .fill 4096,1,0
24358+.section .swapper_pg_dir,"a",@progbits
24359 ENTRY(swapper_pg_dir)
24360+#ifdef CONFIG_X86_PAE
24361+ .fill 4,8,0
24362+#else
24363 .fill 1024,4,0
24364+#endif
24365
24366 /*
24367 * This starts the data section.
24368 */
24369 #ifdef CONFIG_X86_PAE
24370-__PAGE_ALIGNED_DATA
24371- /* Page-aligned for the benefit of paravirt? */
24372- .align PAGE_SIZE
24373+.section .initial_page_table,"a",@progbits
24374 ENTRY(initial_page_table)
24375 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24376 # if KPMDS == 3
24377@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24378 # error "Kernel PMDs should be 1, 2 or 3"
24379 # endif
24380 .align PAGE_SIZE /* needs to be page-sized too */
24381+
24382+#ifdef CONFIG_PAX_PER_CPU_PGD
24383+ENTRY(cpu_pgd)
24384+ .rept 2*NR_CPUS
24385+ .fill 4,8,0
24386+ .endr
24387+#endif
24388+
24389 #endif
24390
24391 .data
24392 .balign 4
24393 ENTRY(stack_start)
24394- .long init_thread_union+THREAD_SIZE
24395+ .long init_thread_union+THREAD_SIZE-8
24396
24397 __INITRODATA
24398 int_msg:
24399@@ -727,7 +825,7 @@ fault_msg:
24400 * segment size, and 32-bit linear address value:
24401 */
24402
24403- .data
24404+.section .rodata,"a",@progbits
24405 .globl boot_gdt_descr
24406 .globl idt_descr
24407
24408@@ -736,7 +834,7 @@ fault_msg:
24409 .word 0 # 32 bit align gdt_desc.address
24410 boot_gdt_descr:
24411 .word __BOOT_DS+7
24412- .long boot_gdt - __PAGE_OFFSET
24413+ .long pa(boot_gdt)
24414
24415 .word 0 # 32-bit align idt_desc.address
24416 idt_descr:
24417@@ -747,7 +845,7 @@ idt_descr:
24418 .word 0 # 32 bit align gdt_desc.address
24419 ENTRY(early_gdt_descr)
24420 .word GDT_ENTRIES*8-1
24421- .long gdt_page /* Overwritten for secondary CPUs */
24422+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24423
24424 /*
24425 * The boot_gdt must mirror the equivalent in setup.S and is
24426@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24427 .align L1_CACHE_BYTES
24428 ENTRY(boot_gdt)
24429 .fill GDT_ENTRY_BOOT_CS,8,0
24430- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24431- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24432+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24433+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24434+
24435+ .align PAGE_SIZE_asm
24436+ENTRY(cpu_gdt_table)
24437+ .rept NR_CPUS
24438+ .quad 0x0000000000000000 /* NULL descriptor */
24439+ .quad 0x0000000000000000 /* 0x0b reserved */
24440+ .quad 0x0000000000000000 /* 0x13 reserved */
24441+ .quad 0x0000000000000000 /* 0x1b reserved */
24442+
24443+#ifdef CONFIG_PAX_KERNEXEC
24444+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24445+#else
24446+ .quad 0x0000000000000000 /* 0x20 unused */
24447+#endif
24448+
24449+ .quad 0x0000000000000000 /* 0x28 unused */
24450+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24451+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24452+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24453+ .quad 0x0000000000000000 /* 0x4b reserved */
24454+ .quad 0x0000000000000000 /* 0x53 reserved */
24455+ .quad 0x0000000000000000 /* 0x5b reserved */
24456+
24457+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24458+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24459+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24460+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24461+
24462+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24463+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24464+
24465+ /*
24466+ * Segments used for calling PnP BIOS have byte granularity.
24467+ * The code segments and data segments have fixed 64k limits,
24468+ * the transfer segment sizes are set at run time.
24469+ */
24470+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24471+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24472+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24473+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24474+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24475+
24476+ /*
24477+ * The APM segments have byte granularity and their bases
24478+ * are set at run time. All have 64k limits.
24479+ */
24480+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24481+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24482+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24483+
24484+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24485+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24486+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24487+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24488+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24489+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24490+
24491+ /* Be sure this is zeroed to avoid false validations in Xen */
24492+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24493+ .endr
24494diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24495index a468c0a..c7dec74 100644
24496--- a/arch/x86/kernel/head_64.S
24497+++ b/arch/x86/kernel/head_64.S
24498@@ -20,6 +20,8 @@
24499 #include <asm/processor-flags.h>
24500 #include <asm/percpu.h>
24501 #include <asm/nops.h>
24502+#include <asm/cpufeature.h>
24503+#include <asm/alternative-asm.h>
24504
24505 #ifdef CONFIG_PARAVIRT
24506 #include <asm/asm-offsets.h>
24507@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24508 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24509 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24510 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24511+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24512+L3_VMALLOC_START = pud_index(VMALLOC_START)
24513+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24514+L3_VMALLOC_END = pud_index(VMALLOC_END)
24515+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24516+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24517
24518 .text
24519 __HEAD
24520@@ -89,11 +97,24 @@ startup_64:
24521 * Fixup the physical addresses in the page table
24522 */
24523 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24524+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24525+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24526+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24527+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24528+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24529
24530- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24531- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24532+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24533+#ifndef CONFIG_XEN
24534+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24535+#endif
24536+
24537+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24538+
24539+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24540+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24541
24542 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24543+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24544
24545 /*
24546 * Set up the identity mapping for the switchover. These
24547@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24548 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24549 1:
24550
24551- /* Enable PAE mode and PGE */
24552- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24553+ /* Enable PAE mode and PSE/PGE */
24554+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24555 movq %rcx, %cr4
24556
24557 /* Setup early boot stage 4 level pagetables. */
24558@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24559 movl $MSR_EFER, %ecx
24560 rdmsr
24561 btsl $_EFER_SCE, %eax /* Enable System Call */
24562- btl $20,%edi /* No Execute supported? */
24563+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24564 jnc 1f
24565 btsl $_EFER_NX, %eax
24566 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24567+#ifndef CONFIG_EFI
24568+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24569+#endif
24570+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24571+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24572+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24573+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24574+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24575+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24576 1: wrmsr /* Make changes effective */
24577
24578 /* Setup cr0 */
24579@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24580 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24581 * address given in m16:64.
24582 */
24583+ pax_set_fptr_mask
24584 movq initial_code(%rip),%rax
24585 pushq $0 # fake return address to stop unwinder
24586 pushq $__KERNEL_CS # set correct cs
24587@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24588 .quad INIT_PER_CPU_VAR(irq_stack_union)
24589
24590 GLOBAL(stack_start)
24591- .quad init_thread_union+THREAD_SIZE-8
24592+ .quad init_thread_union+THREAD_SIZE-16
24593 .word 0
24594 __FINITDATA
24595
24596@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24597 call dump_stack
24598 #ifdef CONFIG_KALLSYMS
24599 leaq early_idt_ripmsg(%rip),%rdi
24600- movq 40(%rsp),%rsi # %rip again
24601+ movq 88(%rsp),%rsi # %rip again
24602 call __print_symbol
24603 #endif
24604 #endif /* EARLY_PRINTK */
24605@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24606 early_recursion_flag:
24607 .long 0
24608
24609+ .section .rodata,"a",@progbits
24610 #ifdef CONFIG_EARLY_PRINTK
24611 early_idt_msg:
24612 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24613@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24614 NEXT_PAGE(early_dynamic_pgts)
24615 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24616
24617- .data
24618+ .section .rodata,"a",@progbits
24619
24620-#ifndef CONFIG_XEN
24621 NEXT_PAGE(init_level4_pgt)
24622- .fill 512,8,0
24623-#else
24624-NEXT_PAGE(init_level4_pgt)
24625- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24626 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24627 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24628+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24629+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24630+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24631+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24632+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24633+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24634 .org init_level4_pgt + L4_START_KERNEL*8, 0
24635 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24636 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24637
24638+#ifdef CONFIG_PAX_PER_CPU_PGD
24639+NEXT_PAGE(cpu_pgd)
24640+ .rept 2*NR_CPUS
24641+ .fill 512,8,0
24642+ .endr
24643+#endif
24644+
24645 NEXT_PAGE(level3_ident_pgt)
24646 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24647+#ifdef CONFIG_XEN
24648 .fill 511, 8, 0
24649+#else
24650+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24651+ .fill 510,8,0
24652+#endif
24653+
24654+NEXT_PAGE(level3_vmalloc_start_pgt)
24655+ .fill 512,8,0
24656+
24657+NEXT_PAGE(level3_vmalloc_end_pgt)
24658+ .fill 512,8,0
24659+
24660+NEXT_PAGE(level3_vmemmap_pgt)
24661+ .fill L3_VMEMMAP_START,8,0
24662+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24663+
24664 NEXT_PAGE(level2_ident_pgt)
24665- /* Since I easily can, map the first 1G.
24666+ /* Since I easily can, map the first 2G.
24667 * Don't set NX because code runs from these pages.
24668 */
24669- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24670-#endif
24671+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24672
24673 NEXT_PAGE(level3_kernel_pgt)
24674 .fill L3_START_KERNEL,8,0
24675@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24676 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24677 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24678
24679+NEXT_PAGE(level2_vmemmap_pgt)
24680+ .fill 512,8,0
24681+
24682 NEXT_PAGE(level2_kernel_pgt)
24683 /*
24684 * 512 MB kernel mapping. We spend a full page on this pagetable
24685@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24686 NEXT_PAGE(level2_fixmap_pgt)
24687 .fill 506,8,0
24688 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24689- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24690- .fill 5,8,0
24691+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24692+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24693+ .fill 4,8,0
24694
24695 NEXT_PAGE(level1_fixmap_pgt)
24696 .fill 512,8,0
24697
24698+NEXT_PAGE(level1_vsyscall_pgt)
24699+ .fill 512,8,0
24700+
24701 #undef PMDS
24702
24703- .data
24704+ .align PAGE_SIZE
24705+ENTRY(cpu_gdt_table)
24706+ .rept NR_CPUS
24707+ .quad 0x0000000000000000 /* NULL descriptor */
24708+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24709+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24710+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24711+ .quad 0x00cffb000000ffff /* __USER32_CS */
24712+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24713+ .quad 0x00affb000000ffff /* __USER_CS */
24714+
24715+#ifdef CONFIG_PAX_KERNEXEC
24716+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24717+#else
24718+ .quad 0x0 /* unused */
24719+#endif
24720+
24721+ .quad 0,0 /* TSS */
24722+ .quad 0,0 /* LDT */
24723+ .quad 0,0,0 /* three TLS descriptors */
24724+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24725+ /* asm/segment.h:GDT_ENTRIES must match this */
24726+
24727+#ifdef CONFIG_PAX_MEMORY_UDEREF
24728+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24729+#else
24730+ .quad 0x0 /* unused */
24731+#endif
24732+
24733+ /* zero the remaining page */
24734+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24735+ .endr
24736+
24737 .align 16
24738 .globl early_gdt_descr
24739 early_gdt_descr:
24740 .word GDT_ENTRIES*8-1
24741 early_gdt_descr_base:
24742- .quad INIT_PER_CPU_VAR(gdt_page)
24743+ .quad cpu_gdt_table
24744
24745 ENTRY(phys_base)
24746 /* This must match the first entry in level2_kernel_pgt */
24747 .quad 0x0000000000000000
24748
24749 #include "../../x86/xen/xen-head.S"
24750-
24751- __PAGE_ALIGNED_BSS
24752+
24753+ .section .rodata,"a",@progbits
24754 NEXT_PAGE(empty_zero_page)
24755 .skip PAGE_SIZE
24756diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24757index 05fd74f..c3548b1 100644
24758--- a/arch/x86/kernel/i386_ksyms_32.c
24759+++ b/arch/x86/kernel/i386_ksyms_32.c
24760@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24761 EXPORT_SYMBOL(cmpxchg8b_emu);
24762 #endif
24763
24764+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24765+
24766 /* Networking helper routines. */
24767 EXPORT_SYMBOL(csum_partial_copy_generic);
24768+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24769+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24770
24771 EXPORT_SYMBOL(__get_user_1);
24772 EXPORT_SYMBOL(__get_user_2);
24773@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24774 EXPORT_SYMBOL(___preempt_schedule_context);
24775 #endif
24776 #endif
24777+
24778+#ifdef CONFIG_PAX_KERNEXEC
24779+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24780+#endif
24781+
24782+#ifdef CONFIG_PAX_PER_CPU_PGD
24783+EXPORT_SYMBOL(cpu_pgd);
24784+#endif
24785diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24786index d5dd808..b6432cf 100644
24787--- a/arch/x86/kernel/i387.c
24788+++ b/arch/x86/kernel/i387.c
24789@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24790 static inline bool interrupted_user_mode(void)
24791 {
24792 struct pt_regs *regs = get_irq_regs();
24793- return regs && user_mode_vm(regs);
24794+ return regs && user_mode(regs);
24795 }
24796
24797 /*
24798diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24799index 2e977b5..5f2c273 100644
24800--- a/arch/x86/kernel/i8259.c
24801+++ b/arch/x86/kernel/i8259.c
24802@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24803 static void make_8259A_irq(unsigned int irq)
24804 {
24805 disable_irq_nosync(irq);
24806- io_apic_irqs &= ~(1<<irq);
24807+ io_apic_irqs &= ~(1UL<<irq);
24808 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24809 i8259A_chip.name);
24810 enable_irq(irq);
24811@@ -209,7 +209,7 @@ spurious_8259A_irq:
24812 "spurious 8259A interrupt: IRQ%d.\n", irq);
24813 spurious_irq_mask |= irqmask;
24814 }
24815- atomic_inc(&irq_err_count);
24816+ atomic_inc_unchecked(&irq_err_count);
24817 /*
24818 * Theoretically we do not have to handle this IRQ,
24819 * but in Linux this does not cause problems and is
24820@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24821 /* (slave's support for AEOI in flat mode is to be investigated) */
24822 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24823
24824+ pax_open_kernel();
24825 if (auto_eoi)
24826 /*
24827 * In AEOI mode we just have to mask the interrupt
24828 * when acking.
24829 */
24830- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24831+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24832 else
24833- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24834+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24835+ pax_close_kernel();
24836
24837 udelay(100); /* wait for 8259A to initialize */
24838
24839diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24840index a979b5b..1d6db75 100644
24841--- a/arch/x86/kernel/io_delay.c
24842+++ b/arch/x86/kernel/io_delay.c
24843@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24844 * Quirk table for systems that misbehave (lock up, etc.) if port
24845 * 0x80 is used:
24846 */
24847-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24848+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24849 {
24850 .callback = dmi_io_delay_0xed_port,
24851 .ident = "Compaq Presario V6000",
24852diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24853index 4ddaf66..49d5c18 100644
24854--- a/arch/x86/kernel/ioport.c
24855+++ b/arch/x86/kernel/ioport.c
24856@@ -6,6 +6,7 @@
24857 #include <linux/sched.h>
24858 #include <linux/kernel.h>
24859 #include <linux/capability.h>
24860+#include <linux/security.h>
24861 #include <linux/errno.h>
24862 #include <linux/types.h>
24863 #include <linux/ioport.h>
24864@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24865 return -EINVAL;
24866 if (turn_on && !capable(CAP_SYS_RAWIO))
24867 return -EPERM;
24868+#ifdef CONFIG_GRKERNSEC_IO
24869+ if (turn_on && grsec_disable_privio) {
24870+ gr_handle_ioperm();
24871+ return -ENODEV;
24872+ }
24873+#endif
24874
24875 /*
24876 * If it's the first ioperm() call in this thread's lifetime, set the
24877@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24878 * because the ->io_bitmap_max value must match the bitmap
24879 * contents:
24880 */
24881- tss = &per_cpu(init_tss, get_cpu());
24882+ tss = init_tss + get_cpu();
24883
24884 if (turn_on)
24885 bitmap_clear(t->io_bitmap_ptr, from, num);
24886@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24887 if (level > old) {
24888 if (!capable(CAP_SYS_RAWIO))
24889 return -EPERM;
24890+#ifdef CONFIG_GRKERNSEC_IO
24891+ if (grsec_disable_privio) {
24892+ gr_handle_iopl();
24893+ return -ENODEV;
24894+ }
24895+#endif
24896 }
24897 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24898 t->iopl = level << 12;
24899diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24900index d99f31d..1c0f466 100644
24901--- a/arch/x86/kernel/irq.c
24902+++ b/arch/x86/kernel/irq.c
24903@@ -21,7 +21,7 @@
24904 #define CREATE_TRACE_POINTS
24905 #include <asm/trace/irq_vectors.h>
24906
24907-atomic_t irq_err_count;
24908+atomic_unchecked_t irq_err_count;
24909
24910 /* Function pointer for generic interrupt vector handling */
24911 void (*x86_platform_ipi_callback)(void) = NULL;
24912@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24913 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24914 seq_printf(p, " Machine check polls\n");
24915 #endif
24916- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24917+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24918 #if defined(CONFIG_X86_IO_APIC)
24919- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24920+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24921 #endif
24922 return 0;
24923 }
24924@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24925
24926 u64 arch_irq_stat(void)
24927 {
24928- u64 sum = atomic_read(&irq_err_count);
24929+ u64 sum = atomic_read_unchecked(&irq_err_count);
24930 return sum;
24931 }
24932
24933diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24934index d7fcbed..96e715a 100644
24935--- a/arch/x86/kernel/irq_32.c
24936+++ b/arch/x86/kernel/irq_32.c
24937@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
24938
24939 #ifdef CONFIG_DEBUG_STACKOVERFLOW
24940
24941+extern void gr_handle_kernel_exploit(void);
24942+
24943 int sysctl_panic_on_stackoverflow __read_mostly;
24944
24945 /* Debugging check for stack overflow: is there less than 1KB free? */
24946@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
24947 __asm__ __volatile__("andl %%esp,%0" :
24948 "=r" (sp) : "0" (THREAD_SIZE - 1));
24949
24950- return sp < (sizeof(struct thread_info) + STACK_WARN);
24951+ return sp < STACK_WARN;
24952 }
24953
24954 static void print_stack_overflow(void)
24955 {
24956 printk(KERN_WARNING "low stack detected by irq handler\n");
24957 dump_stack();
24958+ gr_handle_kernel_exploit();
24959 if (sysctl_panic_on_stackoverflow)
24960 panic("low stack detected by irq handler - check messages\n");
24961 }
24962@@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
24963 * per-CPU IRQ handling contexts (thread information and stack)
24964 */
24965 union irq_ctx {
24966- struct thread_info tinfo;
24967- u32 stack[THREAD_SIZE/sizeof(u32)];
24968+ unsigned long previous_esp;
24969+ u32 stack[THREAD_SIZE/sizeof(u32)];
24970 } __attribute__((aligned(THREAD_SIZE)));
24971
24972 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24973@@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
24974 static inline int
24975 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24976 {
24977- union irq_ctx *curctx, *irqctx;
24978+ union irq_ctx *irqctx;
24979 u32 *isp, arg1, arg2;
24980
24981- curctx = (union irq_ctx *) current_thread_info();
24982 irqctx = __this_cpu_read(hardirq_ctx);
24983
24984 /*
24985@@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24986 * handler) we can't do that and just have to keep using the
24987 * current stack (which is the irq stack already after all)
24988 */
24989- if (unlikely(curctx == irqctx))
24990+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24991 return 0;
24992
24993 /* build the stack frame on the IRQ stack */
24994- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24995- irqctx->tinfo.task = curctx->tinfo.task;
24996- irqctx->tinfo.previous_esp = current_stack_pointer;
24997+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24998+ irqctx->previous_esp = current_stack_pointer;
24999+
25000+#ifdef CONFIG_PAX_MEMORY_UDEREF
25001+ __set_fs(MAKE_MM_SEG(0));
25002+#endif
25003
25004 if (unlikely(overflow))
25005 call_on_stack(print_stack_overflow, isp);
25006@@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25007 : "0" (irq), "1" (desc), "2" (isp),
25008 "D" (desc->handle_irq)
25009 : "memory", "cc", "ecx");
25010+
25011+#ifdef CONFIG_PAX_MEMORY_UDEREF
25012+ __set_fs(current_thread_info()->addr_limit);
25013+#endif
25014+
25015 return 1;
25016 }
25017
25018@@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25019 */
25020 void irq_ctx_init(int cpu)
25021 {
25022- union irq_ctx *irqctx;
25023-
25024 if (per_cpu(hardirq_ctx, cpu))
25025 return;
25026
25027- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25028- THREADINFO_GFP,
25029- THREAD_SIZE_ORDER));
25030- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25031- irqctx->tinfo.cpu = cpu;
25032- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25033-
25034- per_cpu(hardirq_ctx, cpu) = irqctx;
25035-
25036- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25037- THREADINFO_GFP,
25038- THREAD_SIZE_ORDER));
25039- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25040- irqctx->tinfo.cpu = cpu;
25041- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25042-
25043- per_cpu(softirq_ctx, cpu) = irqctx;
25044-
25045- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25046- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
25047+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25048+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25049 }
25050
25051 void do_softirq_own_stack(void)
25052 {
25053- struct thread_info *curctx;
25054 union irq_ctx *irqctx;
25055 u32 *isp;
25056
25057- curctx = current_thread_info();
25058 irqctx = __this_cpu_read(softirq_ctx);
25059- irqctx->tinfo.task = curctx->task;
25060- irqctx->tinfo.previous_esp = current_stack_pointer;
25061+ irqctx->previous_esp = current_stack_pointer;
25062
25063 /* build the stack frame on the softirq stack */
25064- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25065+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25066+
25067+#ifdef CONFIG_PAX_MEMORY_UDEREF
25068+ __set_fs(MAKE_MM_SEG(0));
25069+#endif
25070
25071 call_on_stack(__do_softirq, isp);
25072+
25073+#ifdef CONFIG_PAX_MEMORY_UDEREF
25074+ __set_fs(current_thread_info()->addr_limit);
25075+#endif
25076+
25077 }
25078
25079 bool handle_irq(unsigned irq, struct pt_regs *regs)
25080@@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25081 if (unlikely(!desc))
25082 return false;
25083
25084- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25085+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25086 if (unlikely(overflow))
25087 print_stack_overflow();
25088 desc->handle_irq(irq, desc);
25089diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25090index 4d1c746..55a22d6 100644
25091--- a/arch/x86/kernel/irq_64.c
25092+++ b/arch/x86/kernel/irq_64.c
25093@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25094 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25095 EXPORT_PER_CPU_SYMBOL(irq_regs);
25096
25097+extern void gr_handle_kernel_exploit(void);
25098+
25099 int sysctl_panic_on_stackoverflow;
25100
25101 /*
25102@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25103 u64 estack_top, estack_bottom;
25104 u64 curbase = (u64)task_stack_page(current);
25105
25106- if (user_mode_vm(regs))
25107+ if (user_mode(regs))
25108 return;
25109
25110 if (regs->sp >= curbase + sizeof(struct thread_info) +
25111@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25112 irq_stack_top, irq_stack_bottom,
25113 estack_top, estack_bottom);
25114
25115+ gr_handle_kernel_exploit();
25116+
25117 if (sysctl_panic_on_stackoverflow)
25118 panic("low stack detected by irq handler - check messages\n");
25119 #endif
25120diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25121index 26d5a55..a01160a 100644
25122--- a/arch/x86/kernel/jump_label.c
25123+++ b/arch/x86/kernel/jump_label.c
25124@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25125 * Jump label is enabled for the first time.
25126 * So we expect a default_nop...
25127 */
25128- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25129+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25130 != 0))
25131 bug_at((void *)entry->code, __LINE__);
25132 } else {
25133@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25134 * ...otherwise expect an ideal_nop. Otherwise
25135 * something went horribly wrong.
25136 */
25137- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25138+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25139 != 0))
25140 bug_at((void *)entry->code, __LINE__);
25141 }
25142@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25143 * are converting the default nop to the ideal nop.
25144 */
25145 if (init) {
25146- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25147+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25148 bug_at((void *)entry->code, __LINE__);
25149 } else {
25150 code.jump = 0xe9;
25151 code.offset = entry->target -
25152 (entry->code + JUMP_LABEL_NOP_SIZE);
25153- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25154+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25155 bug_at((void *)entry->code, __LINE__);
25156 }
25157 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25158diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25159index 7ec1d5f..5a7d130 100644
25160--- a/arch/x86/kernel/kgdb.c
25161+++ b/arch/x86/kernel/kgdb.c
25162@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25163 #ifdef CONFIG_X86_32
25164 switch (regno) {
25165 case GDB_SS:
25166- if (!user_mode_vm(regs))
25167+ if (!user_mode(regs))
25168 *(unsigned long *)mem = __KERNEL_DS;
25169 break;
25170 case GDB_SP:
25171- if (!user_mode_vm(regs))
25172+ if (!user_mode(regs))
25173 *(unsigned long *)mem = kernel_stack_pointer(regs);
25174 break;
25175 case GDB_GS:
25176@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25177 bp->attr.bp_addr = breakinfo[breakno].addr;
25178 bp->attr.bp_len = breakinfo[breakno].len;
25179 bp->attr.bp_type = breakinfo[breakno].type;
25180- info->address = breakinfo[breakno].addr;
25181+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25182+ info->address = ktla_ktva(breakinfo[breakno].addr);
25183+ else
25184+ info->address = breakinfo[breakno].addr;
25185 info->len = breakinfo[breakno].len;
25186 info->type = breakinfo[breakno].type;
25187 val = arch_install_hw_breakpoint(bp);
25188@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25189 case 'k':
25190 /* clear the trace bit */
25191 linux_regs->flags &= ~X86_EFLAGS_TF;
25192- atomic_set(&kgdb_cpu_doing_single_step, -1);
25193+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25194
25195 /* set the trace bit if we're stepping */
25196 if (remcomInBuffer[0] == 's') {
25197 linux_regs->flags |= X86_EFLAGS_TF;
25198- atomic_set(&kgdb_cpu_doing_single_step,
25199+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25200 raw_smp_processor_id());
25201 }
25202
25203@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25204
25205 switch (cmd) {
25206 case DIE_DEBUG:
25207- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25208+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25209 if (user_mode(regs))
25210 return single_step_cont(regs, args);
25211 break;
25212@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25213 #endif /* CONFIG_DEBUG_RODATA */
25214
25215 bpt->type = BP_BREAKPOINT;
25216- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25217+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25218 BREAK_INSTR_SIZE);
25219 if (err)
25220 return err;
25221- err = probe_kernel_write((char *)bpt->bpt_addr,
25222+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25223 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25224 #ifdef CONFIG_DEBUG_RODATA
25225 if (!err)
25226@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25227 return -EBUSY;
25228 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25229 BREAK_INSTR_SIZE);
25230- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25231+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25232 if (err)
25233 return err;
25234 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25235@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25236 if (mutex_is_locked(&text_mutex))
25237 goto knl_write;
25238 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25239- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25240+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25241 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25242 goto knl_write;
25243 return err;
25244 knl_write:
25245 #endif /* CONFIG_DEBUG_RODATA */
25246- return probe_kernel_write((char *)bpt->bpt_addr,
25247+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25248 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25249 }
25250
25251diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25252index 79a3f96..6ba030a 100644
25253--- a/arch/x86/kernel/kprobes/core.c
25254+++ b/arch/x86/kernel/kprobes/core.c
25255@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25256 s32 raddr;
25257 } __packed *insn;
25258
25259- insn = (struct __arch_relative_insn *)from;
25260+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25261+
25262+ pax_open_kernel();
25263 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25264 insn->op = op;
25265+ pax_close_kernel();
25266 }
25267
25268 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25269@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25270 kprobe_opcode_t opcode;
25271 kprobe_opcode_t *orig_opcodes = opcodes;
25272
25273- if (search_exception_tables((unsigned long)opcodes))
25274+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25275 return 0; /* Page fault may occur on this address. */
25276
25277 retry:
25278@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25279 * for the first byte, we can recover the original instruction
25280 * from it and kp->opcode.
25281 */
25282- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25283+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25284 buf[0] = kp->opcode;
25285- return (unsigned long)buf;
25286+ return ktva_ktla((unsigned long)buf);
25287 }
25288
25289 /*
25290@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25291 /* Another subsystem puts a breakpoint, failed to recover */
25292 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25293 return 0;
25294+ pax_open_kernel();
25295 memcpy(dest, insn.kaddr, insn.length);
25296+ pax_close_kernel();
25297
25298 #ifdef CONFIG_X86_64
25299 if (insn_rip_relative(&insn)) {
25300@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25301 return 0;
25302 }
25303 disp = (u8 *) dest + insn_offset_displacement(&insn);
25304+ pax_open_kernel();
25305 *(s32 *) disp = (s32) newdisp;
25306+ pax_close_kernel();
25307 }
25308 #endif
25309 return insn.length;
25310@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25311 * nor set current_kprobe, because it doesn't use single
25312 * stepping.
25313 */
25314- regs->ip = (unsigned long)p->ainsn.insn;
25315+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25316 preempt_enable_no_resched();
25317 return;
25318 }
25319@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25320 regs->flags &= ~X86_EFLAGS_IF;
25321 /* single step inline if the instruction is an int3 */
25322 if (p->opcode == BREAKPOINT_INSTRUCTION)
25323- regs->ip = (unsigned long)p->addr;
25324+ regs->ip = ktla_ktva((unsigned long)p->addr);
25325 else
25326- regs->ip = (unsigned long)p->ainsn.insn;
25327+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25328 }
25329
25330 /*
25331@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25332 setup_singlestep(p, regs, kcb, 0);
25333 return 1;
25334 }
25335- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25336+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25337 /*
25338 * The breakpoint instruction was removed right
25339 * after we hit it. Another cpu has removed
25340@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25341 " movq %rax, 152(%rsp)\n"
25342 RESTORE_REGS_STRING
25343 " popfq\n"
25344+#ifdef KERNEXEC_PLUGIN
25345+ " btsq $63,(%rsp)\n"
25346+#endif
25347 #else
25348 " pushf\n"
25349 SAVE_REGS_STRING
25350@@ -779,7 +789,7 @@ static void __kprobes
25351 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25352 {
25353 unsigned long *tos = stack_addr(regs);
25354- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25355+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25356 unsigned long orig_ip = (unsigned long)p->addr;
25357 kprobe_opcode_t *insn = p->ainsn.insn;
25358
25359@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25360 struct die_args *args = data;
25361 int ret = NOTIFY_DONE;
25362
25363- if (args->regs && user_mode_vm(args->regs))
25364+ if (args->regs && user_mode(args->regs))
25365 return ret;
25366
25367 switch (val) {
25368diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25369index 898160b..758cde8 100644
25370--- a/arch/x86/kernel/kprobes/opt.c
25371+++ b/arch/x86/kernel/kprobes/opt.c
25372@@ -79,6 +79,7 @@ found:
25373 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25374 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25375 {
25376+ pax_open_kernel();
25377 #ifdef CONFIG_X86_64
25378 *addr++ = 0x48;
25379 *addr++ = 0xbf;
25380@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25381 *addr++ = 0xb8;
25382 #endif
25383 *(unsigned long *)addr = val;
25384+ pax_close_kernel();
25385 }
25386
25387 asm (
25388@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25389 * Verify if the address gap is in 2GB range, because this uses
25390 * a relative jump.
25391 */
25392- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25393+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25394 if (abs(rel) > 0x7fffffff)
25395 return -ERANGE;
25396
25397@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25398 op->optinsn.size = ret;
25399
25400 /* Copy arch-dep-instance from template */
25401- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25402+ pax_open_kernel();
25403+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25404+ pax_close_kernel();
25405
25406 /* Set probe information */
25407 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25408
25409 /* Set probe function call */
25410- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25411+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25412
25413 /* Set returning jmp instruction at the tail of out-of-line buffer */
25414- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25415+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25416 (u8 *)op->kp.addr + op->optinsn.size);
25417
25418 flush_icache_range((unsigned long) buf,
25419@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25420 WARN_ON(kprobe_disabled(&op->kp));
25421
25422 /* Backup instructions which will be replaced by jump address */
25423- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25424+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25425 RELATIVE_ADDR_SIZE);
25426
25427 insn_buf[0] = RELATIVEJUMP_OPCODE;
25428@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25429 /* This kprobe is really able to run optimized path. */
25430 op = container_of(p, struct optimized_kprobe, kp);
25431 /* Detour through copied instructions */
25432- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25433+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25434 if (!reenter)
25435 reset_current_kprobe();
25436 preempt_enable_no_resched();
25437diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25438index c2bedae..25e7ab6 100644
25439--- a/arch/x86/kernel/ksysfs.c
25440+++ b/arch/x86/kernel/ksysfs.c
25441@@ -184,7 +184,7 @@ out:
25442
25443 static struct kobj_attribute type_attr = __ATTR_RO(type);
25444
25445-static struct bin_attribute data_attr = {
25446+static bin_attribute_no_const data_attr __read_only = {
25447 .attr = {
25448 .name = "data",
25449 .mode = S_IRUGO,
25450diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25451index af1d14a..37b8776 100644
25452--- a/arch/x86/kernel/ldt.c
25453+++ b/arch/x86/kernel/ldt.c
25454@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25455 if (reload) {
25456 #ifdef CONFIG_SMP
25457 preempt_disable();
25458- load_LDT(pc);
25459+ load_LDT_nolock(pc);
25460 if (!cpumask_equal(mm_cpumask(current->mm),
25461 cpumask_of(smp_processor_id())))
25462 smp_call_function(flush_ldt, current->mm, 1);
25463 preempt_enable();
25464 #else
25465- load_LDT(pc);
25466+ load_LDT_nolock(pc);
25467 #endif
25468 }
25469 if (oldsize) {
25470@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25471 return err;
25472
25473 for (i = 0; i < old->size; i++)
25474- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25475+ write_ldt_entry(new->ldt, i, old->ldt + i);
25476 return 0;
25477 }
25478
25479@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25480 retval = copy_ldt(&mm->context, &old_mm->context);
25481 mutex_unlock(&old_mm->context.lock);
25482 }
25483+
25484+ if (tsk == current) {
25485+ mm->context.vdso = 0;
25486+
25487+#ifdef CONFIG_X86_32
25488+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25489+ mm->context.user_cs_base = 0UL;
25490+ mm->context.user_cs_limit = ~0UL;
25491+
25492+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25493+ cpus_clear(mm->context.cpu_user_cs_mask);
25494+#endif
25495+
25496+#endif
25497+#endif
25498+
25499+ }
25500+
25501 return retval;
25502 }
25503
25504@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25505 }
25506 }
25507
25508+#ifdef CONFIG_PAX_SEGMEXEC
25509+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25510+ error = -EINVAL;
25511+ goto out_unlock;
25512+ }
25513+#endif
25514+
25515 /*
25516 * On x86-64 we do not support 16-bit segments due to
25517 * IRET leaking the high bits of the kernel stack address.
25518diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25519index 1667b1d..16492c5 100644
25520--- a/arch/x86/kernel/machine_kexec_32.c
25521+++ b/arch/x86/kernel/machine_kexec_32.c
25522@@ -25,7 +25,7 @@
25523 #include <asm/cacheflush.h>
25524 #include <asm/debugreg.h>
25525
25526-static void set_idt(void *newidt, __u16 limit)
25527+static void set_idt(struct desc_struct *newidt, __u16 limit)
25528 {
25529 struct desc_ptr curidt;
25530
25531@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25532 }
25533
25534
25535-static void set_gdt(void *newgdt, __u16 limit)
25536+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25537 {
25538 struct desc_ptr curgdt;
25539
25540@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25541 }
25542
25543 control_page = page_address(image->control_code_page);
25544- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25545+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25546
25547 relocate_kernel_ptr = control_page;
25548 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25549diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25550index 18be189..4a9fe40 100644
25551--- a/arch/x86/kernel/module.c
25552+++ b/arch/x86/kernel/module.c
25553@@ -43,15 +43,60 @@ do { \
25554 } while (0)
25555 #endif
25556
25557-void *module_alloc(unsigned long size)
25558+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25559 {
25560- if (PAGE_ALIGN(size) > MODULES_LEN)
25561+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25562 return NULL;
25563 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25564- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25565+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25566 NUMA_NO_NODE, __builtin_return_address(0));
25567 }
25568
25569+void *module_alloc(unsigned long size)
25570+{
25571+
25572+#ifdef CONFIG_PAX_KERNEXEC
25573+ return __module_alloc(size, PAGE_KERNEL);
25574+#else
25575+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25576+#endif
25577+
25578+}
25579+
25580+#ifdef CONFIG_PAX_KERNEXEC
25581+#ifdef CONFIG_X86_32
25582+void *module_alloc_exec(unsigned long size)
25583+{
25584+ struct vm_struct *area;
25585+
25586+ if (size == 0)
25587+ return NULL;
25588+
25589+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25590+ return area ? area->addr : NULL;
25591+}
25592+EXPORT_SYMBOL(module_alloc_exec);
25593+
25594+void module_free_exec(struct module *mod, void *module_region)
25595+{
25596+ vunmap(module_region);
25597+}
25598+EXPORT_SYMBOL(module_free_exec);
25599+#else
25600+void module_free_exec(struct module *mod, void *module_region)
25601+{
25602+ module_free(mod, module_region);
25603+}
25604+EXPORT_SYMBOL(module_free_exec);
25605+
25606+void *module_alloc_exec(unsigned long size)
25607+{
25608+ return __module_alloc(size, PAGE_KERNEL_RX);
25609+}
25610+EXPORT_SYMBOL(module_alloc_exec);
25611+#endif
25612+#endif
25613+
25614 #ifdef CONFIG_X86_32
25615 int apply_relocate(Elf32_Shdr *sechdrs,
25616 const char *strtab,
25617@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25618 unsigned int i;
25619 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25620 Elf32_Sym *sym;
25621- uint32_t *location;
25622+ uint32_t *plocation, location;
25623
25624 DEBUGP("Applying relocate section %u to %u\n",
25625 relsec, sechdrs[relsec].sh_info);
25626 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25627 /* This is where to make the change */
25628- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25629- + rel[i].r_offset;
25630+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25631+ location = (uint32_t)plocation;
25632+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25633+ plocation = ktla_ktva((void *)plocation);
25634 /* This is the symbol it is referring to. Note that all
25635 undefined symbols have been resolved. */
25636 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25637@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25638 switch (ELF32_R_TYPE(rel[i].r_info)) {
25639 case R_386_32:
25640 /* We add the value into the location given */
25641- *location += sym->st_value;
25642+ pax_open_kernel();
25643+ *plocation += sym->st_value;
25644+ pax_close_kernel();
25645 break;
25646 case R_386_PC32:
25647 /* Add the value, subtract its position */
25648- *location += sym->st_value - (uint32_t)location;
25649+ pax_open_kernel();
25650+ *plocation += sym->st_value - location;
25651+ pax_close_kernel();
25652 break;
25653 default:
25654 pr_err("%s: Unknown relocation: %u\n",
25655@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25656 case R_X86_64_NONE:
25657 break;
25658 case R_X86_64_64:
25659+ pax_open_kernel();
25660 *(u64 *)loc = val;
25661+ pax_close_kernel();
25662 break;
25663 case R_X86_64_32:
25664+ pax_open_kernel();
25665 *(u32 *)loc = val;
25666+ pax_close_kernel();
25667 if (val != *(u32 *)loc)
25668 goto overflow;
25669 break;
25670 case R_X86_64_32S:
25671+ pax_open_kernel();
25672 *(s32 *)loc = val;
25673+ pax_close_kernel();
25674 if ((s64)val != *(s32 *)loc)
25675 goto overflow;
25676 break;
25677 case R_X86_64_PC32:
25678 val -= (u64)loc;
25679+ pax_open_kernel();
25680 *(u32 *)loc = val;
25681+ pax_close_kernel();
25682+
25683 #if 0
25684 if ((s64)val != *(s32 *)loc)
25685 goto overflow;
25686diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25687index 05266b5..3432443 100644
25688--- a/arch/x86/kernel/msr.c
25689+++ b/arch/x86/kernel/msr.c
25690@@ -37,6 +37,7 @@
25691 #include <linux/notifier.h>
25692 #include <linux/uaccess.h>
25693 #include <linux/gfp.h>
25694+#include <linux/grsecurity.h>
25695
25696 #include <asm/processor.h>
25697 #include <asm/msr.h>
25698@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25699 int err = 0;
25700 ssize_t bytes = 0;
25701
25702+#ifdef CONFIG_GRKERNSEC_KMEM
25703+ gr_handle_msr_write();
25704+ return -EPERM;
25705+#endif
25706+
25707 if (count % 8)
25708 return -EINVAL; /* Invalid chunk size */
25709
25710@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25711 err = -EBADF;
25712 break;
25713 }
25714+#ifdef CONFIG_GRKERNSEC_KMEM
25715+ gr_handle_msr_write();
25716+ return -EPERM;
25717+#endif
25718 if (copy_from_user(&regs, uregs, sizeof regs)) {
25719 err = -EFAULT;
25720 break;
25721@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25722 return notifier_from_errno(err);
25723 }
25724
25725-static struct notifier_block __refdata msr_class_cpu_notifier = {
25726+static struct notifier_block msr_class_cpu_notifier = {
25727 .notifier_call = msr_class_cpu_callback,
25728 };
25729
25730diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25731index 6fcb49c..5b3f4ff 100644
25732--- a/arch/x86/kernel/nmi.c
25733+++ b/arch/x86/kernel/nmi.c
25734@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25735 return handled;
25736 }
25737
25738-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25739+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25740 {
25741 struct nmi_desc *desc = nmi_to_desc(type);
25742 unsigned long flags;
25743@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25744 * event confuses some handlers (kdump uses this flag)
25745 */
25746 if (action->flags & NMI_FLAG_FIRST)
25747- list_add_rcu(&action->list, &desc->head);
25748+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25749 else
25750- list_add_tail_rcu(&action->list, &desc->head);
25751+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25752
25753 spin_unlock_irqrestore(&desc->lock, flags);
25754 return 0;
25755@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25756 if (!strcmp(n->name, name)) {
25757 WARN(in_nmi(),
25758 "Trying to free NMI (%s) from NMI context!\n", n->name);
25759- list_del_rcu(&n->list);
25760+ pax_list_del_rcu((struct list_head *)&n->list);
25761 break;
25762 }
25763 }
25764@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25765 dotraplinkage notrace __kprobes void
25766 do_nmi(struct pt_regs *regs, long error_code)
25767 {
25768+
25769+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25770+ if (!user_mode(regs)) {
25771+ unsigned long cs = regs->cs & 0xFFFF;
25772+ unsigned long ip = ktva_ktla(regs->ip);
25773+
25774+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25775+ regs->ip = ip;
25776+ }
25777+#endif
25778+
25779 nmi_nesting_preprocess(regs);
25780
25781 nmi_enter();
25782diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25783index 6d9582e..f746287 100644
25784--- a/arch/x86/kernel/nmi_selftest.c
25785+++ b/arch/x86/kernel/nmi_selftest.c
25786@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25787 {
25788 /* trap all the unknown NMIs we may generate */
25789 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25790- __initdata);
25791+ __initconst);
25792 }
25793
25794 static void __init cleanup_nmi_testsuite(void)
25795@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25796 unsigned long timeout;
25797
25798 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25799- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25800+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25801 nmi_fail = FAILURE;
25802 return;
25803 }
25804diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25805index bbb6c73..24a58ef 100644
25806--- a/arch/x86/kernel/paravirt-spinlocks.c
25807+++ b/arch/x86/kernel/paravirt-spinlocks.c
25808@@ -8,7 +8,7 @@
25809
25810 #include <asm/paravirt.h>
25811
25812-struct pv_lock_ops pv_lock_ops = {
25813+struct pv_lock_ops pv_lock_ops __read_only = {
25814 #ifdef CONFIG_SMP
25815 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25816 .unlock_kick = paravirt_nop,
25817diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25818index 1b10af8..0b58cbc 100644
25819--- a/arch/x86/kernel/paravirt.c
25820+++ b/arch/x86/kernel/paravirt.c
25821@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25822 {
25823 return x;
25824 }
25825+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25826+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25827+#endif
25828
25829 void __init default_banner(void)
25830 {
25831@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25832 if (opfunc == NULL)
25833 /* If there's no function, patch it with a ud2a (BUG) */
25834 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25835- else if (opfunc == _paravirt_nop)
25836+ else if (opfunc == (void *)_paravirt_nop)
25837 /* If the operation is a nop, then nop the callsite */
25838 ret = paravirt_patch_nop();
25839
25840 /* identity functions just return their single argument */
25841- else if (opfunc == _paravirt_ident_32)
25842+ else if (opfunc == (void *)_paravirt_ident_32)
25843 ret = paravirt_patch_ident_32(insnbuf, len);
25844- else if (opfunc == _paravirt_ident_64)
25845+ else if (opfunc == (void *)_paravirt_ident_64)
25846 ret = paravirt_patch_ident_64(insnbuf, len);
25847+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25848+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25849+ ret = paravirt_patch_ident_64(insnbuf, len);
25850+#endif
25851
25852 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25853 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25854@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25855 if (insn_len > len || start == NULL)
25856 insn_len = len;
25857 else
25858- memcpy(insnbuf, start, insn_len);
25859+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25860
25861 return insn_len;
25862 }
25863@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25864 return this_cpu_read(paravirt_lazy_mode);
25865 }
25866
25867-struct pv_info pv_info = {
25868+struct pv_info pv_info __read_only = {
25869 .name = "bare hardware",
25870 .paravirt_enabled = 0,
25871 .kernel_rpl = 0,
25872@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25873 #endif
25874 };
25875
25876-struct pv_init_ops pv_init_ops = {
25877+struct pv_init_ops pv_init_ops __read_only = {
25878 .patch = native_patch,
25879 };
25880
25881-struct pv_time_ops pv_time_ops = {
25882+struct pv_time_ops pv_time_ops __read_only = {
25883 .sched_clock = native_sched_clock,
25884 .steal_clock = native_steal_clock,
25885 };
25886
25887-__visible struct pv_irq_ops pv_irq_ops = {
25888+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25889 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25890 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25891 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25892@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25893 #endif
25894 };
25895
25896-__visible struct pv_cpu_ops pv_cpu_ops = {
25897+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25898 .cpuid = native_cpuid,
25899 .get_debugreg = native_get_debugreg,
25900 .set_debugreg = native_set_debugreg,
25901@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25902 .end_context_switch = paravirt_nop,
25903 };
25904
25905-struct pv_apic_ops pv_apic_ops = {
25906+struct pv_apic_ops pv_apic_ops __read_only= {
25907 #ifdef CONFIG_X86_LOCAL_APIC
25908 .startup_ipi_hook = paravirt_nop,
25909 #endif
25910 };
25911
25912-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25913+#ifdef CONFIG_X86_32
25914+#ifdef CONFIG_X86_PAE
25915+/* 64-bit pagetable entries */
25916+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25917+#else
25918 /* 32-bit pagetable entries */
25919 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25920+#endif
25921 #else
25922 /* 64-bit pagetable entries */
25923 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25924 #endif
25925
25926-struct pv_mmu_ops pv_mmu_ops = {
25927+struct pv_mmu_ops pv_mmu_ops __read_only = {
25928
25929 .read_cr2 = native_read_cr2,
25930 .write_cr2 = native_write_cr2,
25931@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25932 .make_pud = PTE_IDENT,
25933
25934 .set_pgd = native_set_pgd,
25935+ .set_pgd_batched = native_set_pgd_batched,
25936 #endif
25937 #endif /* PAGETABLE_LEVELS >= 3 */
25938
25939@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25940 },
25941
25942 .set_fixmap = native_set_fixmap,
25943+
25944+#ifdef CONFIG_PAX_KERNEXEC
25945+ .pax_open_kernel = native_pax_open_kernel,
25946+ .pax_close_kernel = native_pax_close_kernel,
25947+#endif
25948+
25949 };
25950
25951 EXPORT_SYMBOL_GPL(pv_time_ops);
25952diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25953index 299d493..2ccb0ee 100644
25954--- a/arch/x86/kernel/pci-calgary_64.c
25955+++ b/arch/x86/kernel/pci-calgary_64.c
25956@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25957 tce_space = be64_to_cpu(readq(target));
25958 tce_space = tce_space & TAR_SW_BITS;
25959
25960- tce_space = tce_space & (~specified_table_size);
25961+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25962 info->tce_space = (u64 *)__va(tce_space);
25963 }
25964 }
25965diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25966index 35ccf75..7a15747 100644
25967--- a/arch/x86/kernel/pci-iommu_table.c
25968+++ b/arch/x86/kernel/pci-iommu_table.c
25969@@ -2,7 +2,7 @@
25970 #include <asm/iommu_table.h>
25971 #include <linux/string.h>
25972 #include <linux/kallsyms.h>
25973-
25974+#include <linux/sched.h>
25975
25976 #define DEBUG 1
25977
25978diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25979index 6c483ba..d10ce2f 100644
25980--- a/arch/x86/kernel/pci-swiotlb.c
25981+++ b/arch/x86/kernel/pci-swiotlb.c
25982@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25983 void *vaddr, dma_addr_t dma_addr,
25984 struct dma_attrs *attrs)
25985 {
25986- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25987+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25988 }
25989
25990 static struct dma_map_ops swiotlb_dma_ops = {
25991diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25992index ca7f0d5..8996469 100644
25993--- a/arch/x86/kernel/preempt.S
25994+++ b/arch/x86/kernel/preempt.S
25995@@ -3,12 +3,14 @@
25996 #include <asm/dwarf2.h>
25997 #include <asm/asm.h>
25998 #include <asm/calling.h>
25999+#include <asm/alternative-asm.h>
26000
26001 ENTRY(___preempt_schedule)
26002 CFI_STARTPROC
26003 SAVE_ALL
26004 call preempt_schedule
26005 RESTORE_ALL
26006+ pax_force_retaddr
26007 ret
26008 CFI_ENDPROC
26009
26010@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26011 SAVE_ALL
26012 call preempt_schedule_context
26013 RESTORE_ALL
26014+ pax_force_retaddr
26015 ret
26016 CFI_ENDPROC
26017
26018diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26019index 3fb8d95..254dc51 100644
26020--- a/arch/x86/kernel/process.c
26021+++ b/arch/x86/kernel/process.c
26022@@ -36,7 +36,8 @@
26023 * section. Since TSS's are completely CPU-local, we want them
26024 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26025 */
26026-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26027+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26028+EXPORT_SYMBOL(init_tss);
26029
26030 #ifdef CONFIG_X86_64
26031 static DEFINE_PER_CPU(unsigned char, is_idle);
26032@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26033 task_xstate_cachep =
26034 kmem_cache_create("task_xstate", xstate_size,
26035 __alignof__(union thread_xstate),
26036- SLAB_PANIC | SLAB_NOTRACK, NULL);
26037+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26038 }
26039
26040 /*
26041@@ -105,7 +106,7 @@ void exit_thread(void)
26042 unsigned long *bp = t->io_bitmap_ptr;
26043
26044 if (bp) {
26045- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26046+ struct tss_struct *tss = init_tss + get_cpu();
26047
26048 t->io_bitmap_ptr = NULL;
26049 clear_thread_flag(TIF_IO_BITMAP);
26050@@ -125,6 +126,9 @@ void flush_thread(void)
26051 {
26052 struct task_struct *tsk = current;
26053
26054+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26055+ loadsegment(gs, 0);
26056+#endif
26057 flush_ptrace_hw_breakpoint(tsk);
26058 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26059 drop_init_fpu(tsk);
26060@@ -271,7 +275,7 @@ static void __exit_idle(void)
26061 void exit_idle(void)
26062 {
26063 /* idle loop has pid 0 */
26064- if (current->pid)
26065+ if (task_pid_nr(current))
26066 return;
26067 __exit_idle();
26068 }
26069@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26070 return ret;
26071 }
26072 #endif
26073-void stop_this_cpu(void *dummy)
26074+__noreturn void stop_this_cpu(void *dummy)
26075 {
26076 local_irq_disable();
26077 /*
26078@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26079 }
26080 early_param("idle", idle_setup);
26081
26082-unsigned long arch_align_stack(unsigned long sp)
26083+#ifdef CONFIG_PAX_RANDKSTACK
26084+void pax_randomize_kstack(struct pt_regs *regs)
26085 {
26086- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26087- sp -= get_random_int() % 8192;
26088- return sp & ~0xf;
26089-}
26090+ struct thread_struct *thread = &current->thread;
26091+ unsigned long time;
26092
26093-unsigned long arch_randomize_brk(struct mm_struct *mm)
26094-{
26095- unsigned long range_end = mm->brk + 0x02000000;
26096- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26097-}
26098+ if (!randomize_va_space)
26099+ return;
26100+
26101+ if (v8086_mode(regs))
26102+ return;
26103
26104+ rdtscl(time);
26105+
26106+ /* P4 seems to return a 0 LSB, ignore it */
26107+#ifdef CONFIG_MPENTIUM4
26108+ time &= 0x3EUL;
26109+ time <<= 2;
26110+#elif defined(CONFIG_X86_64)
26111+ time &= 0xFUL;
26112+ time <<= 4;
26113+#else
26114+ time &= 0x1FUL;
26115+ time <<= 3;
26116+#endif
26117+
26118+ thread->sp0 ^= time;
26119+ load_sp0(init_tss + smp_processor_id(), thread);
26120+
26121+#ifdef CONFIG_X86_64
26122+ this_cpu_write(kernel_stack, thread->sp0);
26123+#endif
26124+}
26125+#endif
26126diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26127index 0de43e9..056b840 100644
26128--- a/arch/x86/kernel/process_32.c
26129+++ b/arch/x86/kernel/process_32.c
26130@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26131 unsigned long thread_saved_pc(struct task_struct *tsk)
26132 {
26133 return ((unsigned long *)tsk->thread.sp)[3];
26134+//XXX return tsk->thread.eip;
26135 }
26136
26137 void __show_regs(struct pt_regs *regs, int all)
26138@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26139 unsigned long sp;
26140 unsigned short ss, gs;
26141
26142- if (user_mode_vm(regs)) {
26143+ if (user_mode(regs)) {
26144 sp = regs->sp;
26145 ss = regs->ss & 0xffff;
26146- gs = get_user_gs(regs);
26147 } else {
26148 sp = kernel_stack_pointer(regs);
26149 savesegment(ss, ss);
26150- savesegment(gs, gs);
26151 }
26152+ gs = get_user_gs(regs);
26153
26154 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26155 (u16)regs->cs, regs->ip, regs->flags,
26156- smp_processor_id());
26157+ raw_smp_processor_id());
26158 print_symbol("EIP is at %s\n", regs->ip);
26159
26160 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26161@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26162 int copy_thread(unsigned long clone_flags, unsigned long sp,
26163 unsigned long arg, struct task_struct *p)
26164 {
26165- struct pt_regs *childregs = task_pt_regs(p);
26166+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26167 struct task_struct *tsk;
26168 int err;
26169
26170 p->thread.sp = (unsigned long) childregs;
26171 p->thread.sp0 = (unsigned long) (childregs+1);
26172+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26173
26174 if (unlikely(p->flags & PF_KTHREAD)) {
26175 /* kernel thread */
26176 memset(childregs, 0, sizeof(struct pt_regs));
26177 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26178- task_user_gs(p) = __KERNEL_STACK_CANARY;
26179- childregs->ds = __USER_DS;
26180- childregs->es = __USER_DS;
26181+ savesegment(gs, childregs->gs);
26182+ childregs->ds = __KERNEL_DS;
26183+ childregs->es = __KERNEL_DS;
26184 childregs->fs = __KERNEL_PERCPU;
26185 childregs->bx = sp; /* function */
26186 childregs->bp = arg;
26187@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26188 struct thread_struct *prev = &prev_p->thread,
26189 *next = &next_p->thread;
26190 int cpu = smp_processor_id();
26191- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26192+ struct tss_struct *tss = init_tss + cpu;
26193 fpu_switch_t fpu;
26194
26195 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26196@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26197 */
26198 lazy_save_gs(prev->gs);
26199
26200+#ifdef CONFIG_PAX_MEMORY_UDEREF
26201+ __set_fs(task_thread_info(next_p)->addr_limit);
26202+#endif
26203+
26204 /*
26205 * Load the per-thread Thread-Local Storage descriptor.
26206 */
26207@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26208 */
26209 arch_end_context_switch(next_p);
26210
26211+ this_cpu_write(current_task, next_p);
26212+ this_cpu_write(current_tinfo, &next_p->tinfo);
26213+
26214 /*
26215 * Restore %gs if needed (which is common)
26216 */
26217@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26218
26219 switch_fpu_finish(next_p, fpu);
26220
26221- this_cpu_write(current_task, next_p);
26222-
26223 return prev_p;
26224 }
26225
26226@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26227 } while (count++ < 16);
26228 return 0;
26229 }
26230-
26231diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26232index 9c0280f..5bbb1c0 100644
26233--- a/arch/x86/kernel/process_64.c
26234+++ b/arch/x86/kernel/process_64.c
26235@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26236 struct pt_regs *childregs;
26237 struct task_struct *me = current;
26238
26239- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26240+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26241 childregs = task_pt_regs(p);
26242 p->thread.sp = (unsigned long) childregs;
26243 p->thread.usersp = me->thread.usersp;
26244+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26245 set_tsk_thread_flag(p, TIF_FORK);
26246 p->thread.fpu_counter = 0;
26247 p->thread.io_bitmap_ptr = NULL;
26248@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26249 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26250 savesegment(es, p->thread.es);
26251 savesegment(ds, p->thread.ds);
26252+ savesegment(ss, p->thread.ss);
26253+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26254 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26255
26256 if (unlikely(p->flags & PF_KTHREAD)) {
26257@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26258 struct thread_struct *prev = &prev_p->thread;
26259 struct thread_struct *next = &next_p->thread;
26260 int cpu = smp_processor_id();
26261- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26262+ struct tss_struct *tss = init_tss + cpu;
26263 unsigned fsindex, gsindex;
26264 fpu_switch_t fpu;
26265
26266@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26267 if (unlikely(next->ds | prev->ds))
26268 loadsegment(ds, next->ds);
26269
26270+ savesegment(ss, prev->ss);
26271+ if (unlikely(next->ss != prev->ss))
26272+ loadsegment(ss, next->ss);
26273
26274 /* We must save %fs and %gs before load_TLS() because
26275 * %fs and %gs may be cleared by load_TLS().
26276@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26277 prev->usersp = this_cpu_read(old_rsp);
26278 this_cpu_write(old_rsp, next->usersp);
26279 this_cpu_write(current_task, next_p);
26280+ this_cpu_write(current_tinfo, &next_p->tinfo);
26281
26282 /*
26283 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26284@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26285 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26286 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26287
26288- this_cpu_write(kernel_stack,
26289- (unsigned long)task_stack_page(next_p) +
26290- THREAD_SIZE - KERNEL_STACK_OFFSET);
26291+ this_cpu_write(kernel_stack, next->sp0);
26292
26293 /*
26294 * Now maybe reload the debug registers and handle I/O bitmaps
26295@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26296 if (!p || p == current || p->state == TASK_RUNNING)
26297 return 0;
26298 stack = (unsigned long)task_stack_page(p);
26299- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26300+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26301 return 0;
26302 fp = *(u64 *)(p->thread.sp);
26303 do {
26304- if (fp < (unsigned long)stack ||
26305- fp >= (unsigned long)stack+THREAD_SIZE)
26306+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26307 return 0;
26308 ip = *(u64 *)(fp+8);
26309 if (!in_sched_functions(ip))
26310diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26311index 7461f50..1334029 100644
26312--- a/arch/x86/kernel/ptrace.c
26313+++ b/arch/x86/kernel/ptrace.c
26314@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26315 {
26316 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26317 unsigned long sp = (unsigned long)&regs->sp;
26318- struct thread_info *tinfo;
26319
26320- if (context == (sp & ~(THREAD_SIZE - 1)))
26321+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26322 return sp;
26323
26324- tinfo = (struct thread_info *)context;
26325- if (tinfo->previous_esp)
26326- return tinfo->previous_esp;
26327+ sp = *(unsigned long *)context;
26328+ if (sp)
26329+ return sp;
26330
26331 return (unsigned long)regs;
26332 }
26333@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26334 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26335 {
26336 int i;
26337- int dr7 = 0;
26338+ unsigned long dr7 = 0;
26339 struct arch_hw_breakpoint *info;
26340
26341 for (i = 0; i < HBP_NUM; i++) {
26342@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26343 unsigned long addr, unsigned long data)
26344 {
26345 int ret;
26346- unsigned long __user *datap = (unsigned long __user *)data;
26347+ unsigned long __user *datap = (__force unsigned long __user *)data;
26348
26349 switch (request) {
26350 /* read the word at location addr in the USER area. */
26351@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26352 if ((int) addr < 0)
26353 return -EIO;
26354 ret = do_get_thread_area(child, addr,
26355- (struct user_desc __user *)data);
26356+ (__force struct user_desc __user *) data);
26357 break;
26358
26359 case PTRACE_SET_THREAD_AREA:
26360 if ((int) addr < 0)
26361 return -EIO;
26362 ret = do_set_thread_area(child, addr,
26363- (struct user_desc __user *)data, 0);
26364+ (__force struct user_desc __user *) data, 0);
26365 break;
26366 #endif
26367
26368@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26369
26370 #ifdef CONFIG_X86_64
26371
26372-static struct user_regset x86_64_regsets[] __read_mostly = {
26373+static user_regset_no_const x86_64_regsets[] __read_only = {
26374 [REGSET_GENERAL] = {
26375 .core_note_type = NT_PRSTATUS,
26376 .n = sizeof(struct user_regs_struct) / sizeof(long),
26377@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26378 #endif /* CONFIG_X86_64 */
26379
26380 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26381-static struct user_regset x86_32_regsets[] __read_mostly = {
26382+static user_regset_no_const x86_32_regsets[] __read_only = {
26383 [REGSET_GENERAL] = {
26384 .core_note_type = NT_PRSTATUS,
26385 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26386@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26387 */
26388 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26389
26390-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26391+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26392 {
26393 #ifdef CONFIG_X86_64
26394 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26395@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26396 memset(info, 0, sizeof(*info));
26397 info->si_signo = SIGTRAP;
26398 info->si_code = si_code;
26399- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26400+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26401 }
26402
26403 void user_single_step_siginfo(struct task_struct *tsk,
26404@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26405 # define IS_IA32 0
26406 #endif
26407
26408+#ifdef CONFIG_GRKERNSEC_SETXID
26409+extern void gr_delayed_cred_worker(void);
26410+#endif
26411+
26412 /*
26413 * We must return the syscall number to actually look up in the table.
26414 * This can be -1L to skip running any syscall at all.
26415@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26416
26417 user_exit();
26418
26419+#ifdef CONFIG_GRKERNSEC_SETXID
26420+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26421+ gr_delayed_cred_worker();
26422+#endif
26423+
26424 /*
26425 * If we stepped into a sysenter/syscall insn, it trapped in
26426 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26427@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26428 */
26429 user_exit();
26430
26431+#ifdef CONFIG_GRKERNSEC_SETXID
26432+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26433+ gr_delayed_cred_worker();
26434+#endif
26435+
26436 audit_syscall_exit(regs);
26437
26438 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26439diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26440index 2f355d2..e75ed0a 100644
26441--- a/arch/x86/kernel/pvclock.c
26442+++ b/arch/x86/kernel/pvclock.c
26443@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26444 reset_hung_task_detector();
26445 }
26446
26447-static atomic64_t last_value = ATOMIC64_INIT(0);
26448+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26449
26450 void pvclock_resume(void)
26451 {
26452- atomic64_set(&last_value, 0);
26453+ atomic64_set_unchecked(&last_value, 0);
26454 }
26455
26456 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26457@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26458 * updating at the same time, and one of them could be slightly behind,
26459 * making the assumption that last_value always go forward fail to hold.
26460 */
26461- last = atomic64_read(&last_value);
26462+ last = atomic64_read_unchecked(&last_value);
26463 do {
26464 if (ret < last)
26465 return last;
26466- last = atomic64_cmpxchg(&last_value, last, ret);
26467+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26468 } while (unlikely(last != ret));
26469
26470 return ret;
26471diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26472index c752cb4..866c432 100644
26473--- a/arch/x86/kernel/reboot.c
26474+++ b/arch/x86/kernel/reboot.c
26475@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26476
26477 void __noreturn machine_real_restart(unsigned int type)
26478 {
26479+
26480+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26481+ struct desc_struct *gdt;
26482+#endif
26483+
26484 local_irq_disable();
26485
26486 /*
26487@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26488
26489 /* Jump to the identity-mapped low memory code */
26490 #ifdef CONFIG_X86_32
26491- asm volatile("jmpl *%0" : :
26492+
26493+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26494+ gdt = get_cpu_gdt_table(smp_processor_id());
26495+ pax_open_kernel();
26496+#ifdef CONFIG_PAX_MEMORY_UDEREF
26497+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26498+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26499+ loadsegment(ds, __KERNEL_DS);
26500+ loadsegment(es, __KERNEL_DS);
26501+ loadsegment(ss, __KERNEL_DS);
26502+#endif
26503+#ifdef CONFIG_PAX_KERNEXEC
26504+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26505+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26506+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26507+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26508+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26509+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26510+#endif
26511+ pax_close_kernel();
26512+#endif
26513+
26514+ asm volatile("ljmpl *%0" : :
26515 "rm" (real_mode_header->machine_real_restart_asm),
26516 "a" (type));
26517 #else
26518@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26519 * try to force a triple fault and then cycle between hitting the keyboard
26520 * controller and doing that
26521 */
26522-static void native_machine_emergency_restart(void)
26523+static void __noreturn native_machine_emergency_restart(void)
26524 {
26525 int i;
26526 int attempt = 0;
26527@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26528 #endif
26529 }
26530
26531-static void __machine_emergency_restart(int emergency)
26532+static void __noreturn __machine_emergency_restart(int emergency)
26533 {
26534 reboot_emergency = emergency;
26535 machine_ops.emergency_restart();
26536 }
26537
26538-static void native_machine_restart(char *__unused)
26539+static void __noreturn native_machine_restart(char *__unused)
26540 {
26541 pr_notice("machine restart\n");
26542
26543@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26544 __machine_emergency_restart(0);
26545 }
26546
26547-static void native_machine_halt(void)
26548+static void __noreturn native_machine_halt(void)
26549 {
26550 /* Stop other cpus and apics */
26551 machine_shutdown();
26552@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26553 stop_this_cpu(NULL);
26554 }
26555
26556-static void native_machine_power_off(void)
26557+static void __noreturn native_machine_power_off(void)
26558 {
26559 if (pm_power_off) {
26560 if (!reboot_force)
26561@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26562 }
26563 /* A fallback in case there is no PM info available */
26564 tboot_shutdown(TB_SHUTDOWN_HALT);
26565+ unreachable();
26566 }
26567
26568-struct machine_ops machine_ops = {
26569+struct machine_ops machine_ops __read_only = {
26570 .power_off = native_machine_power_off,
26571 .shutdown = native_machine_shutdown,
26572 .emergency_restart = native_machine_emergency_restart,
26573diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26574index c8e41e9..64049ef 100644
26575--- a/arch/x86/kernel/reboot_fixups_32.c
26576+++ b/arch/x86/kernel/reboot_fixups_32.c
26577@@ -57,7 +57,7 @@ struct device_fixup {
26578 unsigned int vendor;
26579 unsigned int device;
26580 void (*reboot_fixup)(struct pci_dev *);
26581-};
26582+} __do_const;
26583
26584 /*
26585 * PCI ids solely used for fixups_table go here
26586diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26587index 3fd2c69..a444264 100644
26588--- a/arch/x86/kernel/relocate_kernel_64.S
26589+++ b/arch/x86/kernel/relocate_kernel_64.S
26590@@ -96,8 +96,7 @@ relocate_kernel:
26591
26592 /* jump to identity mapped page */
26593 addq $(identity_mapped - relocate_kernel), %r8
26594- pushq %r8
26595- ret
26596+ jmp *%r8
26597
26598 identity_mapped:
26599 /* set return address to 0 if not preserving context */
26600diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26601index ce72964..be8aea7 100644
26602--- a/arch/x86/kernel/setup.c
26603+++ b/arch/x86/kernel/setup.c
26604@@ -110,6 +110,7 @@
26605 #include <asm/mce.h>
26606 #include <asm/alternative.h>
26607 #include <asm/prom.h>
26608+#include <asm/boot.h>
26609
26610 /*
26611 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26612@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26613 #endif
26614
26615
26616-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26617-__visible unsigned long mmu_cr4_features;
26618+#ifdef CONFIG_X86_64
26619+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26620+#elif defined(CONFIG_X86_PAE)
26621+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26622 #else
26623-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26624+__visible unsigned long mmu_cr4_features __read_only;
26625 #endif
26626
26627+void set_in_cr4(unsigned long mask)
26628+{
26629+ unsigned long cr4 = read_cr4();
26630+
26631+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26632+ return;
26633+
26634+ pax_open_kernel();
26635+ mmu_cr4_features |= mask;
26636+ pax_close_kernel();
26637+
26638+ if (trampoline_cr4_features)
26639+ *trampoline_cr4_features = mmu_cr4_features;
26640+ cr4 |= mask;
26641+ write_cr4(cr4);
26642+}
26643+EXPORT_SYMBOL(set_in_cr4);
26644+
26645+void clear_in_cr4(unsigned long mask)
26646+{
26647+ unsigned long cr4 = read_cr4();
26648+
26649+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26650+ return;
26651+
26652+ pax_open_kernel();
26653+ mmu_cr4_features &= ~mask;
26654+ pax_close_kernel();
26655+
26656+ if (trampoline_cr4_features)
26657+ *trampoline_cr4_features = mmu_cr4_features;
26658+ cr4 &= ~mask;
26659+ write_cr4(cr4);
26660+}
26661+EXPORT_SYMBOL(clear_in_cr4);
26662+
26663 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26664 int bootloader_type, bootloader_version;
26665
26666@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26667 * area (640->1Mb) as ram even though it is not.
26668 * take them out.
26669 */
26670- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26671+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26672
26673 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26674 }
26675@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26676 /* called before trim_bios_range() to spare extra sanitize */
26677 static void __init e820_add_kernel_range(void)
26678 {
26679- u64 start = __pa_symbol(_text);
26680+ u64 start = __pa_symbol(ktla_ktva(_text));
26681 u64 size = __pa_symbol(_end) - start;
26682
26683 /*
26684@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26685
26686 void __init setup_arch(char **cmdline_p)
26687 {
26688+#ifdef CONFIG_X86_32
26689+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26690+#else
26691 memblock_reserve(__pa_symbol(_text),
26692 (unsigned long)__bss_stop - (unsigned long)_text);
26693+#endif
26694
26695 early_reserve_initrd();
26696
26697@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
26698
26699 if (!boot_params.hdr.root_flags)
26700 root_mountflags &= ~MS_RDONLY;
26701- init_mm.start_code = (unsigned long) _text;
26702- init_mm.end_code = (unsigned long) _etext;
26703+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26704+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26705 init_mm.end_data = (unsigned long) _edata;
26706 init_mm.brk = _brk_end;
26707
26708- code_resource.start = __pa_symbol(_text);
26709- code_resource.end = __pa_symbol(_etext)-1;
26710- data_resource.start = __pa_symbol(_etext);
26711+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26712+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26713+ data_resource.start = __pa_symbol(_sdata);
26714 data_resource.end = __pa_symbol(_edata)-1;
26715 bss_resource.start = __pa_symbol(__bss_start);
26716 bss_resource.end = __pa_symbol(__bss_stop)-1;
26717diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26718index 5cdff03..80fa283 100644
26719--- a/arch/x86/kernel/setup_percpu.c
26720+++ b/arch/x86/kernel/setup_percpu.c
26721@@ -21,19 +21,17 @@
26722 #include <asm/cpu.h>
26723 #include <asm/stackprotector.h>
26724
26725-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26726+#ifdef CONFIG_SMP
26727+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26728 EXPORT_PER_CPU_SYMBOL(cpu_number);
26729+#endif
26730
26731-#ifdef CONFIG_X86_64
26732 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26733-#else
26734-#define BOOT_PERCPU_OFFSET 0
26735-#endif
26736
26737 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26738 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26739
26740-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26741+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26742 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26743 };
26744 EXPORT_SYMBOL(__per_cpu_offset);
26745@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26746 {
26747 #ifdef CONFIG_NEED_MULTIPLE_NODES
26748 pg_data_t *last = NULL;
26749- unsigned int cpu;
26750+ int cpu;
26751
26752 for_each_possible_cpu(cpu) {
26753 int node = early_cpu_to_node(cpu);
26754@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26755 {
26756 #ifdef CONFIG_X86_32
26757 struct desc_struct gdt;
26758+ unsigned long base = per_cpu_offset(cpu);
26759
26760- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26761- 0x2 | DESCTYPE_S, 0x8);
26762- gdt.s = 1;
26763+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26764+ 0x83 | DESCTYPE_S, 0xC);
26765 write_gdt_entry(get_cpu_gdt_table(cpu),
26766 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26767 #endif
26768@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26769 /* alrighty, percpu areas up and running */
26770 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26771 for_each_possible_cpu(cpu) {
26772+#ifdef CONFIG_CC_STACKPROTECTOR
26773+#ifdef CONFIG_X86_32
26774+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26775+#endif
26776+#endif
26777 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26778 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26779 per_cpu(cpu_number, cpu) = cpu;
26780@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26781 */
26782 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26783 #endif
26784+#ifdef CONFIG_CC_STACKPROTECTOR
26785+#ifdef CONFIG_X86_32
26786+ if (!cpu)
26787+ per_cpu(stack_canary.canary, cpu) = canary;
26788+#endif
26789+#endif
26790 /*
26791 * Up to this point, the boot CPU has been using .init.data
26792 * area. Reload any changed state for the boot CPU.
26793diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26794index 9e5de68..16c53cb 100644
26795--- a/arch/x86/kernel/signal.c
26796+++ b/arch/x86/kernel/signal.c
26797@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26798 * Align the stack pointer according to the i386 ABI,
26799 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26800 */
26801- sp = ((sp + 4) & -16ul) - 4;
26802+ sp = ((sp - 12) & -16ul) - 4;
26803 #else /* !CONFIG_X86_32 */
26804 sp = round_down(sp, 16) - 8;
26805 #endif
26806@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26807 }
26808
26809 if (current->mm->context.vdso)
26810- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26811+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26812 else
26813- restorer = &frame->retcode;
26814+ restorer = (void __user *)&frame->retcode;
26815 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26816 restorer = ksig->ka.sa.sa_restorer;
26817
26818@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26819 * reasons and because gdb uses it as a signature to notice
26820 * signal handler stack frames.
26821 */
26822- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26823+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26824
26825 if (err)
26826 return -EFAULT;
26827@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26828 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26829
26830 /* Set up to return from userspace. */
26831- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26832+ if (current->mm->context.vdso)
26833+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26834+ else
26835+ restorer = (void __user *)&frame->retcode;
26836 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26837 restorer = ksig->ka.sa.sa_restorer;
26838 put_user_ex(restorer, &frame->pretcode);
26839@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26840 * reasons and because gdb uses it as a signature to notice
26841 * signal handler stack frames.
26842 */
26843- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26844+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26845 } put_user_catch(err);
26846
26847 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26848@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26849 {
26850 int usig = signr_convert(ksig->sig);
26851 sigset_t *set = sigmask_to_save();
26852- compat_sigset_t *cset = (compat_sigset_t *) set;
26853+ sigset_t sigcopy;
26854+ compat_sigset_t *cset;
26855+
26856+ sigcopy = *set;
26857+
26858+ cset = (compat_sigset_t *) &sigcopy;
26859
26860 /* Set up the stack frame */
26861 if (is_ia32_frame()) {
26862@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26863 } else if (is_x32_frame()) {
26864 return x32_setup_rt_frame(ksig, cset, regs);
26865 } else {
26866- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26867+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26868 }
26869 }
26870
26871diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26872index 7c3a5a6..f0a8961 100644
26873--- a/arch/x86/kernel/smp.c
26874+++ b/arch/x86/kernel/smp.c
26875@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26876
26877 __setup("nonmi_ipi", nonmi_ipi_setup);
26878
26879-struct smp_ops smp_ops = {
26880+struct smp_ops smp_ops __read_only = {
26881 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26882 .smp_prepare_cpus = native_smp_prepare_cpus,
26883 .smp_cpus_done = native_smp_cpus_done,
26884diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26885index a32da80..30c97f1 100644
26886--- a/arch/x86/kernel/smpboot.c
26887+++ b/arch/x86/kernel/smpboot.c
26888@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26889
26890 enable_start_cpu0 = 0;
26891
26892-#ifdef CONFIG_X86_32
26893- /* switch away from the initial page table */
26894- load_cr3(swapper_pg_dir);
26895- __flush_tlb_all();
26896-#endif
26897-
26898 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26899 barrier();
26900+
26901+ /* switch away from the initial page table */
26902+#ifdef CONFIG_PAX_PER_CPU_PGD
26903+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26904+ __flush_tlb_all();
26905+#elif defined(CONFIG_X86_32)
26906+ load_cr3(swapper_pg_dir);
26907+ __flush_tlb_all();
26908+#endif
26909+
26910 /*
26911 * Check TSC synchronization with the BP:
26912 */
26913@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26914 alternatives_enable_smp();
26915
26916 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26917- (THREAD_SIZE + task_stack_page(idle))) - 1);
26918+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26919 per_cpu(current_task, cpu) = idle;
26920+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26921
26922 #ifdef CONFIG_X86_32
26923 /* Stack for startup_32 can be just as for start_secondary onwards */
26924@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26925 #else
26926 clear_tsk_thread_flag(idle, TIF_FORK);
26927 initial_gs = per_cpu_offset(cpu);
26928- per_cpu(kernel_stack, cpu) =
26929- (unsigned long)task_stack_page(idle) -
26930- KERNEL_STACK_OFFSET + THREAD_SIZE;
26931+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26932 #endif
26933+
26934+ pax_open_kernel();
26935 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26936+ pax_close_kernel();
26937+
26938 initial_code = (unsigned long)start_secondary;
26939 stack_start = idle->thread.sp;
26940
26941@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26942 /* the FPU context is blank, nobody can own it */
26943 __cpu_disable_lazy_restore(cpu);
26944
26945+#ifdef CONFIG_PAX_PER_CPU_PGD
26946+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26947+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26948+ KERNEL_PGD_PTRS);
26949+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26950+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26951+ KERNEL_PGD_PTRS);
26952+#endif
26953+
26954 err = do_boot_cpu(apicid, cpu, tidle);
26955 if (err) {
26956 pr_debug("do_boot_cpu failed %d\n", err);
26957diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26958index 9b4d51d..5d28b58 100644
26959--- a/arch/x86/kernel/step.c
26960+++ b/arch/x86/kernel/step.c
26961@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26962 struct desc_struct *desc;
26963 unsigned long base;
26964
26965- seg &= ~7UL;
26966+ seg >>= 3;
26967
26968 mutex_lock(&child->mm->context.lock);
26969- if (unlikely((seg >> 3) >= child->mm->context.size))
26970+ if (unlikely(seg >= child->mm->context.size))
26971 addr = -1L; /* bogus selector, access would fault */
26972 else {
26973 desc = child->mm->context.ldt + seg;
26974@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26975 addr += base;
26976 }
26977 mutex_unlock(&child->mm->context.lock);
26978- }
26979+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26980+ addr = ktla_ktva(addr);
26981
26982 return addr;
26983 }
26984@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26985 unsigned char opcode[15];
26986 unsigned long addr = convert_ip_to_linear(child, regs);
26987
26988+ if (addr == -EINVAL)
26989+ return 0;
26990+
26991 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26992 for (i = 0; i < copied; i++) {
26993 switch (opcode[i]) {
26994diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26995new file mode 100644
26996index 0000000..5877189
26997--- /dev/null
26998+++ b/arch/x86/kernel/sys_i386_32.c
26999@@ -0,0 +1,189 @@
27000+/*
27001+ * This file contains various random system calls that
27002+ * have a non-standard calling sequence on the Linux/i386
27003+ * platform.
27004+ */
27005+
27006+#include <linux/errno.h>
27007+#include <linux/sched.h>
27008+#include <linux/mm.h>
27009+#include <linux/fs.h>
27010+#include <linux/smp.h>
27011+#include <linux/sem.h>
27012+#include <linux/msg.h>
27013+#include <linux/shm.h>
27014+#include <linux/stat.h>
27015+#include <linux/syscalls.h>
27016+#include <linux/mman.h>
27017+#include <linux/file.h>
27018+#include <linux/utsname.h>
27019+#include <linux/ipc.h>
27020+#include <linux/elf.h>
27021+
27022+#include <linux/uaccess.h>
27023+#include <linux/unistd.h>
27024+
27025+#include <asm/syscalls.h>
27026+
27027+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27028+{
27029+ unsigned long pax_task_size = TASK_SIZE;
27030+
27031+#ifdef CONFIG_PAX_SEGMEXEC
27032+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27033+ pax_task_size = SEGMEXEC_TASK_SIZE;
27034+#endif
27035+
27036+ if (flags & MAP_FIXED)
27037+ if (len > pax_task_size || addr > pax_task_size - len)
27038+ return -EINVAL;
27039+
27040+ return 0;
27041+}
27042+
27043+/*
27044+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27045+ */
27046+static unsigned long get_align_mask(void)
27047+{
27048+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27049+ return 0;
27050+
27051+ if (!(current->flags & PF_RANDOMIZE))
27052+ return 0;
27053+
27054+ return va_align.mask;
27055+}
27056+
27057+unsigned long
27058+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27059+ unsigned long len, unsigned long pgoff, unsigned long flags)
27060+{
27061+ struct mm_struct *mm = current->mm;
27062+ struct vm_area_struct *vma;
27063+ unsigned long pax_task_size = TASK_SIZE;
27064+ struct vm_unmapped_area_info info;
27065+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27066+
27067+#ifdef CONFIG_PAX_SEGMEXEC
27068+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27069+ pax_task_size = SEGMEXEC_TASK_SIZE;
27070+#endif
27071+
27072+ pax_task_size -= PAGE_SIZE;
27073+
27074+ if (len > pax_task_size)
27075+ return -ENOMEM;
27076+
27077+ if (flags & MAP_FIXED)
27078+ return addr;
27079+
27080+#ifdef CONFIG_PAX_RANDMMAP
27081+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27082+#endif
27083+
27084+ if (addr) {
27085+ addr = PAGE_ALIGN(addr);
27086+ if (pax_task_size - len >= addr) {
27087+ vma = find_vma(mm, addr);
27088+ if (check_heap_stack_gap(vma, addr, len, offset))
27089+ return addr;
27090+ }
27091+ }
27092+
27093+ info.flags = 0;
27094+ info.length = len;
27095+ info.align_mask = filp ? get_align_mask() : 0;
27096+ info.align_offset = pgoff << PAGE_SHIFT;
27097+ info.threadstack_offset = offset;
27098+
27099+#ifdef CONFIG_PAX_PAGEEXEC
27100+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27101+ info.low_limit = 0x00110000UL;
27102+ info.high_limit = mm->start_code;
27103+
27104+#ifdef CONFIG_PAX_RANDMMAP
27105+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27106+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27107+#endif
27108+
27109+ if (info.low_limit < info.high_limit) {
27110+ addr = vm_unmapped_area(&info);
27111+ if (!IS_ERR_VALUE(addr))
27112+ return addr;
27113+ }
27114+ } else
27115+#endif
27116+
27117+ info.low_limit = mm->mmap_base;
27118+ info.high_limit = pax_task_size;
27119+
27120+ return vm_unmapped_area(&info);
27121+}
27122+
27123+unsigned long
27124+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27125+ const unsigned long len, const unsigned long pgoff,
27126+ const unsigned long flags)
27127+{
27128+ struct vm_area_struct *vma;
27129+ struct mm_struct *mm = current->mm;
27130+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27131+ struct vm_unmapped_area_info info;
27132+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27133+
27134+#ifdef CONFIG_PAX_SEGMEXEC
27135+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27136+ pax_task_size = SEGMEXEC_TASK_SIZE;
27137+#endif
27138+
27139+ pax_task_size -= PAGE_SIZE;
27140+
27141+ /* requested length too big for entire address space */
27142+ if (len > pax_task_size)
27143+ return -ENOMEM;
27144+
27145+ if (flags & MAP_FIXED)
27146+ return addr;
27147+
27148+#ifdef CONFIG_PAX_PAGEEXEC
27149+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27150+ goto bottomup;
27151+#endif
27152+
27153+#ifdef CONFIG_PAX_RANDMMAP
27154+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27155+#endif
27156+
27157+ /* requesting a specific address */
27158+ if (addr) {
27159+ addr = PAGE_ALIGN(addr);
27160+ if (pax_task_size - len >= addr) {
27161+ vma = find_vma(mm, addr);
27162+ if (check_heap_stack_gap(vma, addr, len, offset))
27163+ return addr;
27164+ }
27165+ }
27166+
27167+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27168+ info.length = len;
27169+ info.low_limit = PAGE_SIZE;
27170+ info.high_limit = mm->mmap_base;
27171+ info.align_mask = filp ? get_align_mask() : 0;
27172+ info.align_offset = pgoff << PAGE_SHIFT;
27173+ info.threadstack_offset = offset;
27174+
27175+ addr = vm_unmapped_area(&info);
27176+ if (!(addr & ~PAGE_MASK))
27177+ return addr;
27178+ VM_BUG_ON(addr != -ENOMEM);
27179+
27180+bottomup:
27181+ /*
27182+ * A failed mmap() very likely causes application failure,
27183+ * so fall back to the bottom-up function here. This scenario
27184+ * can happen with large stack limits and large mmap()
27185+ * allocations.
27186+ */
27187+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27188+}
27189diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27190index 30277e2..5664a29 100644
27191--- a/arch/x86/kernel/sys_x86_64.c
27192+++ b/arch/x86/kernel/sys_x86_64.c
27193@@ -81,8 +81,8 @@ out:
27194 return error;
27195 }
27196
27197-static void find_start_end(unsigned long flags, unsigned long *begin,
27198- unsigned long *end)
27199+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27200+ unsigned long *begin, unsigned long *end)
27201 {
27202 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27203 unsigned long new_begin;
27204@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27205 *begin = new_begin;
27206 }
27207 } else {
27208- *begin = current->mm->mmap_legacy_base;
27209+ *begin = mm->mmap_legacy_base;
27210 *end = TASK_SIZE;
27211 }
27212 }
27213@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27214 struct vm_area_struct *vma;
27215 struct vm_unmapped_area_info info;
27216 unsigned long begin, end;
27217+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27218
27219 if (flags & MAP_FIXED)
27220 return addr;
27221
27222- find_start_end(flags, &begin, &end);
27223+ find_start_end(mm, flags, &begin, &end);
27224
27225 if (len > end)
27226 return -ENOMEM;
27227
27228+#ifdef CONFIG_PAX_RANDMMAP
27229+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27230+#endif
27231+
27232 if (addr) {
27233 addr = PAGE_ALIGN(addr);
27234 vma = find_vma(mm, addr);
27235- if (end - len >= addr &&
27236- (!vma || addr + len <= vma->vm_start))
27237+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27238 return addr;
27239 }
27240
27241@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27242 info.high_limit = end;
27243 info.align_mask = filp ? get_align_mask() : 0;
27244 info.align_offset = pgoff << PAGE_SHIFT;
27245+ info.threadstack_offset = offset;
27246 return vm_unmapped_area(&info);
27247 }
27248
27249@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27250 struct mm_struct *mm = current->mm;
27251 unsigned long addr = addr0;
27252 struct vm_unmapped_area_info info;
27253+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27254
27255 /* requested length too big for entire address space */
27256 if (len > TASK_SIZE)
27257@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27258 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27259 goto bottomup;
27260
27261+#ifdef CONFIG_PAX_RANDMMAP
27262+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27263+#endif
27264+
27265 /* requesting a specific address */
27266 if (addr) {
27267 addr = PAGE_ALIGN(addr);
27268 vma = find_vma(mm, addr);
27269- if (TASK_SIZE - len >= addr &&
27270- (!vma || addr + len <= vma->vm_start))
27271+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27272 return addr;
27273 }
27274
27275@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27276 info.high_limit = mm->mmap_base;
27277 info.align_mask = filp ? get_align_mask() : 0;
27278 info.align_offset = pgoff << PAGE_SHIFT;
27279+ info.threadstack_offset = offset;
27280 addr = vm_unmapped_area(&info);
27281 if (!(addr & ~PAGE_MASK))
27282 return addr;
27283diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27284index 91a4496..bb87552 100644
27285--- a/arch/x86/kernel/tboot.c
27286+++ b/arch/x86/kernel/tboot.c
27287@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27288
27289 void tboot_shutdown(u32 shutdown_type)
27290 {
27291- void (*shutdown)(void);
27292+ void (* __noreturn shutdown)(void);
27293
27294 if (!tboot_enabled())
27295 return;
27296@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27297
27298 switch_to_tboot_pt();
27299
27300- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27301+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27302 shutdown();
27303
27304 /* should not reach here */
27305@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27306 return -ENODEV;
27307 }
27308
27309-static atomic_t ap_wfs_count;
27310+static atomic_unchecked_t ap_wfs_count;
27311
27312 static int tboot_wait_for_aps(int num_aps)
27313 {
27314@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27315 {
27316 switch (action) {
27317 case CPU_DYING:
27318- atomic_inc(&ap_wfs_count);
27319+ atomic_inc_unchecked(&ap_wfs_count);
27320 if (num_online_cpus() == 1)
27321- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27322+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27323 return NOTIFY_BAD;
27324 break;
27325 }
27326@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27327
27328 tboot_create_trampoline();
27329
27330- atomic_set(&ap_wfs_count, 0);
27331+ atomic_set_unchecked(&ap_wfs_count, 0);
27332 register_hotcpu_notifier(&tboot_cpu_notifier);
27333
27334 #ifdef CONFIG_DEBUG_FS
27335diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27336index 24d3c91..d06b473 100644
27337--- a/arch/x86/kernel/time.c
27338+++ b/arch/x86/kernel/time.c
27339@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27340 {
27341 unsigned long pc = instruction_pointer(regs);
27342
27343- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27344+ if (!user_mode(regs) && in_lock_functions(pc)) {
27345 #ifdef CONFIG_FRAME_POINTER
27346- return *(unsigned long *)(regs->bp + sizeof(long));
27347+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27348 #else
27349 unsigned long *sp =
27350 (unsigned long *)kernel_stack_pointer(regs);
27351@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27352 * or above a saved flags. Eflags has bits 22-31 zero,
27353 * kernel addresses don't.
27354 */
27355+
27356+#ifdef CONFIG_PAX_KERNEXEC
27357+ return ktla_ktva(sp[0]);
27358+#else
27359 if (sp[0] >> 22)
27360 return sp[0];
27361 if (sp[1] >> 22)
27362 return sp[1];
27363 #endif
27364+
27365+#endif
27366 }
27367 return pc;
27368 }
27369diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27370index f7fec09..9991981 100644
27371--- a/arch/x86/kernel/tls.c
27372+++ b/arch/x86/kernel/tls.c
27373@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27374 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27375 return -EINVAL;
27376
27377+#ifdef CONFIG_PAX_SEGMEXEC
27378+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27379+ return -EINVAL;
27380+#endif
27381+
27382 set_tls_desc(p, idx, &info, 1);
27383
27384 return 0;
27385@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27386
27387 if (kbuf)
27388 info = kbuf;
27389- else if (__copy_from_user(infobuf, ubuf, count))
27390+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27391 return -EFAULT;
27392 else
27393 info = infobuf;
27394diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27395index 1c113db..287b42e 100644
27396--- a/arch/x86/kernel/tracepoint.c
27397+++ b/arch/x86/kernel/tracepoint.c
27398@@ -9,11 +9,11 @@
27399 #include <linux/atomic.h>
27400
27401 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27402-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27403+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27404 (unsigned long) trace_idt_table };
27405
27406 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27407-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27408+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27409
27410 static int trace_irq_vector_refcount;
27411 static DEFINE_MUTEX(irq_vector_mutex);
27412diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27413index 57409f6..e2c17e1 100644
27414--- a/arch/x86/kernel/traps.c
27415+++ b/arch/x86/kernel/traps.c
27416@@ -66,7 +66,7 @@
27417 #include <asm/proto.h>
27418
27419 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27420-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27421+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27422 #else
27423 #include <asm/processor-flags.h>
27424 #include <asm/setup.h>
27425@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27426 #endif
27427
27428 /* Must be page-aligned because the real IDT is used in a fixmap. */
27429-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27430+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27431
27432 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27433 EXPORT_SYMBOL_GPL(used_vectors);
27434@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27435 }
27436
27437 static int __kprobes
27438-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27439+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27440 struct pt_regs *regs, long error_code)
27441 {
27442 #ifdef CONFIG_X86_32
27443- if (regs->flags & X86_VM_MASK) {
27444+ if (v8086_mode(regs)) {
27445 /*
27446 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27447 * On nmi (interrupt 2), do_trap should not be called.
27448@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27449 return -1;
27450 }
27451 #endif
27452- if (!user_mode(regs)) {
27453+ if (!user_mode_novm(regs)) {
27454 if (!fixup_exception(regs)) {
27455 tsk->thread.error_code = error_code;
27456 tsk->thread.trap_nr = trapnr;
27457+
27458+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27459+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27460+ str = "PAX: suspicious stack segment fault";
27461+#endif
27462+
27463 die(str, regs, error_code);
27464 }
27465+
27466+#ifdef CONFIG_PAX_REFCOUNT
27467+ if (trapnr == X86_TRAP_OF)
27468+ pax_report_refcount_overflow(regs);
27469+#endif
27470+
27471 return 0;
27472 }
27473
27474@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27475 }
27476
27477 static void __kprobes
27478-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27479+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27480 long error_code, siginfo_t *info)
27481 {
27482 struct task_struct *tsk = current;
27483@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27484 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27485 printk_ratelimit()) {
27486 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27487- tsk->comm, tsk->pid, str,
27488+ tsk->comm, task_pid_nr(tsk), str,
27489 regs->ip, regs->sp, error_code);
27490 print_vma_addr(" in ", regs->ip);
27491 pr_cont("\n");
27492@@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27493 conditional_sti(regs);
27494
27495 #ifdef CONFIG_X86_32
27496- if (regs->flags & X86_VM_MASK) {
27497+ if (v8086_mode(regs)) {
27498 local_irq_enable();
27499 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27500 goto exit;
27501@@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27502 #endif
27503
27504 tsk = current;
27505- if (!user_mode(regs)) {
27506+ if (!user_mode_novm(regs)) {
27507 if (fixup_exception(regs))
27508 goto exit;
27509
27510 tsk->thread.error_code = error_code;
27511 tsk->thread.trap_nr = X86_TRAP_GP;
27512 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27513- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27514+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27515+
27516+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27517+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27518+ die("PAX: suspicious general protection fault", regs, error_code);
27519+ else
27520+#endif
27521+
27522 die("general protection fault", regs, error_code);
27523+ }
27524 goto exit;
27525 }
27526
27527+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27528+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27529+ struct mm_struct *mm = tsk->mm;
27530+ unsigned long limit;
27531+
27532+ down_write(&mm->mmap_sem);
27533+ limit = mm->context.user_cs_limit;
27534+ if (limit < TASK_SIZE) {
27535+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27536+ up_write(&mm->mmap_sem);
27537+ return;
27538+ }
27539+ up_write(&mm->mmap_sem);
27540+ }
27541+#endif
27542+
27543 tsk->thread.error_code = error_code;
27544 tsk->thread.trap_nr = X86_TRAP_GP;
27545
27546@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27547 /* It's safe to allow irq's after DR6 has been saved */
27548 preempt_conditional_sti(regs);
27549
27550- if (regs->flags & X86_VM_MASK) {
27551+ if (v8086_mode(regs)) {
27552 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27553 X86_TRAP_DB);
27554 preempt_conditional_cli(regs);
27555@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27556 * We already checked v86 mode above, so we can check for kernel mode
27557 * by just checking the CPL of CS.
27558 */
27559- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27560+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27561 tsk->thread.debugreg6 &= ~DR_STEP;
27562 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27563 regs->flags &= ~X86_EFLAGS_TF;
27564@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27565 return;
27566 conditional_sti(regs);
27567
27568- if (!user_mode_vm(regs))
27569+ if (!user_mode(regs))
27570 {
27571 if (!fixup_exception(regs)) {
27572 task->thread.error_code = error_code;
27573diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27574index cfbe99f..a6e8fa7 100644
27575--- a/arch/x86/kernel/tsc.c
27576+++ b/arch/x86/kernel/tsc.c
27577@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27578 */
27579 smp_wmb();
27580
27581- ACCESS_ONCE(c2n->head) = data;
27582+ ACCESS_ONCE_RW(c2n->head) = data;
27583 }
27584
27585 /*
27586diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27587index 2ed8459..7cf329f 100644
27588--- a/arch/x86/kernel/uprobes.c
27589+++ b/arch/x86/kernel/uprobes.c
27590@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27591 int ret = NOTIFY_DONE;
27592
27593 /* We are only interested in userspace traps */
27594- if (regs && !user_mode_vm(regs))
27595+ if (regs && !user_mode(regs))
27596 return NOTIFY_DONE;
27597
27598 switch (val) {
27599@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27600
27601 if (ncopied != rasize) {
27602 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27603- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27604+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27605
27606 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27607 }
27608diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27609index b9242ba..50c5edd 100644
27610--- a/arch/x86/kernel/verify_cpu.S
27611+++ b/arch/x86/kernel/verify_cpu.S
27612@@ -20,6 +20,7 @@
27613 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27614 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27615 * arch/x86/kernel/head_32.S: processor startup
27616+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27617 *
27618 * verify_cpu, returns the status of longmode and SSE in register %eax.
27619 * 0: Success 1: Failure
27620diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27621index e8edcf5..27f9344 100644
27622--- a/arch/x86/kernel/vm86_32.c
27623+++ b/arch/x86/kernel/vm86_32.c
27624@@ -44,6 +44,7 @@
27625 #include <linux/ptrace.h>
27626 #include <linux/audit.h>
27627 #include <linux/stddef.h>
27628+#include <linux/grsecurity.h>
27629
27630 #include <asm/uaccess.h>
27631 #include <asm/io.h>
27632@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27633 do_exit(SIGSEGV);
27634 }
27635
27636- tss = &per_cpu(init_tss, get_cpu());
27637+ tss = init_tss + get_cpu();
27638 current->thread.sp0 = current->thread.saved_sp0;
27639 current->thread.sysenter_cs = __KERNEL_CS;
27640 load_sp0(tss, &current->thread);
27641@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27642
27643 if (tsk->thread.saved_sp0)
27644 return -EPERM;
27645+
27646+#ifdef CONFIG_GRKERNSEC_VM86
27647+ if (!capable(CAP_SYS_RAWIO)) {
27648+ gr_handle_vm86();
27649+ return -EPERM;
27650+ }
27651+#endif
27652+
27653 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27654 offsetof(struct kernel_vm86_struct, vm86plus) -
27655 sizeof(info.regs));
27656@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27657 int tmp;
27658 struct vm86plus_struct __user *v86;
27659
27660+#ifdef CONFIG_GRKERNSEC_VM86
27661+ if (!capable(CAP_SYS_RAWIO)) {
27662+ gr_handle_vm86();
27663+ return -EPERM;
27664+ }
27665+#endif
27666+
27667 tsk = current;
27668 switch (cmd) {
27669 case VM86_REQUEST_IRQ:
27670@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27671 tsk->thread.saved_fs = info->regs32->fs;
27672 tsk->thread.saved_gs = get_user_gs(info->regs32);
27673
27674- tss = &per_cpu(init_tss, get_cpu());
27675+ tss = init_tss + get_cpu();
27676 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27677 if (cpu_has_sep)
27678 tsk->thread.sysenter_cs = 0;
27679@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27680 goto cannot_handle;
27681 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27682 goto cannot_handle;
27683- intr_ptr = (unsigned long __user *) (i << 2);
27684+ intr_ptr = (__force unsigned long __user *) (i << 2);
27685 if (get_user(segoffs, intr_ptr))
27686 goto cannot_handle;
27687 if ((segoffs >> 16) == BIOSSEG)
27688diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27689index da6b35a..977e9cf 100644
27690--- a/arch/x86/kernel/vmlinux.lds.S
27691+++ b/arch/x86/kernel/vmlinux.lds.S
27692@@ -26,6 +26,13 @@
27693 #include <asm/page_types.h>
27694 #include <asm/cache.h>
27695 #include <asm/boot.h>
27696+#include <asm/segment.h>
27697+
27698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27699+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27700+#else
27701+#define __KERNEL_TEXT_OFFSET 0
27702+#endif
27703
27704 #undef i386 /* in case the preprocessor is a 32bit one */
27705
27706@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27707
27708 PHDRS {
27709 text PT_LOAD FLAGS(5); /* R_E */
27710+#ifdef CONFIG_X86_32
27711+ module PT_LOAD FLAGS(5); /* R_E */
27712+#endif
27713+#ifdef CONFIG_XEN
27714+ rodata PT_LOAD FLAGS(5); /* R_E */
27715+#else
27716+ rodata PT_LOAD FLAGS(4); /* R__ */
27717+#endif
27718 data PT_LOAD FLAGS(6); /* RW_ */
27719-#ifdef CONFIG_X86_64
27720+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27721 #ifdef CONFIG_SMP
27722 percpu PT_LOAD FLAGS(6); /* RW_ */
27723 #endif
27724+ text.init PT_LOAD FLAGS(5); /* R_E */
27725+ text.exit PT_LOAD FLAGS(5); /* R_E */
27726 init PT_LOAD FLAGS(7); /* RWE */
27727-#endif
27728 note PT_NOTE FLAGS(0); /* ___ */
27729 }
27730
27731 SECTIONS
27732 {
27733 #ifdef CONFIG_X86_32
27734- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27735- phys_startup_32 = startup_32 - LOAD_OFFSET;
27736+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27737 #else
27738- . = __START_KERNEL;
27739- phys_startup_64 = startup_64 - LOAD_OFFSET;
27740+ . = __START_KERNEL;
27741 #endif
27742
27743 /* Text and read-only data */
27744- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27745- _text = .;
27746+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27747 /* bootstrapping code */
27748+#ifdef CONFIG_X86_32
27749+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27750+#else
27751+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27752+#endif
27753+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27754+ _text = .;
27755 HEAD_TEXT
27756 . = ALIGN(8);
27757 _stext = .;
27758@@ -104,13 +124,47 @@ SECTIONS
27759 IRQENTRY_TEXT
27760 *(.fixup)
27761 *(.gnu.warning)
27762- /* End of text section */
27763- _etext = .;
27764 } :text = 0x9090
27765
27766- NOTES :text :note
27767+ . += __KERNEL_TEXT_OFFSET;
27768
27769- EXCEPTION_TABLE(16) :text = 0x9090
27770+#ifdef CONFIG_X86_32
27771+ . = ALIGN(PAGE_SIZE);
27772+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27773+
27774+#ifdef CONFIG_PAX_KERNEXEC
27775+ MODULES_EXEC_VADDR = .;
27776+ BYTE(0)
27777+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27778+ . = ALIGN(HPAGE_SIZE) - 1;
27779+ MODULES_EXEC_END = .;
27780+#endif
27781+
27782+ } :module
27783+#endif
27784+
27785+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27786+ /* End of text section */
27787+ BYTE(0)
27788+ _etext = . - __KERNEL_TEXT_OFFSET;
27789+ }
27790+
27791+#ifdef CONFIG_X86_32
27792+ . = ALIGN(PAGE_SIZE);
27793+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27794+ . = ALIGN(PAGE_SIZE);
27795+ *(.empty_zero_page)
27796+ *(.initial_pg_fixmap)
27797+ *(.initial_pg_pmd)
27798+ *(.initial_page_table)
27799+ *(.swapper_pg_dir)
27800+ } :rodata
27801+#endif
27802+
27803+ . = ALIGN(PAGE_SIZE);
27804+ NOTES :rodata :note
27805+
27806+ EXCEPTION_TABLE(16) :rodata
27807
27808 #if defined(CONFIG_DEBUG_RODATA)
27809 /* .text should occupy whole number of pages */
27810@@ -122,16 +176,20 @@ SECTIONS
27811
27812 /* Data */
27813 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27814+
27815+#ifdef CONFIG_PAX_KERNEXEC
27816+ . = ALIGN(HPAGE_SIZE);
27817+#else
27818+ . = ALIGN(PAGE_SIZE);
27819+#endif
27820+
27821 /* Start of data section */
27822 _sdata = .;
27823
27824 /* init_task */
27825 INIT_TASK_DATA(THREAD_SIZE)
27826
27827-#ifdef CONFIG_X86_32
27828- /* 32 bit has nosave before _edata */
27829 NOSAVE_DATA
27830-#endif
27831
27832 PAGE_ALIGNED_DATA(PAGE_SIZE)
27833
27834@@ -172,12 +230,19 @@ SECTIONS
27835 #endif /* CONFIG_X86_64 */
27836
27837 /* Init code and data - will be freed after init */
27838- . = ALIGN(PAGE_SIZE);
27839 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27840+ BYTE(0)
27841+
27842+#ifdef CONFIG_PAX_KERNEXEC
27843+ . = ALIGN(HPAGE_SIZE);
27844+#else
27845+ . = ALIGN(PAGE_SIZE);
27846+#endif
27847+
27848 __init_begin = .; /* paired with __init_end */
27849- }
27850+ } :init.begin
27851
27852-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27853+#ifdef CONFIG_SMP
27854 /*
27855 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27856 * output PHDR, so the next output section - .init.text - should
27857@@ -186,12 +251,27 @@ SECTIONS
27858 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27859 #endif
27860
27861- INIT_TEXT_SECTION(PAGE_SIZE)
27862-#ifdef CONFIG_X86_64
27863- :init
27864-#endif
27865+ . = ALIGN(PAGE_SIZE);
27866+ init_begin = .;
27867+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27868+ VMLINUX_SYMBOL(_sinittext) = .;
27869+ INIT_TEXT
27870+ VMLINUX_SYMBOL(_einittext) = .;
27871+ . = ALIGN(PAGE_SIZE);
27872+ } :text.init
27873
27874- INIT_DATA_SECTION(16)
27875+ /*
27876+ * .exit.text is discard at runtime, not link time, to deal with
27877+ * references from .altinstructions and .eh_frame
27878+ */
27879+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27880+ EXIT_TEXT
27881+ . = ALIGN(16);
27882+ } :text.exit
27883+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27884+
27885+ . = ALIGN(PAGE_SIZE);
27886+ INIT_DATA_SECTION(16) :init
27887
27888 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27889 __x86_cpu_dev_start = .;
27890@@ -262,19 +342,12 @@ SECTIONS
27891 }
27892
27893 . = ALIGN(8);
27894- /*
27895- * .exit.text is discard at runtime, not link time, to deal with
27896- * references from .altinstructions and .eh_frame
27897- */
27898- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27899- EXIT_TEXT
27900- }
27901
27902 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27903 EXIT_DATA
27904 }
27905
27906-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27907+#ifndef CONFIG_SMP
27908 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27909 #endif
27910
27911@@ -293,16 +366,10 @@ SECTIONS
27912 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27913 __smp_locks = .;
27914 *(.smp_locks)
27915- . = ALIGN(PAGE_SIZE);
27916 __smp_locks_end = .;
27917+ . = ALIGN(PAGE_SIZE);
27918 }
27919
27920-#ifdef CONFIG_X86_64
27921- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27922- NOSAVE_DATA
27923- }
27924-#endif
27925-
27926 /* BSS */
27927 . = ALIGN(PAGE_SIZE);
27928 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27929@@ -318,6 +385,7 @@ SECTIONS
27930 __brk_base = .;
27931 . += 64 * 1024; /* 64k alignment slop space */
27932 *(.brk_reservation) /* areas brk users have reserved */
27933+ . = ALIGN(HPAGE_SIZE);
27934 __brk_limit = .;
27935 }
27936
27937@@ -344,13 +412,12 @@ SECTIONS
27938 * for the boot processor.
27939 */
27940 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27941-INIT_PER_CPU(gdt_page);
27942 INIT_PER_CPU(irq_stack_union);
27943
27944 /*
27945 * Build-time check on the image size:
27946 */
27947-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27948+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27949 "kernel image bigger than KERNEL_IMAGE_SIZE");
27950
27951 #ifdef CONFIG_SMP
27952diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27953index 1f96f93..d5c8f7a 100644
27954--- a/arch/x86/kernel/vsyscall_64.c
27955+++ b/arch/x86/kernel/vsyscall_64.c
27956@@ -56,15 +56,13 @@
27957 DEFINE_VVAR(int, vgetcpu_mode);
27958 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27959
27960-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27961+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27962
27963 static int __init vsyscall_setup(char *str)
27964 {
27965 if (str) {
27966 if (!strcmp("emulate", str))
27967 vsyscall_mode = EMULATE;
27968- else if (!strcmp("native", str))
27969- vsyscall_mode = NATIVE;
27970 else if (!strcmp("none", str))
27971 vsyscall_mode = NONE;
27972 else
27973@@ -323,8 +321,7 @@ do_ret:
27974 return true;
27975
27976 sigsegv:
27977- force_sig(SIGSEGV, current);
27978- return true;
27979+ do_group_exit(SIGKILL);
27980 }
27981
27982 /*
27983@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27984 extern char __vvar_page;
27985 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27986
27987- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27988- vsyscall_mode == NATIVE
27989- ? PAGE_KERNEL_VSYSCALL
27990- : PAGE_KERNEL_VVAR);
27991+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27992 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27993 (unsigned long)VSYSCALL_START);
27994
27995diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27996index 04068192..4d75aa6 100644
27997--- a/arch/x86/kernel/x8664_ksyms_64.c
27998+++ b/arch/x86/kernel/x8664_ksyms_64.c
27999@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28000 EXPORT_SYMBOL(copy_user_generic_unrolled);
28001 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28002 EXPORT_SYMBOL(__copy_user_nocache);
28003-EXPORT_SYMBOL(_copy_from_user);
28004-EXPORT_SYMBOL(_copy_to_user);
28005
28006 EXPORT_SYMBOL(copy_page);
28007 EXPORT_SYMBOL(clear_page);
28008@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28009 EXPORT_SYMBOL(___preempt_schedule_context);
28010 #endif
28011 #endif
28012+
28013+#ifdef CONFIG_PAX_PER_CPU_PGD
28014+EXPORT_SYMBOL(cpu_pgd);
28015+#endif
28016diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28017index e48b674..a451dd9 100644
28018--- a/arch/x86/kernel/x86_init.c
28019+++ b/arch/x86/kernel/x86_init.c
28020@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28021 static void default_nmi_init(void) { };
28022 static int default_i8042_detect(void) { return 1; };
28023
28024-struct x86_platform_ops x86_platform = {
28025+struct x86_platform_ops x86_platform __read_only = {
28026 .calibrate_tsc = native_calibrate_tsc,
28027 .get_wallclock = mach_get_cmos_time,
28028 .set_wallclock = mach_set_rtc_mmss,
28029@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28030 EXPORT_SYMBOL_GPL(x86_platform);
28031
28032 #if defined(CONFIG_PCI_MSI)
28033-struct x86_msi_ops x86_msi = {
28034+struct x86_msi_ops x86_msi __read_only = {
28035 .setup_msi_irqs = native_setup_msi_irqs,
28036 .compose_msi_msg = native_compose_msi_msg,
28037 .teardown_msi_irq = native_teardown_msi_irq,
28038@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28039 }
28040 #endif
28041
28042-struct x86_io_apic_ops x86_io_apic_ops = {
28043+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28044 .init = native_io_apic_init_mappings,
28045 .read = native_io_apic_read,
28046 .write = native_io_apic_write,
28047diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28048index a4b451c..8dfe1ad 100644
28049--- a/arch/x86/kernel/xsave.c
28050+++ b/arch/x86/kernel/xsave.c
28051@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28052
28053 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28054 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28055- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28056+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28057
28058 if (!use_xsave())
28059 return err;
28060
28061- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28062+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28063
28064 /*
28065 * Read the xstate_bv which we copied (directly from the cpu or
28066 * from the state in task struct) to the user buffers.
28067 */
28068- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28069+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28070
28071 /*
28072 * For legacy compatible, we always set FP/SSE bits in the bit
28073@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28074 */
28075 xstate_bv |= XSTATE_FPSSE;
28076
28077- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28078+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28079
28080 return err;
28081 }
28082@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28083 {
28084 int err;
28085
28086+ buf = (struct xsave_struct __user *)____m(buf);
28087 if (use_xsave())
28088 err = xsave_user(buf);
28089 else if (use_fxsr())
28090@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28091 */
28092 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28093 {
28094+ buf = (void __user *)____m(buf);
28095 if (use_xsave()) {
28096 if ((unsigned long)buf % 64 || fx_only) {
28097 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28098diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28099index c697625..a032162 100644
28100--- a/arch/x86/kvm/cpuid.c
28101+++ b/arch/x86/kvm/cpuid.c
28102@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28103 struct kvm_cpuid2 *cpuid,
28104 struct kvm_cpuid_entry2 __user *entries)
28105 {
28106- int r;
28107+ int r, i;
28108
28109 r = -E2BIG;
28110 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28111 goto out;
28112 r = -EFAULT;
28113- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28114- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28115+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28116 goto out;
28117+ for (i = 0; i < cpuid->nent; ++i) {
28118+ struct kvm_cpuid_entry2 cpuid_entry;
28119+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28120+ goto out;
28121+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28122+ }
28123 vcpu->arch.cpuid_nent = cpuid->nent;
28124 kvm_apic_set_version(vcpu);
28125 kvm_x86_ops->cpuid_update(vcpu);
28126@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28127 struct kvm_cpuid2 *cpuid,
28128 struct kvm_cpuid_entry2 __user *entries)
28129 {
28130- int r;
28131+ int r, i;
28132
28133 r = -E2BIG;
28134 if (cpuid->nent < vcpu->arch.cpuid_nent)
28135 goto out;
28136 r = -EFAULT;
28137- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28138- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28139+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28140 goto out;
28141+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28142+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28143+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28144+ goto out;
28145+ }
28146 return 0;
28147
28148 out:
28149diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28150index 9736529..ab4f54c 100644
28151--- a/arch/x86/kvm/lapic.c
28152+++ b/arch/x86/kvm/lapic.c
28153@@ -55,7 +55,7 @@
28154 #define APIC_BUS_CYCLE_NS 1
28155
28156 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28157-#define apic_debug(fmt, arg...)
28158+#define apic_debug(fmt, arg...) do {} while (0)
28159
28160 #define APIC_LVT_NUM 6
28161 /* 14 is the version for Xeon and Pentium 8.4.8*/
28162diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28163index cba218a..1cc1bed 100644
28164--- a/arch/x86/kvm/paging_tmpl.h
28165+++ b/arch/x86/kvm/paging_tmpl.h
28166@@ -331,7 +331,7 @@ retry_walk:
28167 if (unlikely(kvm_is_error_hva(host_addr)))
28168 goto error;
28169
28170- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28171+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28172 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28173 goto error;
28174 walker->ptep_user[walker->level - 1] = ptep_user;
28175diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28176index 2de1bc0..22251ee 100644
28177--- a/arch/x86/kvm/svm.c
28178+++ b/arch/x86/kvm/svm.c
28179@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28180 int cpu = raw_smp_processor_id();
28181
28182 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28183+
28184+ pax_open_kernel();
28185 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28186+ pax_close_kernel();
28187+
28188 load_TR_desc();
28189 }
28190
28191@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28192 #endif
28193 #endif
28194
28195+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28196+ __set_fs(current_thread_info()->addr_limit);
28197+#endif
28198+
28199 reload_tss(vcpu);
28200
28201 local_irq_disable();
28202diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28203index 3927528..fc19971 100644
28204--- a/arch/x86/kvm/vmx.c
28205+++ b/arch/x86/kvm/vmx.c
28206@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28207 #endif
28208 }
28209
28210-static void vmcs_clear_bits(unsigned long field, u32 mask)
28211+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28212 {
28213 vmcs_writel(field, vmcs_readl(field) & ~mask);
28214 }
28215
28216-static void vmcs_set_bits(unsigned long field, u32 mask)
28217+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28218 {
28219 vmcs_writel(field, vmcs_readl(field) | mask);
28220 }
28221@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28222 struct desc_struct *descs;
28223
28224 descs = (void *)gdt->address;
28225+
28226+ pax_open_kernel();
28227 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28228+ pax_close_kernel();
28229+
28230 load_TR_desc();
28231 }
28232
28233@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28234 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28235 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28236
28237+#ifdef CONFIG_PAX_PER_CPU_PGD
28238+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28239+#endif
28240+
28241 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28242 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28243 vmx->loaded_vmcs->cpu = cpu;
28244@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28245 * reads and returns guest's timestamp counter "register"
28246 * guest_tsc = host_tsc + tsc_offset -- 21.3
28247 */
28248-static u64 guest_read_tsc(void)
28249+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28250 {
28251 u64 host_tsc, tsc_offset;
28252
28253@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28254 if (!cpu_has_vmx_flexpriority())
28255 flexpriority_enabled = 0;
28256
28257- if (!cpu_has_vmx_tpr_shadow())
28258- kvm_x86_ops->update_cr8_intercept = NULL;
28259+ if (!cpu_has_vmx_tpr_shadow()) {
28260+ pax_open_kernel();
28261+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28262+ pax_close_kernel();
28263+ }
28264
28265 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28266 kvm_disable_largepages();
28267@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28268 if (!cpu_has_vmx_apicv())
28269 enable_apicv = 0;
28270
28271+ pax_open_kernel();
28272 if (enable_apicv)
28273- kvm_x86_ops->update_cr8_intercept = NULL;
28274+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28275 else {
28276- kvm_x86_ops->hwapic_irr_update = NULL;
28277- kvm_x86_ops->deliver_posted_interrupt = NULL;
28278- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28279+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28280+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28281+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28282 }
28283+ pax_close_kernel();
28284
28285 if (nested)
28286 nested_vmx_setup_ctls_msrs();
28287@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28288
28289 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28290 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28291+
28292+#ifndef CONFIG_PAX_PER_CPU_PGD
28293 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28294+#endif
28295
28296 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28297 #ifdef CONFIG_X86_64
28298@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28299 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28300 vmx->host_idt_base = dt.address;
28301
28302- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28303+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28304
28305 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28306 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28307@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28308 "jmp 2f \n\t"
28309 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28310 "2: "
28311+
28312+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28313+ "ljmp %[cs],$3f\n\t"
28314+ "3: "
28315+#endif
28316+
28317 /* Save guest registers, load host registers, keep flags */
28318 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28319 "pop %0 \n\t"
28320@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28321 #endif
28322 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28323 [wordsize]"i"(sizeof(ulong))
28324+
28325+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28326+ ,[cs]"i"(__KERNEL_CS)
28327+#endif
28328+
28329 : "cc", "memory"
28330 #ifdef CONFIG_X86_64
28331 , "rax", "rbx", "rdi", "rsi"
28332@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28333 if (debugctlmsr)
28334 update_debugctlmsr(debugctlmsr);
28335
28336-#ifndef CONFIG_X86_64
28337+#ifdef CONFIG_X86_32
28338 /*
28339 * The sysexit path does not restore ds/es, so we must set them to
28340 * a reasonable value ourselves.
28341@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28342 * may be executed in interrupt context, which saves and restore segments
28343 * around it, nullifying its effect.
28344 */
28345- loadsegment(ds, __USER_DS);
28346- loadsegment(es, __USER_DS);
28347+ loadsegment(ds, __KERNEL_DS);
28348+ loadsegment(es, __KERNEL_DS);
28349+ loadsegment(ss, __KERNEL_DS);
28350+
28351+#ifdef CONFIG_PAX_KERNEXEC
28352+ loadsegment(fs, __KERNEL_PERCPU);
28353+#endif
28354+
28355+#ifdef CONFIG_PAX_MEMORY_UDEREF
28356+ __set_fs(current_thread_info()->addr_limit);
28357+#endif
28358+
28359 #endif
28360
28361 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28362diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28363index 2b85784..ad70e19 100644
28364--- a/arch/x86/kvm/x86.c
28365+++ b/arch/x86/kvm/x86.c
28366@@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28367 {
28368 struct kvm *kvm = vcpu->kvm;
28369 int lm = is_long_mode(vcpu);
28370- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28371- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28372+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28373+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28374 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28375 : kvm->arch.xen_hvm_config.blob_size_32;
28376 u32 page_num = data & ~PAGE_MASK;
28377@@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28378 if (n < msr_list.nmsrs)
28379 goto out;
28380 r = -EFAULT;
28381+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28382+ goto out;
28383 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28384 num_msrs_to_save * sizeof(u32)))
28385 goto out;
28386@@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28387 };
28388 #endif
28389
28390-int kvm_arch_init(void *opaque)
28391+int kvm_arch_init(const void *opaque)
28392 {
28393 int r;
28394 struct kvm_x86_ops *ops = opaque;
28395diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28396index ad1fb5f..fe30b66 100644
28397--- a/arch/x86/lguest/boot.c
28398+++ b/arch/x86/lguest/boot.c
28399@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28400 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28401 * Launcher to reboot us.
28402 */
28403-static void lguest_restart(char *reason)
28404+static __noreturn void lguest_restart(char *reason)
28405 {
28406 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28407+ BUG();
28408 }
28409
28410 /*G:050
28411diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28412index 00933d5..3a64af9 100644
28413--- a/arch/x86/lib/atomic64_386_32.S
28414+++ b/arch/x86/lib/atomic64_386_32.S
28415@@ -48,6 +48,10 @@ BEGIN(read)
28416 movl (v), %eax
28417 movl 4(v), %edx
28418 RET_ENDP
28419+BEGIN(read_unchecked)
28420+ movl (v), %eax
28421+ movl 4(v), %edx
28422+RET_ENDP
28423 #undef v
28424
28425 #define v %esi
28426@@ -55,6 +59,10 @@ BEGIN(set)
28427 movl %ebx, (v)
28428 movl %ecx, 4(v)
28429 RET_ENDP
28430+BEGIN(set_unchecked)
28431+ movl %ebx, (v)
28432+ movl %ecx, 4(v)
28433+RET_ENDP
28434 #undef v
28435
28436 #define v %esi
28437@@ -70,6 +78,20 @@ RET_ENDP
28438 BEGIN(add)
28439 addl %eax, (v)
28440 adcl %edx, 4(v)
28441+
28442+#ifdef CONFIG_PAX_REFCOUNT
28443+ jno 0f
28444+ subl %eax, (v)
28445+ sbbl %edx, 4(v)
28446+ int $4
28447+0:
28448+ _ASM_EXTABLE(0b, 0b)
28449+#endif
28450+
28451+RET_ENDP
28452+BEGIN(add_unchecked)
28453+ addl %eax, (v)
28454+ adcl %edx, 4(v)
28455 RET_ENDP
28456 #undef v
28457
28458@@ -77,6 +99,24 @@ RET_ENDP
28459 BEGIN(add_return)
28460 addl (v), %eax
28461 adcl 4(v), %edx
28462+
28463+#ifdef CONFIG_PAX_REFCOUNT
28464+ into
28465+1234:
28466+ _ASM_EXTABLE(1234b, 2f)
28467+#endif
28468+
28469+ movl %eax, (v)
28470+ movl %edx, 4(v)
28471+
28472+#ifdef CONFIG_PAX_REFCOUNT
28473+2:
28474+#endif
28475+
28476+RET_ENDP
28477+BEGIN(add_return_unchecked)
28478+ addl (v), %eax
28479+ adcl 4(v), %edx
28480 movl %eax, (v)
28481 movl %edx, 4(v)
28482 RET_ENDP
28483@@ -86,6 +126,20 @@ RET_ENDP
28484 BEGIN(sub)
28485 subl %eax, (v)
28486 sbbl %edx, 4(v)
28487+
28488+#ifdef CONFIG_PAX_REFCOUNT
28489+ jno 0f
28490+ addl %eax, (v)
28491+ adcl %edx, 4(v)
28492+ int $4
28493+0:
28494+ _ASM_EXTABLE(0b, 0b)
28495+#endif
28496+
28497+RET_ENDP
28498+BEGIN(sub_unchecked)
28499+ subl %eax, (v)
28500+ sbbl %edx, 4(v)
28501 RET_ENDP
28502 #undef v
28503
28504@@ -96,6 +150,27 @@ BEGIN(sub_return)
28505 sbbl $0, %edx
28506 addl (v), %eax
28507 adcl 4(v), %edx
28508+
28509+#ifdef CONFIG_PAX_REFCOUNT
28510+ into
28511+1234:
28512+ _ASM_EXTABLE(1234b, 2f)
28513+#endif
28514+
28515+ movl %eax, (v)
28516+ movl %edx, 4(v)
28517+
28518+#ifdef CONFIG_PAX_REFCOUNT
28519+2:
28520+#endif
28521+
28522+RET_ENDP
28523+BEGIN(sub_return_unchecked)
28524+ negl %edx
28525+ negl %eax
28526+ sbbl $0, %edx
28527+ addl (v), %eax
28528+ adcl 4(v), %edx
28529 movl %eax, (v)
28530 movl %edx, 4(v)
28531 RET_ENDP
28532@@ -105,6 +180,20 @@ RET_ENDP
28533 BEGIN(inc)
28534 addl $1, (v)
28535 adcl $0, 4(v)
28536+
28537+#ifdef CONFIG_PAX_REFCOUNT
28538+ jno 0f
28539+ subl $1, (v)
28540+ sbbl $0, 4(v)
28541+ int $4
28542+0:
28543+ _ASM_EXTABLE(0b, 0b)
28544+#endif
28545+
28546+RET_ENDP
28547+BEGIN(inc_unchecked)
28548+ addl $1, (v)
28549+ adcl $0, 4(v)
28550 RET_ENDP
28551 #undef v
28552
28553@@ -114,6 +203,26 @@ BEGIN(inc_return)
28554 movl 4(v), %edx
28555 addl $1, %eax
28556 adcl $0, %edx
28557+
28558+#ifdef CONFIG_PAX_REFCOUNT
28559+ into
28560+1234:
28561+ _ASM_EXTABLE(1234b, 2f)
28562+#endif
28563+
28564+ movl %eax, (v)
28565+ movl %edx, 4(v)
28566+
28567+#ifdef CONFIG_PAX_REFCOUNT
28568+2:
28569+#endif
28570+
28571+RET_ENDP
28572+BEGIN(inc_return_unchecked)
28573+ movl (v), %eax
28574+ movl 4(v), %edx
28575+ addl $1, %eax
28576+ adcl $0, %edx
28577 movl %eax, (v)
28578 movl %edx, 4(v)
28579 RET_ENDP
28580@@ -123,6 +232,20 @@ RET_ENDP
28581 BEGIN(dec)
28582 subl $1, (v)
28583 sbbl $0, 4(v)
28584+
28585+#ifdef CONFIG_PAX_REFCOUNT
28586+ jno 0f
28587+ addl $1, (v)
28588+ adcl $0, 4(v)
28589+ int $4
28590+0:
28591+ _ASM_EXTABLE(0b, 0b)
28592+#endif
28593+
28594+RET_ENDP
28595+BEGIN(dec_unchecked)
28596+ subl $1, (v)
28597+ sbbl $0, 4(v)
28598 RET_ENDP
28599 #undef v
28600
28601@@ -132,6 +255,26 @@ BEGIN(dec_return)
28602 movl 4(v), %edx
28603 subl $1, %eax
28604 sbbl $0, %edx
28605+
28606+#ifdef CONFIG_PAX_REFCOUNT
28607+ into
28608+1234:
28609+ _ASM_EXTABLE(1234b, 2f)
28610+#endif
28611+
28612+ movl %eax, (v)
28613+ movl %edx, 4(v)
28614+
28615+#ifdef CONFIG_PAX_REFCOUNT
28616+2:
28617+#endif
28618+
28619+RET_ENDP
28620+BEGIN(dec_return_unchecked)
28621+ movl (v), %eax
28622+ movl 4(v), %edx
28623+ subl $1, %eax
28624+ sbbl $0, %edx
28625 movl %eax, (v)
28626 movl %edx, 4(v)
28627 RET_ENDP
28628@@ -143,6 +286,13 @@ BEGIN(add_unless)
28629 adcl %edx, %edi
28630 addl (v), %eax
28631 adcl 4(v), %edx
28632+
28633+#ifdef CONFIG_PAX_REFCOUNT
28634+ into
28635+1234:
28636+ _ASM_EXTABLE(1234b, 2f)
28637+#endif
28638+
28639 cmpl %eax, %ecx
28640 je 3f
28641 1:
28642@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28643 1:
28644 addl $1, %eax
28645 adcl $0, %edx
28646+
28647+#ifdef CONFIG_PAX_REFCOUNT
28648+ into
28649+1234:
28650+ _ASM_EXTABLE(1234b, 2f)
28651+#endif
28652+
28653 movl %eax, (v)
28654 movl %edx, 4(v)
28655 movl $1, %eax
28656@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28657 movl 4(v), %edx
28658 subl $1, %eax
28659 sbbl $0, %edx
28660+
28661+#ifdef CONFIG_PAX_REFCOUNT
28662+ into
28663+1234:
28664+ _ASM_EXTABLE(1234b, 1f)
28665+#endif
28666+
28667 js 1f
28668 movl %eax, (v)
28669 movl %edx, 4(v)
28670diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28671index f5cc9eb..51fa319 100644
28672--- a/arch/x86/lib/atomic64_cx8_32.S
28673+++ b/arch/x86/lib/atomic64_cx8_32.S
28674@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28675 CFI_STARTPROC
28676
28677 read64 %ecx
28678+ pax_force_retaddr
28679 ret
28680 CFI_ENDPROC
28681 ENDPROC(atomic64_read_cx8)
28682
28683+ENTRY(atomic64_read_unchecked_cx8)
28684+ CFI_STARTPROC
28685+
28686+ read64 %ecx
28687+ pax_force_retaddr
28688+ ret
28689+ CFI_ENDPROC
28690+ENDPROC(atomic64_read_unchecked_cx8)
28691+
28692 ENTRY(atomic64_set_cx8)
28693 CFI_STARTPROC
28694
28695@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28696 cmpxchg8b (%esi)
28697 jne 1b
28698
28699+ pax_force_retaddr
28700 ret
28701 CFI_ENDPROC
28702 ENDPROC(atomic64_set_cx8)
28703
28704+ENTRY(atomic64_set_unchecked_cx8)
28705+ CFI_STARTPROC
28706+
28707+1:
28708+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28709+ * are atomic on 586 and newer */
28710+ cmpxchg8b (%esi)
28711+ jne 1b
28712+
28713+ pax_force_retaddr
28714+ ret
28715+ CFI_ENDPROC
28716+ENDPROC(atomic64_set_unchecked_cx8)
28717+
28718 ENTRY(atomic64_xchg_cx8)
28719 CFI_STARTPROC
28720
28721@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28722 cmpxchg8b (%esi)
28723 jne 1b
28724
28725+ pax_force_retaddr
28726 ret
28727 CFI_ENDPROC
28728 ENDPROC(atomic64_xchg_cx8)
28729
28730-.macro addsub_return func ins insc
28731-ENTRY(atomic64_\func\()_return_cx8)
28732+.macro addsub_return func ins insc unchecked=""
28733+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28734 CFI_STARTPROC
28735 SAVE ebp
28736 SAVE ebx
28737@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28738 movl %edx, %ecx
28739 \ins\()l %esi, %ebx
28740 \insc\()l %edi, %ecx
28741+
28742+.ifb \unchecked
28743+#ifdef CONFIG_PAX_REFCOUNT
28744+ into
28745+2:
28746+ _ASM_EXTABLE(2b, 3f)
28747+#endif
28748+.endif
28749+
28750 LOCK_PREFIX
28751 cmpxchg8b (%ebp)
28752 jne 1b
28753-
28754-10:
28755 movl %ebx, %eax
28756 movl %ecx, %edx
28757+
28758+.ifb \unchecked
28759+#ifdef CONFIG_PAX_REFCOUNT
28760+3:
28761+#endif
28762+.endif
28763+
28764 RESTORE edi
28765 RESTORE esi
28766 RESTORE ebx
28767 RESTORE ebp
28768+ pax_force_retaddr
28769 ret
28770 CFI_ENDPROC
28771-ENDPROC(atomic64_\func\()_return_cx8)
28772+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28773 .endm
28774
28775 addsub_return add add adc
28776 addsub_return sub sub sbb
28777+addsub_return add add adc _unchecked
28778+addsub_return sub sub sbb _unchecked
28779
28780-.macro incdec_return func ins insc
28781-ENTRY(atomic64_\func\()_return_cx8)
28782+.macro incdec_return func ins insc unchecked=""
28783+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28784 CFI_STARTPROC
28785 SAVE ebx
28786
28787@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28788 movl %edx, %ecx
28789 \ins\()l $1, %ebx
28790 \insc\()l $0, %ecx
28791+
28792+.ifb \unchecked
28793+#ifdef CONFIG_PAX_REFCOUNT
28794+ into
28795+2:
28796+ _ASM_EXTABLE(2b, 3f)
28797+#endif
28798+.endif
28799+
28800 LOCK_PREFIX
28801 cmpxchg8b (%esi)
28802 jne 1b
28803
28804-10:
28805 movl %ebx, %eax
28806 movl %ecx, %edx
28807+
28808+.ifb \unchecked
28809+#ifdef CONFIG_PAX_REFCOUNT
28810+3:
28811+#endif
28812+.endif
28813+
28814 RESTORE ebx
28815+ pax_force_retaddr
28816 ret
28817 CFI_ENDPROC
28818-ENDPROC(atomic64_\func\()_return_cx8)
28819+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28820 .endm
28821
28822 incdec_return inc add adc
28823 incdec_return dec sub sbb
28824+incdec_return inc add adc _unchecked
28825+incdec_return dec sub sbb _unchecked
28826
28827 ENTRY(atomic64_dec_if_positive_cx8)
28828 CFI_STARTPROC
28829@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28830 movl %edx, %ecx
28831 subl $1, %ebx
28832 sbb $0, %ecx
28833+
28834+#ifdef CONFIG_PAX_REFCOUNT
28835+ into
28836+1234:
28837+ _ASM_EXTABLE(1234b, 2f)
28838+#endif
28839+
28840 js 2f
28841 LOCK_PREFIX
28842 cmpxchg8b (%esi)
28843@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28844 movl %ebx, %eax
28845 movl %ecx, %edx
28846 RESTORE ebx
28847+ pax_force_retaddr
28848 ret
28849 CFI_ENDPROC
28850 ENDPROC(atomic64_dec_if_positive_cx8)
28851@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28852 movl %edx, %ecx
28853 addl %ebp, %ebx
28854 adcl %edi, %ecx
28855+
28856+#ifdef CONFIG_PAX_REFCOUNT
28857+ into
28858+1234:
28859+ _ASM_EXTABLE(1234b, 3f)
28860+#endif
28861+
28862 LOCK_PREFIX
28863 cmpxchg8b (%esi)
28864 jne 1b
28865@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28866 CFI_ADJUST_CFA_OFFSET -8
28867 RESTORE ebx
28868 RESTORE ebp
28869+ pax_force_retaddr
28870 ret
28871 4:
28872 cmpl %edx, 4(%esp)
28873@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28874 xorl %ecx, %ecx
28875 addl $1, %ebx
28876 adcl %edx, %ecx
28877+
28878+#ifdef CONFIG_PAX_REFCOUNT
28879+ into
28880+1234:
28881+ _ASM_EXTABLE(1234b, 3f)
28882+#endif
28883+
28884 LOCK_PREFIX
28885 cmpxchg8b (%esi)
28886 jne 1b
28887@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28888 movl $1, %eax
28889 3:
28890 RESTORE ebx
28891+ pax_force_retaddr
28892 ret
28893 CFI_ENDPROC
28894 ENDPROC(atomic64_inc_not_zero_cx8)
28895diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28896index e78b8ee..7e173a8 100644
28897--- a/arch/x86/lib/checksum_32.S
28898+++ b/arch/x86/lib/checksum_32.S
28899@@ -29,7 +29,8 @@
28900 #include <asm/dwarf2.h>
28901 #include <asm/errno.h>
28902 #include <asm/asm.h>
28903-
28904+#include <asm/segment.h>
28905+
28906 /*
28907 * computes a partial checksum, e.g. for TCP/UDP fragments
28908 */
28909@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28910
28911 #define ARGBASE 16
28912 #define FP 12
28913-
28914-ENTRY(csum_partial_copy_generic)
28915+
28916+ENTRY(csum_partial_copy_generic_to_user)
28917 CFI_STARTPROC
28918+
28919+#ifdef CONFIG_PAX_MEMORY_UDEREF
28920+ pushl_cfi %gs
28921+ popl_cfi %es
28922+ jmp csum_partial_copy_generic
28923+#endif
28924+
28925+ENTRY(csum_partial_copy_generic_from_user)
28926+
28927+#ifdef CONFIG_PAX_MEMORY_UDEREF
28928+ pushl_cfi %gs
28929+ popl_cfi %ds
28930+#endif
28931+
28932+ENTRY(csum_partial_copy_generic)
28933 subl $4,%esp
28934 CFI_ADJUST_CFA_OFFSET 4
28935 pushl_cfi %edi
28936@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28937 jmp 4f
28938 SRC(1: movw (%esi), %bx )
28939 addl $2, %esi
28940-DST( movw %bx, (%edi) )
28941+DST( movw %bx, %es:(%edi) )
28942 addl $2, %edi
28943 addw %bx, %ax
28944 adcl $0, %eax
28945@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28946 SRC(1: movl (%esi), %ebx )
28947 SRC( movl 4(%esi), %edx )
28948 adcl %ebx, %eax
28949-DST( movl %ebx, (%edi) )
28950+DST( movl %ebx, %es:(%edi) )
28951 adcl %edx, %eax
28952-DST( movl %edx, 4(%edi) )
28953+DST( movl %edx, %es:4(%edi) )
28954
28955 SRC( movl 8(%esi), %ebx )
28956 SRC( movl 12(%esi), %edx )
28957 adcl %ebx, %eax
28958-DST( movl %ebx, 8(%edi) )
28959+DST( movl %ebx, %es:8(%edi) )
28960 adcl %edx, %eax
28961-DST( movl %edx, 12(%edi) )
28962+DST( movl %edx, %es:12(%edi) )
28963
28964 SRC( movl 16(%esi), %ebx )
28965 SRC( movl 20(%esi), %edx )
28966 adcl %ebx, %eax
28967-DST( movl %ebx, 16(%edi) )
28968+DST( movl %ebx, %es:16(%edi) )
28969 adcl %edx, %eax
28970-DST( movl %edx, 20(%edi) )
28971+DST( movl %edx, %es:20(%edi) )
28972
28973 SRC( movl 24(%esi), %ebx )
28974 SRC( movl 28(%esi), %edx )
28975 adcl %ebx, %eax
28976-DST( movl %ebx, 24(%edi) )
28977+DST( movl %ebx, %es:24(%edi) )
28978 adcl %edx, %eax
28979-DST( movl %edx, 28(%edi) )
28980+DST( movl %edx, %es:28(%edi) )
28981
28982 lea 32(%esi), %esi
28983 lea 32(%edi), %edi
28984@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28985 shrl $2, %edx # This clears CF
28986 SRC(3: movl (%esi), %ebx )
28987 adcl %ebx, %eax
28988-DST( movl %ebx, (%edi) )
28989+DST( movl %ebx, %es:(%edi) )
28990 lea 4(%esi), %esi
28991 lea 4(%edi), %edi
28992 dec %edx
28993@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28994 jb 5f
28995 SRC( movw (%esi), %cx )
28996 leal 2(%esi), %esi
28997-DST( movw %cx, (%edi) )
28998+DST( movw %cx, %es:(%edi) )
28999 leal 2(%edi), %edi
29000 je 6f
29001 shll $16,%ecx
29002 SRC(5: movb (%esi), %cl )
29003-DST( movb %cl, (%edi) )
29004+DST( movb %cl, %es:(%edi) )
29005 6: addl %ecx, %eax
29006 adcl $0, %eax
29007 7:
29008@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29009
29010 6001:
29011 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29012- movl $-EFAULT, (%ebx)
29013+ movl $-EFAULT, %ss:(%ebx)
29014
29015 # zero the complete destination - computing the rest
29016 # is too much work
29017@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29018
29019 6002:
29020 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29021- movl $-EFAULT,(%ebx)
29022+ movl $-EFAULT,%ss:(%ebx)
29023 jmp 5000b
29024
29025 .previous
29026
29027+ pushl_cfi %ss
29028+ popl_cfi %ds
29029+ pushl_cfi %ss
29030+ popl_cfi %es
29031 popl_cfi %ebx
29032 CFI_RESTORE ebx
29033 popl_cfi %esi
29034@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29035 popl_cfi %ecx # equivalent to addl $4,%esp
29036 ret
29037 CFI_ENDPROC
29038-ENDPROC(csum_partial_copy_generic)
29039+ENDPROC(csum_partial_copy_generic_to_user)
29040
29041 #else
29042
29043 /* Version for PentiumII/PPro */
29044
29045 #define ROUND1(x) \
29046+ nop; nop; nop; \
29047 SRC(movl x(%esi), %ebx ) ; \
29048 addl %ebx, %eax ; \
29049- DST(movl %ebx, x(%edi) ) ;
29050+ DST(movl %ebx, %es:x(%edi)) ;
29051
29052 #define ROUND(x) \
29053+ nop; nop; nop; \
29054 SRC(movl x(%esi), %ebx ) ; \
29055 adcl %ebx, %eax ; \
29056- DST(movl %ebx, x(%edi) ) ;
29057+ DST(movl %ebx, %es:x(%edi)) ;
29058
29059 #define ARGBASE 12
29060-
29061-ENTRY(csum_partial_copy_generic)
29062+
29063+ENTRY(csum_partial_copy_generic_to_user)
29064 CFI_STARTPROC
29065+
29066+#ifdef CONFIG_PAX_MEMORY_UDEREF
29067+ pushl_cfi %gs
29068+ popl_cfi %es
29069+ jmp csum_partial_copy_generic
29070+#endif
29071+
29072+ENTRY(csum_partial_copy_generic_from_user)
29073+
29074+#ifdef CONFIG_PAX_MEMORY_UDEREF
29075+ pushl_cfi %gs
29076+ popl_cfi %ds
29077+#endif
29078+
29079+ENTRY(csum_partial_copy_generic)
29080 pushl_cfi %ebx
29081 CFI_REL_OFFSET ebx, 0
29082 pushl_cfi %edi
29083@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29084 subl %ebx, %edi
29085 lea -1(%esi),%edx
29086 andl $-32,%edx
29087- lea 3f(%ebx,%ebx), %ebx
29088+ lea 3f(%ebx,%ebx,2), %ebx
29089 testl %esi, %esi
29090 jmp *%ebx
29091 1: addl $64,%esi
29092@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29093 jb 5f
29094 SRC( movw (%esi), %dx )
29095 leal 2(%esi), %esi
29096-DST( movw %dx, (%edi) )
29097+DST( movw %dx, %es:(%edi) )
29098 leal 2(%edi), %edi
29099 je 6f
29100 shll $16,%edx
29101 5:
29102 SRC( movb (%esi), %dl )
29103-DST( movb %dl, (%edi) )
29104+DST( movb %dl, %es:(%edi) )
29105 6: addl %edx, %eax
29106 adcl $0, %eax
29107 7:
29108 .section .fixup, "ax"
29109 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29110- movl $-EFAULT, (%ebx)
29111+ movl $-EFAULT, %ss:(%ebx)
29112 # zero the complete destination (computing the rest is too much work)
29113 movl ARGBASE+8(%esp),%edi # dst
29114 movl ARGBASE+12(%esp),%ecx # len
29115@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29116 rep; stosb
29117 jmp 7b
29118 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29119- movl $-EFAULT, (%ebx)
29120+ movl $-EFAULT, %ss:(%ebx)
29121 jmp 7b
29122 .previous
29123
29124+#ifdef CONFIG_PAX_MEMORY_UDEREF
29125+ pushl_cfi %ss
29126+ popl_cfi %ds
29127+ pushl_cfi %ss
29128+ popl_cfi %es
29129+#endif
29130+
29131 popl_cfi %esi
29132 CFI_RESTORE esi
29133 popl_cfi %edi
29134@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29135 CFI_RESTORE ebx
29136 ret
29137 CFI_ENDPROC
29138-ENDPROC(csum_partial_copy_generic)
29139+ENDPROC(csum_partial_copy_generic_to_user)
29140
29141 #undef ROUND
29142 #undef ROUND1
29143diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29144index f2145cf..cea889d 100644
29145--- a/arch/x86/lib/clear_page_64.S
29146+++ b/arch/x86/lib/clear_page_64.S
29147@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29148 movl $4096/8,%ecx
29149 xorl %eax,%eax
29150 rep stosq
29151+ pax_force_retaddr
29152 ret
29153 CFI_ENDPROC
29154 ENDPROC(clear_page_c)
29155@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29156 movl $4096,%ecx
29157 xorl %eax,%eax
29158 rep stosb
29159+ pax_force_retaddr
29160 ret
29161 CFI_ENDPROC
29162 ENDPROC(clear_page_c_e)
29163@@ -43,6 +45,7 @@ ENTRY(clear_page)
29164 leaq 64(%rdi),%rdi
29165 jnz .Lloop
29166 nop
29167+ pax_force_retaddr
29168 ret
29169 CFI_ENDPROC
29170 .Lclear_page_end:
29171@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29172
29173 #include <asm/cpufeature.h>
29174
29175- .section .altinstr_replacement,"ax"
29176+ .section .altinstr_replacement,"a"
29177 1: .byte 0xeb /* jmp <disp8> */
29178 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29179 2: .byte 0xeb /* jmp <disp8> */
29180diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29181index 1e572c5..2a162cd 100644
29182--- a/arch/x86/lib/cmpxchg16b_emu.S
29183+++ b/arch/x86/lib/cmpxchg16b_emu.S
29184@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29185
29186 popf
29187 mov $1, %al
29188+ pax_force_retaddr
29189 ret
29190
29191 not_same:
29192 popf
29193 xor %al,%al
29194+ pax_force_retaddr
29195 ret
29196
29197 CFI_ENDPROC
29198diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29199index 176cca6..e0d658e 100644
29200--- a/arch/x86/lib/copy_page_64.S
29201+++ b/arch/x86/lib/copy_page_64.S
29202@@ -9,6 +9,7 @@ copy_page_rep:
29203 CFI_STARTPROC
29204 movl $4096/8, %ecx
29205 rep movsq
29206+ pax_force_retaddr
29207 ret
29208 CFI_ENDPROC
29209 ENDPROC(copy_page_rep)
29210@@ -24,8 +25,8 @@ ENTRY(copy_page)
29211 CFI_ADJUST_CFA_OFFSET 2*8
29212 movq %rbx, (%rsp)
29213 CFI_REL_OFFSET rbx, 0
29214- movq %r12, 1*8(%rsp)
29215- CFI_REL_OFFSET r12, 1*8
29216+ movq %r13, 1*8(%rsp)
29217+ CFI_REL_OFFSET r13, 1*8
29218
29219 movl $(4096/64)-5, %ecx
29220 .p2align 4
29221@@ -38,7 +39,7 @@ ENTRY(copy_page)
29222 movq 0x8*4(%rsi), %r9
29223 movq 0x8*5(%rsi), %r10
29224 movq 0x8*6(%rsi), %r11
29225- movq 0x8*7(%rsi), %r12
29226+ movq 0x8*7(%rsi), %r13
29227
29228 prefetcht0 5*64(%rsi)
29229
29230@@ -49,7 +50,7 @@ ENTRY(copy_page)
29231 movq %r9, 0x8*4(%rdi)
29232 movq %r10, 0x8*5(%rdi)
29233 movq %r11, 0x8*6(%rdi)
29234- movq %r12, 0x8*7(%rdi)
29235+ movq %r13, 0x8*7(%rdi)
29236
29237 leaq 64 (%rsi), %rsi
29238 leaq 64 (%rdi), %rdi
29239@@ -68,7 +69,7 @@ ENTRY(copy_page)
29240 movq 0x8*4(%rsi), %r9
29241 movq 0x8*5(%rsi), %r10
29242 movq 0x8*6(%rsi), %r11
29243- movq 0x8*7(%rsi), %r12
29244+ movq 0x8*7(%rsi), %r13
29245
29246 movq %rax, 0x8*0(%rdi)
29247 movq %rbx, 0x8*1(%rdi)
29248@@ -77,7 +78,7 @@ ENTRY(copy_page)
29249 movq %r9, 0x8*4(%rdi)
29250 movq %r10, 0x8*5(%rdi)
29251 movq %r11, 0x8*6(%rdi)
29252- movq %r12, 0x8*7(%rdi)
29253+ movq %r13, 0x8*7(%rdi)
29254
29255 leaq 64(%rdi), %rdi
29256 leaq 64(%rsi), %rsi
29257@@ -85,10 +86,11 @@ ENTRY(copy_page)
29258
29259 movq (%rsp), %rbx
29260 CFI_RESTORE rbx
29261- movq 1*8(%rsp), %r12
29262- CFI_RESTORE r12
29263+ movq 1*8(%rsp), %r13
29264+ CFI_RESTORE r13
29265 addq $2*8, %rsp
29266 CFI_ADJUST_CFA_OFFSET -2*8
29267+ pax_force_retaddr
29268 ret
29269 .Lcopy_page_end:
29270 CFI_ENDPROC
29271@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29272
29273 #include <asm/cpufeature.h>
29274
29275- .section .altinstr_replacement,"ax"
29276+ .section .altinstr_replacement,"a"
29277 1: .byte 0xeb /* jmp <disp8> */
29278 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29279 2:
29280diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29281index dee945d..a84067b 100644
29282--- a/arch/x86/lib/copy_user_64.S
29283+++ b/arch/x86/lib/copy_user_64.S
29284@@ -18,31 +18,7 @@
29285 #include <asm/alternative-asm.h>
29286 #include <asm/asm.h>
29287 #include <asm/smap.h>
29288-
29289-/*
29290- * By placing feature2 after feature1 in altinstructions section, we logically
29291- * implement:
29292- * If CPU has feature2, jmp to alt2 is used
29293- * else if CPU has feature1, jmp to alt1 is used
29294- * else jmp to orig is used.
29295- */
29296- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29297-0:
29298- .byte 0xe9 /* 32bit jump */
29299- .long \orig-1f /* by default jump to orig */
29300-1:
29301- .section .altinstr_replacement,"ax"
29302-2: .byte 0xe9 /* near jump with 32bit immediate */
29303- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29304-3: .byte 0xe9 /* near jump with 32bit immediate */
29305- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29306- .previous
29307-
29308- .section .altinstructions,"a"
29309- altinstruction_entry 0b,2b,\feature1,5,5
29310- altinstruction_entry 0b,3b,\feature2,5,5
29311- .previous
29312- .endm
29313+#include <asm/pgtable.h>
29314
29315 .macro ALIGN_DESTINATION
29316 #ifdef FIX_ALIGNMENT
29317@@ -70,52 +46,6 @@
29318 #endif
29319 .endm
29320
29321-/* Standard copy_to_user with segment limit checking */
29322-ENTRY(_copy_to_user)
29323- CFI_STARTPROC
29324- GET_THREAD_INFO(%rax)
29325- movq %rdi,%rcx
29326- addq %rdx,%rcx
29327- jc bad_to_user
29328- cmpq TI_addr_limit(%rax),%rcx
29329- ja bad_to_user
29330- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29331- copy_user_generic_unrolled,copy_user_generic_string, \
29332- copy_user_enhanced_fast_string
29333- CFI_ENDPROC
29334-ENDPROC(_copy_to_user)
29335-
29336-/* Standard copy_from_user with segment limit checking */
29337-ENTRY(_copy_from_user)
29338- CFI_STARTPROC
29339- GET_THREAD_INFO(%rax)
29340- movq %rsi,%rcx
29341- addq %rdx,%rcx
29342- jc bad_from_user
29343- cmpq TI_addr_limit(%rax),%rcx
29344- ja bad_from_user
29345- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29346- copy_user_generic_unrolled,copy_user_generic_string, \
29347- copy_user_enhanced_fast_string
29348- CFI_ENDPROC
29349-ENDPROC(_copy_from_user)
29350-
29351- .section .fixup,"ax"
29352- /* must zero dest */
29353-ENTRY(bad_from_user)
29354-bad_from_user:
29355- CFI_STARTPROC
29356- movl %edx,%ecx
29357- xorl %eax,%eax
29358- rep
29359- stosb
29360-bad_to_user:
29361- movl %edx,%eax
29362- ret
29363- CFI_ENDPROC
29364-ENDPROC(bad_from_user)
29365- .previous
29366-
29367 /*
29368 * copy_user_generic_unrolled - memory copy with exception handling.
29369 * This version is for CPUs like P4 that don't have efficient micro
29370@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29371 */
29372 ENTRY(copy_user_generic_unrolled)
29373 CFI_STARTPROC
29374+ ASM_PAX_OPEN_USERLAND
29375 ASM_STAC
29376 cmpl $8,%edx
29377 jb 20f /* less then 8 bytes, go to byte copy loop */
29378@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29379 jnz 21b
29380 23: xor %eax,%eax
29381 ASM_CLAC
29382+ ASM_PAX_CLOSE_USERLAND
29383+ pax_force_retaddr
29384 ret
29385
29386 .section .fixup,"ax"
29387@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29388 */
29389 ENTRY(copy_user_generic_string)
29390 CFI_STARTPROC
29391+ ASM_PAX_OPEN_USERLAND
29392 ASM_STAC
29393 cmpl $8,%edx
29394 jb 2f /* less than 8 bytes, go to byte copy loop */
29395@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29396 movsb
29397 xorl %eax,%eax
29398 ASM_CLAC
29399+ ASM_PAX_CLOSE_USERLAND
29400+ pax_force_retaddr
29401 ret
29402
29403 .section .fixup,"ax"
29404@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29405 */
29406 ENTRY(copy_user_enhanced_fast_string)
29407 CFI_STARTPROC
29408+ ASM_PAX_OPEN_USERLAND
29409 ASM_STAC
29410 movl %edx,%ecx
29411 1: rep
29412 movsb
29413 xorl %eax,%eax
29414 ASM_CLAC
29415+ ASM_PAX_CLOSE_USERLAND
29416+ pax_force_retaddr
29417 ret
29418
29419 .section .fixup,"ax"
29420diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29421index 6a4f43c..c70fb52 100644
29422--- a/arch/x86/lib/copy_user_nocache_64.S
29423+++ b/arch/x86/lib/copy_user_nocache_64.S
29424@@ -8,6 +8,7 @@
29425
29426 #include <linux/linkage.h>
29427 #include <asm/dwarf2.h>
29428+#include <asm/alternative-asm.h>
29429
29430 #define FIX_ALIGNMENT 1
29431
29432@@ -16,6 +17,7 @@
29433 #include <asm/thread_info.h>
29434 #include <asm/asm.h>
29435 #include <asm/smap.h>
29436+#include <asm/pgtable.h>
29437
29438 .macro ALIGN_DESTINATION
29439 #ifdef FIX_ALIGNMENT
29440@@ -49,6 +51,16 @@
29441 */
29442 ENTRY(__copy_user_nocache)
29443 CFI_STARTPROC
29444+
29445+#ifdef CONFIG_PAX_MEMORY_UDEREF
29446+ mov pax_user_shadow_base,%rcx
29447+ cmp %rcx,%rsi
29448+ jae 1f
29449+ add %rcx,%rsi
29450+1:
29451+#endif
29452+
29453+ ASM_PAX_OPEN_USERLAND
29454 ASM_STAC
29455 cmpl $8,%edx
29456 jb 20f /* less then 8 bytes, go to byte copy loop */
29457@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29458 jnz 21b
29459 23: xorl %eax,%eax
29460 ASM_CLAC
29461+ ASM_PAX_CLOSE_USERLAND
29462 sfence
29463+ pax_force_retaddr
29464 ret
29465
29466 .section .fixup,"ax"
29467diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29468index 2419d5f..fe52d0e 100644
29469--- a/arch/x86/lib/csum-copy_64.S
29470+++ b/arch/x86/lib/csum-copy_64.S
29471@@ -9,6 +9,7 @@
29472 #include <asm/dwarf2.h>
29473 #include <asm/errno.h>
29474 #include <asm/asm.h>
29475+#include <asm/alternative-asm.h>
29476
29477 /*
29478 * Checksum copy with exception handling.
29479@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29480 CFI_ADJUST_CFA_OFFSET 7*8
29481 movq %rbx, 2*8(%rsp)
29482 CFI_REL_OFFSET rbx, 2*8
29483- movq %r12, 3*8(%rsp)
29484- CFI_REL_OFFSET r12, 3*8
29485+ movq %r15, 3*8(%rsp)
29486+ CFI_REL_OFFSET r15, 3*8
29487 movq %r14, 4*8(%rsp)
29488 CFI_REL_OFFSET r14, 4*8
29489 movq %r13, 5*8(%rsp)
29490@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29491 movl %edx, %ecx
29492
29493 xorl %r9d, %r9d
29494- movq %rcx, %r12
29495+ movq %rcx, %r15
29496
29497- shrq $6, %r12
29498+ shrq $6, %r15
29499 jz .Lhandle_tail /* < 64 */
29500
29501 clc
29502
29503 /* main loop. clear in 64 byte blocks */
29504 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29505- /* r11: temp3, rdx: temp4, r12 loopcnt */
29506+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29507 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29508 .p2align 4
29509 .Lloop:
29510@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29511 adcq %r14, %rax
29512 adcq %r13, %rax
29513
29514- decl %r12d
29515+ decl %r15d
29516
29517 dest
29518 movq %rbx, (%rsi)
29519@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29520 .Lende:
29521 movq 2*8(%rsp), %rbx
29522 CFI_RESTORE rbx
29523- movq 3*8(%rsp), %r12
29524- CFI_RESTORE r12
29525+ movq 3*8(%rsp), %r15
29526+ CFI_RESTORE r15
29527 movq 4*8(%rsp), %r14
29528 CFI_RESTORE r14
29529 movq 5*8(%rsp), %r13
29530@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29531 CFI_RESTORE rbp
29532 addq $7*8, %rsp
29533 CFI_ADJUST_CFA_OFFSET -7*8
29534+ pax_force_retaddr
29535 ret
29536 CFI_RESTORE_STATE
29537
29538diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29539index 7609e0e..b449b98 100644
29540--- a/arch/x86/lib/csum-wrappers_64.c
29541+++ b/arch/x86/lib/csum-wrappers_64.c
29542@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29543 len -= 2;
29544 }
29545 }
29546+ pax_open_userland();
29547 stac();
29548- isum = csum_partial_copy_generic((__force const void *)src,
29549+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29550 dst, len, isum, errp, NULL);
29551 clac();
29552+ pax_close_userland();
29553 if (unlikely(*errp))
29554 goto out_err;
29555
29556@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29557 }
29558
29559 *errp = 0;
29560+ pax_open_userland();
29561 stac();
29562- ret = csum_partial_copy_generic(src, (void __force *)dst,
29563+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29564 len, isum, NULL, errp);
29565 clac();
29566+ pax_close_userland();
29567 return ret;
29568 }
29569 EXPORT_SYMBOL(csum_partial_copy_to_user);
29570diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29571index a451235..1daa956 100644
29572--- a/arch/x86/lib/getuser.S
29573+++ b/arch/x86/lib/getuser.S
29574@@ -33,17 +33,40 @@
29575 #include <asm/thread_info.h>
29576 #include <asm/asm.h>
29577 #include <asm/smap.h>
29578+#include <asm/segment.h>
29579+#include <asm/pgtable.h>
29580+#include <asm/alternative-asm.h>
29581+
29582+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29583+#define __copyuser_seg gs;
29584+#else
29585+#define __copyuser_seg
29586+#endif
29587
29588 .text
29589 ENTRY(__get_user_1)
29590 CFI_STARTPROC
29591+
29592+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29593 GET_THREAD_INFO(%_ASM_DX)
29594 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29595 jae bad_get_user
29596 ASM_STAC
29597-1: movzbl (%_ASM_AX),%edx
29598+
29599+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29600+ mov pax_user_shadow_base,%_ASM_DX
29601+ cmp %_ASM_DX,%_ASM_AX
29602+ jae 1234f
29603+ add %_ASM_DX,%_ASM_AX
29604+1234:
29605+#endif
29606+
29607+#endif
29608+
29609+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29610 xor %eax,%eax
29611 ASM_CLAC
29612+ pax_force_retaddr
29613 ret
29614 CFI_ENDPROC
29615 ENDPROC(__get_user_1)
29616@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29617 ENTRY(__get_user_2)
29618 CFI_STARTPROC
29619 add $1,%_ASM_AX
29620+
29621+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29622 jc bad_get_user
29623 GET_THREAD_INFO(%_ASM_DX)
29624 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29625 jae bad_get_user
29626 ASM_STAC
29627-2: movzwl -1(%_ASM_AX),%edx
29628+
29629+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29630+ mov pax_user_shadow_base,%_ASM_DX
29631+ cmp %_ASM_DX,%_ASM_AX
29632+ jae 1234f
29633+ add %_ASM_DX,%_ASM_AX
29634+1234:
29635+#endif
29636+
29637+#endif
29638+
29639+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29640 xor %eax,%eax
29641 ASM_CLAC
29642+ pax_force_retaddr
29643 ret
29644 CFI_ENDPROC
29645 ENDPROC(__get_user_2)
29646@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29647 ENTRY(__get_user_4)
29648 CFI_STARTPROC
29649 add $3,%_ASM_AX
29650+
29651+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29652 jc bad_get_user
29653 GET_THREAD_INFO(%_ASM_DX)
29654 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29655 jae bad_get_user
29656 ASM_STAC
29657-3: movl -3(%_ASM_AX),%edx
29658+
29659+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29660+ mov pax_user_shadow_base,%_ASM_DX
29661+ cmp %_ASM_DX,%_ASM_AX
29662+ jae 1234f
29663+ add %_ASM_DX,%_ASM_AX
29664+1234:
29665+#endif
29666+
29667+#endif
29668+
29669+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29670 xor %eax,%eax
29671 ASM_CLAC
29672+ pax_force_retaddr
29673 ret
29674 CFI_ENDPROC
29675 ENDPROC(__get_user_4)
29676@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29677 GET_THREAD_INFO(%_ASM_DX)
29678 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29679 jae bad_get_user
29680+
29681+#ifdef CONFIG_PAX_MEMORY_UDEREF
29682+ mov pax_user_shadow_base,%_ASM_DX
29683+ cmp %_ASM_DX,%_ASM_AX
29684+ jae 1234f
29685+ add %_ASM_DX,%_ASM_AX
29686+1234:
29687+#endif
29688+
29689 ASM_STAC
29690 4: movq -7(%_ASM_AX),%rdx
29691 xor %eax,%eax
29692 ASM_CLAC
29693+ pax_force_retaddr
29694 ret
29695 #else
29696 add $7,%_ASM_AX
29697@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29698 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29699 jae bad_get_user_8
29700 ASM_STAC
29701-4: movl -7(%_ASM_AX),%edx
29702-5: movl -3(%_ASM_AX),%ecx
29703+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29704+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29705 xor %eax,%eax
29706 ASM_CLAC
29707+ pax_force_retaddr
29708 ret
29709 #endif
29710 CFI_ENDPROC
29711@@ -113,6 +175,7 @@ bad_get_user:
29712 xor %edx,%edx
29713 mov $(-EFAULT),%_ASM_AX
29714 ASM_CLAC
29715+ pax_force_retaddr
29716 ret
29717 CFI_ENDPROC
29718 END(bad_get_user)
29719@@ -124,6 +187,7 @@ bad_get_user_8:
29720 xor %ecx,%ecx
29721 mov $(-EFAULT),%_ASM_AX
29722 ASM_CLAC
29723+ pax_force_retaddr
29724 ret
29725 CFI_ENDPROC
29726 END(bad_get_user_8)
29727diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29728index 54fcffe..7be149e 100644
29729--- a/arch/x86/lib/insn.c
29730+++ b/arch/x86/lib/insn.c
29731@@ -20,8 +20,10 @@
29732
29733 #ifdef __KERNEL__
29734 #include <linux/string.h>
29735+#include <asm/pgtable_types.h>
29736 #else
29737 #include <string.h>
29738+#define ktla_ktva(addr) addr
29739 #endif
29740 #include <asm/inat.h>
29741 #include <asm/insn.h>
29742@@ -53,8 +55,8 @@
29743 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29744 {
29745 memset(insn, 0, sizeof(*insn));
29746- insn->kaddr = kaddr;
29747- insn->next_byte = kaddr;
29748+ insn->kaddr = ktla_ktva(kaddr);
29749+ insn->next_byte = ktla_ktva(kaddr);
29750 insn->x86_64 = x86_64 ? 1 : 0;
29751 insn->opnd_bytes = 4;
29752 if (x86_64)
29753diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29754index 05a95e7..326f2fa 100644
29755--- a/arch/x86/lib/iomap_copy_64.S
29756+++ b/arch/x86/lib/iomap_copy_64.S
29757@@ -17,6 +17,7 @@
29758
29759 #include <linux/linkage.h>
29760 #include <asm/dwarf2.h>
29761+#include <asm/alternative-asm.h>
29762
29763 /*
29764 * override generic version in lib/iomap_copy.c
29765@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29766 CFI_STARTPROC
29767 movl %edx,%ecx
29768 rep movsd
29769+ pax_force_retaddr
29770 ret
29771 CFI_ENDPROC
29772 ENDPROC(__iowrite32_copy)
29773diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29774index 56313a3..0db417e 100644
29775--- a/arch/x86/lib/memcpy_64.S
29776+++ b/arch/x86/lib/memcpy_64.S
29777@@ -24,7 +24,7 @@
29778 * This gets patched over the unrolled variant (below) via the
29779 * alternative instructions framework:
29780 */
29781- .section .altinstr_replacement, "ax", @progbits
29782+ .section .altinstr_replacement, "a", @progbits
29783 .Lmemcpy_c:
29784 movq %rdi, %rax
29785 movq %rdx, %rcx
29786@@ -33,6 +33,7 @@
29787 rep movsq
29788 movl %edx, %ecx
29789 rep movsb
29790+ pax_force_retaddr
29791 ret
29792 .Lmemcpy_e:
29793 .previous
29794@@ -44,11 +45,12 @@
29795 * This gets patched over the unrolled variant (below) via the
29796 * alternative instructions framework:
29797 */
29798- .section .altinstr_replacement, "ax", @progbits
29799+ .section .altinstr_replacement, "a", @progbits
29800 .Lmemcpy_c_e:
29801 movq %rdi, %rax
29802 movq %rdx, %rcx
29803 rep movsb
29804+ pax_force_retaddr
29805 ret
29806 .Lmemcpy_e_e:
29807 .previous
29808@@ -136,6 +138,7 @@ ENTRY(memcpy)
29809 movq %r9, 1*8(%rdi)
29810 movq %r10, -2*8(%rdi, %rdx)
29811 movq %r11, -1*8(%rdi, %rdx)
29812+ pax_force_retaddr
29813 retq
29814 .p2align 4
29815 .Lless_16bytes:
29816@@ -148,6 +151,7 @@ ENTRY(memcpy)
29817 movq -1*8(%rsi, %rdx), %r9
29818 movq %r8, 0*8(%rdi)
29819 movq %r9, -1*8(%rdi, %rdx)
29820+ pax_force_retaddr
29821 retq
29822 .p2align 4
29823 .Lless_8bytes:
29824@@ -161,6 +165,7 @@ ENTRY(memcpy)
29825 movl -4(%rsi, %rdx), %r8d
29826 movl %ecx, (%rdi)
29827 movl %r8d, -4(%rdi, %rdx)
29828+ pax_force_retaddr
29829 retq
29830 .p2align 4
29831 .Lless_3bytes:
29832@@ -179,6 +184,7 @@ ENTRY(memcpy)
29833 movb %cl, (%rdi)
29834
29835 .Lend:
29836+ pax_force_retaddr
29837 retq
29838 CFI_ENDPROC
29839 ENDPROC(memcpy)
29840diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29841index 65268a6..dd1de11 100644
29842--- a/arch/x86/lib/memmove_64.S
29843+++ b/arch/x86/lib/memmove_64.S
29844@@ -202,14 +202,16 @@ ENTRY(memmove)
29845 movb (%rsi), %r11b
29846 movb %r11b, (%rdi)
29847 13:
29848+ pax_force_retaddr
29849 retq
29850 CFI_ENDPROC
29851
29852- .section .altinstr_replacement,"ax"
29853+ .section .altinstr_replacement,"a"
29854 .Lmemmove_begin_forward_efs:
29855 /* Forward moving data. */
29856 movq %rdx, %rcx
29857 rep movsb
29858+ pax_force_retaddr
29859 retq
29860 .Lmemmove_end_forward_efs:
29861 .previous
29862diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29863index 2dcb380..2eb79fe 100644
29864--- a/arch/x86/lib/memset_64.S
29865+++ b/arch/x86/lib/memset_64.S
29866@@ -16,7 +16,7 @@
29867 *
29868 * rax original destination
29869 */
29870- .section .altinstr_replacement, "ax", @progbits
29871+ .section .altinstr_replacement, "a", @progbits
29872 .Lmemset_c:
29873 movq %rdi,%r9
29874 movq %rdx,%rcx
29875@@ -30,6 +30,7 @@
29876 movl %edx,%ecx
29877 rep stosb
29878 movq %r9,%rax
29879+ pax_force_retaddr
29880 ret
29881 .Lmemset_e:
29882 .previous
29883@@ -45,13 +46,14 @@
29884 *
29885 * rax original destination
29886 */
29887- .section .altinstr_replacement, "ax", @progbits
29888+ .section .altinstr_replacement, "a", @progbits
29889 .Lmemset_c_e:
29890 movq %rdi,%r9
29891 movb %sil,%al
29892 movq %rdx,%rcx
29893 rep stosb
29894 movq %r9,%rax
29895+ pax_force_retaddr
29896 ret
29897 .Lmemset_e_e:
29898 .previous
29899@@ -118,6 +120,7 @@ ENTRY(__memset)
29900
29901 .Lende:
29902 movq %r10,%rax
29903+ pax_force_retaddr
29904 ret
29905
29906 CFI_RESTORE_STATE
29907diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29908index c9f2d9b..e7fd2c0 100644
29909--- a/arch/x86/lib/mmx_32.c
29910+++ b/arch/x86/lib/mmx_32.c
29911@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29912 {
29913 void *p;
29914 int i;
29915+ unsigned long cr0;
29916
29917 if (unlikely(in_interrupt()))
29918 return __memcpy(to, from, len);
29919@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29920 kernel_fpu_begin();
29921
29922 __asm__ __volatile__ (
29923- "1: prefetch (%0)\n" /* This set is 28 bytes */
29924- " prefetch 64(%0)\n"
29925- " prefetch 128(%0)\n"
29926- " prefetch 192(%0)\n"
29927- " prefetch 256(%0)\n"
29928+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29929+ " prefetch 64(%1)\n"
29930+ " prefetch 128(%1)\n"
29931+ " prefetch 192(%1)\n"
29932+ " prefetch 256(%1)\n"
29933 "2: \n"
29934 ".section .fixup, \"ax\"\n"
29935- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29936+ "3: \n"
29937+
29938+#ifdef CONFIG_PAX_KERNEXEC
29939+ " movl %%cr0, %0\n"
29940+ " movl %0, %%eax\n"
29941+ " andl $0xFFFEFFFF, %%eax\n"
29942+ " movl %%eax, %%cr0\n"
29943+#endif
29944+
29945+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29946+
29947+#ifdef CONFIG_PAX_KERNEXEC
29948+ " movl %0, %%cr0\n"
29949+#endif
29950+
29951 " jmp 2b\n"
29952 ".previous\n"
29953 _ASM_EXTABLE(1b, 3b)
29954- : : "r" (from));
29955+ : "=&r" (cr0) : "r" (from) : "ax");
29956
29957 for ( ; i > 5; i--) {
29958 __asm__ __volatile__ (
29959- "1: prefetch 320(%0)\n"
29960- "2: movq (%0), %%mm0\n"
29961- " movq 8(%0), %%mm1\n"
29962- " movq 16(%0), %%mm2\n"
29963- " movq 24(%0), %%mm3\n"
29964- " movq %%mm0, (%1)\n"
29965- " movq %%mm1, 8(%1)\n"
29966- " movq %%mm2, 16(%1)\n"
29967- " movq %%mm3, 24(%1)\n"
29968- " movq 32(%0), %%mm0\n"
29969- " movq 40(%0), %%mm1\n"
29970- " movq 48(%0), %%mm2\n"
29971- " movq 56(%0), %%mm3\n"
29972- " movq %%mm0, 32(%1)\n"
29973- " movq %%mm1, 40(%1)\n"
29974- " movq %%mm2, 48(%1)\n"
29975- " movq %%mm3, 56(%1)\n"
29976+ "1: prefetch 320(%1)\n"
29977+ "2: movq (%1), %%mm0\n"
29978+ " movq 8(%1), %%mm1\n"
29979+ " movq 16(%1), %%mm2\n"
29980+ " movq 24(%1), %%mm3\n"
29981+ " movq %%mm0, (%2)\n"
29982+ " movq %%mm1, 8(%2)\n"
29983+ " movq %%mm2, 16(%2)\n"
29984+ " movq %%mm3, 24(%2)\n"
29985+ " movq 32(%1), %%mm0\n"
29986+ " movq 40(%1), %%mm1\n"
29987+ " movq 48(%1), %%mm2\n"
29988+ " movq 56(%1), %%mm3\n"
29989+ " movq %%mm0, 32(%2)\n"
29990+ " movq %%mm1, 40(%2)\n"
29991+ " movq %%mm2, 48(%2)\n"
29992+ " movq %%mm3, 56(%2)\n"
29993 ".section .fixup, \"ax\"\n"
29994- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29995+ "3:\n"
29996+
29997+#ifdef CONFIG_PAX_KERNEXEC
29998+ " movl %%cr0, %0\n"
29999+ " movl %0, %%eax\n"
30000+ " andl $0xFFFEFFFF, %%eax\n"
30001+ " movl %%eax, %%cr0\n"
30002+#endif
30003+
30004+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30005+
30006+#ifdef CONFIG_PAX_KERNEXEC
30007+ " movl %0, %%cr0\n"
30008+#endif
30009+
30010 " jmp 2b\n"
30011 ".previous\n"
30012 _ASM_EXTABLE(1b, 3b)
30013- : : "r" (from), "r" (to) : "memory");
30014+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30015
30016 from += 64;
30017 to += 64;
30018@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30019 static void fast_copy_page(void *to, void *from)
30020 {
30021 int i;
30022+ unsigned long cr0;
30023
30024 kernel_fpu_begin();
30025
30026@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30027 * but that is for later. -AV
30028 */
30029 __asm__ __volatile__(
30030- "1: prefetch (%0)\n"
30031- " prefetch 64(%0)\n"
30032- " prefetch 128(%0)\n"
30033- " prefetch 192(%0)\n"
30034- " prefetch 256(%0)\n"
30035+ "1: prefetch (%1)\n"
30036+ " prefetch 64(%1)\n"
30037+ " prefetch 128(%1)\n"
30038+ " prefetch 192(%1)\n"
30039+ " prefetch 256(%1)\n"
30040 "2: \n"
30041 ".section .fixup, \"ax\"\n"
30042- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30043+ "3: \n"
30044+
30045+#ifdef CONFIG_PAX_KERNEXEC
30046+ " movl %%cr0, %0\n"
30047+ " movl %0, %%eax\n"
30048+ " andl $0xFFFEFFFF, %%eax\n"
30049+ " movl %%eax, %%cr0\n"
30050+#endif
30051+
30052+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30053+
30054+#ifdef CONFIG_PAX_KERNEXEC
30055+ " movl %0, %%cr0\n"
30056+#endif
30057+
30058 " jmp 2b\n"
30059 ".previous\n"
30060- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30061+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30062
30063 for (i = 0; i < (4096-320)/64; i++) {
30064 __asm__ __volatile__ (
30065- "1: prefetch 320(%0)\n"
30066- "2: movq (%0), %%mm0\n"
30067- " movntq %%mm0, (%1)\n"
30068- " movq 8(%0), %%mm1\n"
30069- " movntq %%mm1, 8(%1)\n"
30070- " movq 16(%0), %%mm2\n"
30071- " movntq %%mm2, 16(%1)\n"
30072- " movq 24(%0), %%mm3\n"
30073- " movntq %%mm3, 24(%1)\n"
30074- " movq 32(%0), %%mm4\n"
30075- " movntq %%mm4, 32(%1)\n"
30076- " movq 40(%0), %%mm5\n"
30077- " movntq %%mm5, 40(%1)\n"
30078- " movq 48(%0), %%mm6\n"
30079- " movntq %%mm6, 48(%1)\n"
30080- " movq 56(%0), %%mm7\n"
30081- " movntq %%mm7, 56(%1)\n"
30082+ "1: prefetch 320(%1)\n"
30083+ "2: movq (%1), %%mm0\n"
30084+ " movntq %%mm0, (%2)\n"
30085+ " movq 8(%1), %%mm1\n"
30086+ " movntq %%mm1, 8(%2)\n"
30087+ " movq 16(%1), %%mm2\n"
30088+ " movntq %%mm2, 16(%2)\n"
30089+ " movq 24(%1), %%mm3\n"
30090+ " movntq %%mm3, 24(%2)\n"
30091+ " movq 32(%1), %%mm4\n"
30092+ " movntq %%mm4, 32(%2)\n"
30093+ " movq 40(%1), %%mm5\n"
30094+ " movntq %%mm5, 40(%2)\n"
30095+ " movq 48(%1), %%mm6\n"
30096+ " movntq %%mm6, 48(%2)\n"
30097+ " movq 56(%1), %%mm7\n"
30098+ " movntq %%mm7, 56(%2)\n"
30099 ".section .fixup, \"ax\"\n"
30100- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30101+ "3:\n"
30102+
30103+#ifdef CONFIG_PAX_KERNEXEC
30104+ " movl %%cr0, %0\n"
30105+ " movl %0, %%eax\n"
30106+ " andl $0xFFFEFFFF, %%eax\n"
30107+ " movl %%eax, %%cr0\n"
30108+#endif
30109+
30110+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30111+
30112+#ifdef CONFIG_PAX_KERNEXEC
30113+ " movl %0, %%cr0\n"
30114+#endif
30115+
30116 " jmp 2b\n"
30117 ".previous\n"
30118- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30119+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30120
30121 from += 64;
30122 to += 64;
30123@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30124 static void fast_copy_page(void *to, void *from)
30125 {
30126 int i;
30127+ unsigned long cr0;
30128
30129 kernel_fpu_begin();
30130
30131 __asm__ __volatile__ (
30132- "1: prefetch (%0)\n"
30133- " prefetch 64(%0)\n"
30134- " prefetch 128(%0)\n"
30135- " prefetch 192(%0)\n"
30136- " prefetch 256(%0)\n"
30137+ "1: prefetch (%1)\n"
30138+ " prefetch 64(%1)\n"
30139+ " prefetch 128(%1)\n"
30140+ " prefetch 192(%1)\n"
30141+ " prefetch 256(%1)\n"
30142 "2: \n"
30143 ".section .fixup, \"ax\"\n"
30144- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30145+ "3: \n"
30146+
30147+#ifdef CONFIG_PAX_KERNEXEC
30148+ " movl %%cr0, %0\n"
30149+ " movl %0, %%eax\n"
30150+ " andl $0xFFFEFFFF, %%eax\n"
30151+ " movl %%eax, %%cr0\n"
30152+#endif
30153+
30154+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30155+
30156+#ifdef CONFIG_PAX_KERNEXEC
30157+ " movl %0, %%cr0\n"
30158+#endif
30159+
30160 " jmp 2b\n"
30161 ".previous\n"
30162- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30163+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30164
30165 for (i = 0; i < 4096/64; i++) {
30166 __asm__ __volatile__ (
30167- "1: prefetch 320(%0)\n"
30168- "2: movq (%0), %%mm0\n"
30169- " movq 8(%0), %%mm1\n"
30170- " movq 16(%0), %%mm2\n"
30171- " movq 24(%0), %%mm3\n"
30172- " movq %%mm0, (%1)\n"
30173- " movq %%mm1, 8(%1)\n"
30174- " movq %%mm2, 16(%1)\n"
30175- " movq %%mm3, 24(%1)\n"
30176- " movq 32(%0), %%mm0\n"
30177- " movq 40(%0), %%mm1\n"
30178- " movq 48(%0), %%mm2\n"
30179- " movq 56(%0), %%mm3\n"
30180- " movq %%mm0, 32(%1)\n"
30181- " movq %%mm1, 40(%1)\n"
30182- " movq %%mm2, 48(%1)\n"
30183- " movq %%mm3, 56(%1)\n"
30184+ "1: prefetch 320(%1)\n"
30185+ "2: movq (%1), %%mm0\n"
30186+ " movq 8(%1), %%mm1\n"
30187+ " movq 16(%1), %%mm2\n"
30188+ " movq 24(%1), %%mm3\n"
30189+ " movq %%mm0, (%2)\n"
30190+ " movq %%mm1, 8(%2)\n"
30191+ " movq %%mm2, 16(%2)\n"
30192+ " movq %%mm3, 24(%2)\n"
30193+ " movq 32(%1), %%mm0\n"
30194+ " movq 40(%1), %%mm1\n"
30195+ " movq 48(%1), %%mm2\n"
30196+ " movq 56(%1), %%mm3\n"
30197+ " movq %%mm0, 32(%2)\n"
30198+ " movq %%mm1, 40(%2)\n"
30199+ " movq %%mm2, 48(%2)\n"
30200+ " movq %%mm3, 56(%2)\n"
30201 ".section .fixup, \"ax\"\n"
30202- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30203+ "3:\n"
30204+
30205+#ifdef CONFIG_PAX_KERNEXEC
30206+ " movl %%cr0, %0\n"
30207+ " movl %0, %%eax\n"
30208+ " andl $0xFFFEFFFF, %%eax\n"
30209+ " movl %%eax, %%cr0\n"
30210+#endif
30211+
30212+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30213+
30214+#ifdef CONFIG_PAX_KERNEXEC
30215+ " movl %0, %%cr0\n"
30216+#endif
30217+
30218 " jmp 2b\n"
30219 ".previous\n"
30220 _ASM_EXTABLE(1b, 3b)
30221- : : "r" (from), "r" (to) : "memory");
30222+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30223
30224 from += 64;
30225 to += 64;
30226diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30227index f6d13ee..d789440 100644
30228--- a/arch/x86/lib/msr-reg.S
30229+++ b/arch/x86/lib/msr-reg.S
30230@@ -3,6 +3,7 @@
30231 #include <asm/dwarf2.h>
30232 #include <asm/asm.h>
30233 #include <asm/msr.h>
30234+#include <asm/alternative-asm.h>
30235
30236 #ifdef CONFIG_X86_64
30237 /*
30238@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30239 movl %edi, 28(%r10)
30240 popq_cfi %rbp
30241 popq_cfi %rbx
30242+ pax_force_retaddr
30243 ret
30244 3:
30245 CFI_RESTORE_STATE
30246diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30247index fc6ba17..d4d989d 100644
30248--- a/arch/x86/lib/putuser.S
30249+++ b/arch/x86/lib/putuser.S
30250@@ -16,7 +16,9 @@
30251 #include <asm/errno.h>
30252 #include <asm/asm.h>
30253 #include <asm/smap.h>
30254-
30255+#include <asm/segment.h>
30256+#include <asm/pgtable.h>
30257+#include <asm/alternative-asm.h>
30258
30259 /*
30260 * __put_user_X
30261@@ -30,57 +32,125 @@
30262 * as they get called from within inline assembly.
30263 */
30264
30265-#define ENTER CFI_STARTPROC ; \
30266- GET_THREAD_INFO(%_ASM_BX)
30267-#define EXIT ASM_CLAC ; \
30268- ret ; \
30269+#define ENTER CFI_STARTPROC
30270+#define EXIT ASM_CLAC ; \
30271+ pax_force_retaddr ; \
30272+ ret ; \
30273 CFI_ENDPROC
30274
30275+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30276+#define _DEST %_ASM_CX,%_ASM_BX
30277+#else
30278+#define _DEST %_ASM_CX
30279+#endif
30280+
30281+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30282+#define __copyuser_seg gs;
30283+#else
30284+#define __copyuser_seg
30285+#endif
30286+
30287 .text
30288 ENTRY(__put_user_1)
30289 ENTER
30290+
30291+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30292+ GET_THREAD_INFO(%_ASM_BX)
30293 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30294 jae bad_put_user
30295 ASM_STAC
30296-1: movb %al,(%_ASM_CX)
30297+
30298+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30299+ mov pax_user_shadow_base,%_ASM_BX
30300+ cmp %_ASM_BX,%_ASM_CX
30301+ jb 1234f
30302+ xor %ebx,%ebx
30303+1234:
30304+#endif
30305+
30306+#endif
30307+
30308+1: __copyuser_seg movb %al,(_DEST)
30309 xor %eax,%eax
30310 EXIT
30311 ENDPROC(__put_user_1)
30312
30313 ENTRY(__put_user_2)
30314 ENTER
30315+
30316+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30317+ GET_THREAD_INFO(%_ASM_BX)
30318 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30319 sub $1,%_ASM_BX
30320 cmp %_ASM_BX,%_ASM_CX
30321 jae bad_put_user
30322 ASM_STAC
30323-2: movw %ax,(%_ASM_CX)
30324+
30325+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30326+ mov pax_user_shadow_base,%_ASM_BX
30327+ cmp %_ASM_BX,%_ASM_CX
30328+ jb 1234f
30329+ xor %ebx,%ebx
30330+1234:
30331+#endif
30332+
30333+#endif
30334+
30335+2: __copyuser_seg movw %ax,(_DEST)
30336 xor %eax,%eax
30337 EXIT
30338 ENDPROC(__put_user_2)
30339
30340 ENTRY(__put_user_4)
30341 ENTER
30342+
30343+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30344+ GET_THREAD_INFO(%_ASM_BX)
30345 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30346 sub $3,%_ASM_BX
30347 cmp %_ASM_BX,%_ASM_CX
30348 jae bad_put_user
30349 ASM_STAC
30350-3: movl %eax,(%_ASM_CX)
30351+
30352+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30353+ mov pax_user_shadow_base,%_ASM_BX
30354+ cmp %_ASM_BX,%_ASM_CX
30355+ jb 1234f
30356+ xor %ebx,%ebx
30357+1234:
30358+#endif
30359+
30360+#endif
30361+
30362+3: __copyuser_seg movl %eax,(_DEST)
30363 xor %eax,%eax
30364 EXIT
30365 ENDPROC(__put_user_4)
30366
30367 ENTRY(__put_user_8)
30368 ENTER
30369+
30370+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30371+ GET_THREAD_INFO(%_ASM_BX)
30372 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30373 sub $7,%_ASM_BX
30374 cmp %_ASM_BX,%_ASM_CX
30375 jae bad_put_user
30376 ASM_STAC
30377-4: mov %_ASM_AX,(%_ASM_CX)
30378+
30379+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30380+ mov pax_user_shadow_base,%_ASM_BX
30381+ cmp %_ASM_BX,%_ASM_CX
30382+ jb 1234f
30383+ xor %ebx,%ebx
30384+1234:
30385+#endif
30386+
30387+#endif
30388+
30389+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30390 #ifdef CONFIG_X86_32
30391-5: movl %edx,4(%_ASM_CX)
30392+5: __copyuser_seg movl %edx,4(_DEST)
30393 #endif
30394 xor %eax,%eax
30395 EXIT
30396diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30397index 1cad221..de671ee 100644
30398--- a/arch/x86/lib/rwlock.S
30399+++ b/arch/x86/lib/rwlock.S
30400@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30401 FRAME
30402 0: LOCK_PREFIX
30403 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30404+
30405+#ifdef CONFIG_PAX_REFCOUNT
30406+ jno 1234f
30407+ LOCK_PREFIX
30408+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30409+ int $4
30410+1234:
30411+ _ASM_EXTABLE(1234b, 1234b)
30412+#endif
30413+
30414 1: rep; nop
30415 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30416 jne 1b
30417 LOCK_PREFIX
30418 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30419+
30420+#ifdef CONFIG_PAX_REFCOUNT
30421+ jno 1234f
30422+ LOCK_PREFIX
30423+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30424+ int $4
30425+1234:
30426+ _ASM_EXTABLE(1234b, 1234b)
30427+#endif
30428+
30429 jnz 0b
30430 ENDFRAME
30431+ pax_force_retaddr
30432 ret
30433 CFI_ENDPROC
30434 END(__write_lock_failed)
30435@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30436 FRAME
30437 0: LOCK_PREFIX
30438 READ_LOCK_SIZE(inc) (%__lock_ptr)
30439+
30440+#ifdef CONFIG_PAX_REFCOUNT
30441+ jno 1234f
30442+ LOCK_PREFIX
30443+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30444+ int $4
30445+1234:
30446+ _ASM_EXTABLE(1234b, 1234b)
30447+#endif
30448+
30449 1: rep; nop
30450 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30451 js 1b
30452 LOCK_PREFIX
30453 READ_LOCK_SIZE(dec) (%__lock_ptr)
30454+
30455+#ifdef CONFIG_PAX_REFCOUNT
30456+ jno 1234f
30457+ LOCK_PREFIX
30458+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30459+ int $4
30460+1234:
30461+ _ASM_EXTABLE(1234b, 1234b)
30462+#endif
30463+
30464 js 0b
30465 ENDFRAME
30466+ pax_force_retaddr
30467 ret
30468 CFI_ENDPROC
30469 END(__read_lock_failed)
30470diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30471index 5dff5f0..cadebf4 100644
30472--- a/arch/x86/lib/rwsem.S
30473+++ b/arch/x86/lib/rwsem.S
30474@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30475 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30476 CFI_RESTORE __ASM_REG(dx)
30477 restore_common_regs
30478+ pax_force_retaddr
30479 ret
30480 CFI_ENDPROC
30481 ENDPROC(call_rwsem_down_read_failed)
30482@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30483 movq %rax,%rdi
30484 call rwsem_down_write_failed
30485 restore_common_regs
30486+ pax_force_retaddr
30487 ret
30488 CFI_ENDPROC
30489 ENDPROC(call_rwsem_down_write_failed)
30490@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30491 movq %rax,%rdi
30492 call rwsem_wake
30493 restore_common_regs
30494-1: ret
30495+1: pax_force_retaddr
30496+ ret
30497 CFI_ENDPROC
30498 ENDPROC(call_rwsem_wake)
30499
30500@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30501 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30502 CFI_RESTORE __ASM_REG(dx)
30503 restore_common_regs
30504+ pax_force_retaddr
30505 ret
30506 CFI_ENDPROC
30507 ENDPROC(call_rwsem_downgrade_wake)
30508diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30509index a63efd6..8149fbe 100644
30510--- a/arch/x86/lib/thunk_64.S
30511+++ b/arch/x86/lib/thunk_64.S
30512@@ -8,6 +8,7 @@
30513 #include <linux/linkage.h>
30514 #include <asm/dwarf2.h>
30515 #include <asm/calling.h>
30516+#include <asm/alternative-asm.h>
30517
30518 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30519 .macro THUNK name, func, put_ret_addr_in_rdi=0
30520@@ -15,11 +16,11 @@
30521 \name:
30522 CFI_STARTPROC
30523
30524- /* this one pushes 9 elems, the next one would be %rIP */
30525- SAVE_ARGS
30526+ /* this one pushes 15+1 elems, the next one would be %rIP */
30527+ SAVE_ARGS 8
30528
30529 .if \put_ret_addr_in_rdi
30530- movq_cfi_restore 9*8, rdi
30531+ movq_cfi_restore RIP, rdi
30532 .endif
30533
30534 call \func
30535@@ -38,8 +39,9 @@
30536
30537 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30538 CFI_STARTPROC
30539- SAVE_ARGS
30540+ SAVE_ARGS 8
30541 restore:
30542- RESTORE_ARGS
30543+ RESTORE_ARGS 1,8
30544+ pax_force_retaddr
30545 ret
30546 CFI_ENDPROC
30547diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30548index e2f5e21..4b22130 100644
30549--- a/arch/x86/lib/usercopy_32.c
30550+++ b/arch/x86/lib/usercopy_32.c
30551@@ -42,11 +42,13 @@ do { \
30552 int __d0; \
30553 might_fault(); \
30554 __asm__ __volatile__( \
30555+ __COPYUSER_SET_ES \
30556 ASM_STAC "\n" \
30557 "0: rep; stosl\n" \
30558 " movl %2,%0\n" \
30559 "1: rep; stosb\n" \
30560 "2: " ASM_CLAC "\n" \
30561+ __COPYUSER_RESTORE_ES \
30562 ".section .fixup,\"ax\"\n" \
30563 "3: lea 0(%2,%0,4),%0\n" \
30564 " jmp 2b\n" \
30565@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30566
30567 #ifdef CONFIG_X86_INTEL_USERCOPY
30568 static unsigned long
30569-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30570+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30571 {
30572 int d0, d1;
30573 __asm__ __volatile__(
30574@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30575 " .align 2,0x90\n"
30576 "3: movl 0(%4), %%eax\n"
30577 "4: movl 4(%4), %%edx\n"
30578- "5: movl %%eax, 0(%3)\n"
30579- "6: movl %%edx, 4(%3)\n"
30580+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30581+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30582 "7: movl 8(%4), %%eax\n"
30583 "8: movl 12(%4),%%edx\n"
30584- "9: movl %%eax, 8(%3)\n"
30585- "10: movl %%edx, 12(%3)\n"
30586+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30587+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30588 "11: movl 16(%4), %%eax\n"
30589 "12: movl 20(%4), %%edx\n"
30590- "13: movl %%eax, 16(%3)\n"
30591- "14: movl %%edx, 20(%3)\n"
30592+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30593+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30594 "15: movl 24(%4), %%eax\n"
30595 "16: movl 28(%4), %%edx\n"
30596- "17: movl %%eax, 24(%3)\n"
30597- "18: movl %%edx, 28(%3)\n"
30598+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30599+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30600 "19: movl 32(%4), %%eax\n"
30601 "20: movl 36(%4), %%edx\n"
30602- "21: movl %%eax, 32(%3)\n"
30603- "22: movl %%edx, 36(%3)\n"
30604+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30605+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30606 "23: movl 40(%4), %%eax\n"
30607 "24: movl 44(%4), %%edx\n"
30608- "25: movl %%eax, 40(%3)\n"
30609- "26: movl %%edx, 44(%3)\n"
30610+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30611+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30612 "27: movl 48(%4), %%eax\n"
30613 "28: movl 52(%4), %%edx\n"
30614- "29: movl %%eax, 48(%3)\n"
30615- "30: movl %%edx, 52(%3)\n"
30616+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30617+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30618 "31: movl 56(%4), %%eax\n"
30619 "32: movl 60(%4), %%edx\n"
30620- "33: movl %%eax, 56(%3)\n"
30621- "34: movl %%edx, 60(%3)\n"
30622+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30623+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30624 " addl $-64, %0\n"
30625 " addl $64, %4\n"
30626 " addl $64, %3\n"
30627@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30628 " shrl $2, %0\n"
30629 " andl $3, %%eax\n"
30630 " cld\n"
30631+ __COPYUSER_SET_ES
30632 "99: rep; movsl\n"
30633 "36: movl %%eax, %0\n"
30634 "37: rep; movsb\n"
30635 "100:\n"
30636+ __COPYUSER_RESTORE_ES
30637+ ".section .fixup,\"ax\"\n"
30638+ "101: lea 0(%%eax,%0,4),%0\n"
30639+ " jmp 100b\n"
30640+ ".previous\n"
30641+ _ASM_EXTABLE(1b,100b)
30642+ _ASM_EXTABLE(2b,100b)
30643+ _ASM_EXTABLE(3b,100b)
30644+ _ASM_EXTABLE(4b,100b)
30645+ _ASM_EXTABLE(5b,100b)
30646+ _ASM_EXTABLE(6b,100b)
30647+ _ASM_EXTABLE(7b,100b)
30648+ _ASM_EXTABLE(8b,100b)
30649+ _ASM_EXTABLE(9b,100b)
30650+ _ASM_EXTABLE(10b,100b)
30651+ _ASM_EXTABLE(11b,100b)
30652+ _ASM_EXTABLE(12b,100b)
30653+ _ASM_EXTABLE(13b,100b)
30654+ _ASM_EXTABLE(14b,100b)
30655+ _ASM_EXTABLE(15b,100b)
30656+ _ASM_EXTABLE(16b,100b)
30657+ _ASM_EXTABLE(17b,100b)
30658+ _ASM_EXTABLE(18b,100b)
30659+ _ASM_EXTABLE(19b,100b)
30660+ _ASM_EXTABLE(20b,100b)
30661+ _ASM_EXTABLE(21b,100b)
30662+ _ASM_EXTABLE(22b,100b)
30663+ _ASM_EXTABLE(23b,100b)
30664+ _ASM_EXTABLE(24b,100b)
30665+ _ASM_EXTABLE(25b,100b)
30666+ _ASM_EXTABLE(26b,100b)
30667+ _ASM_EXTABLE(27b,100b)
30668+ _ASM_EXTABLE(28b,100b)
30669+ _ASM_EXTABLE(29b,100b)
30670+ _ASM_EXTABLE(30b,100b)
30671+ _ASM_EXTABLE(31b,100b)
30672+ _ASM_EXTABLE(32b,100b)
30673+ _ASM_EXTABLE(33b,100b)
30674+ _ASM_EXTABLE(34b,100b)
30675+ _ASM_EXTABLE(35b,100b)
30676+ _ASM_EXTABLE(36b,100b)
30677+ _ASM_EXTABLE(37b,100b)
30678+ _ASM_EXTABLE(99b,101b)
30679+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30680+ : "1"(to), "2"(from), "0"(size)
30681+ : "eax", "edx", "memory");
30682+ return size;
30683+}
30684+
30685+static unsigned long
30686+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30687+{
30688+ int d0, d1;
30689+ __asm__ __volatile__(
30690+ " .align 2,0x90\n"
30691+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30692+ " cmpl $67, %0\n"
30693+ " jbe 3f\n"
30694+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30695+ " .align 2,0x90\n"
30696+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30697+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30698+ "5: movl %%eax, 0(%3)\n"
30699+ "6: movl %%edx, 4(%3)\n"
30700+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30701+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30702+ "9: movl %%eax, 8(%3)\n"
30703+ "10: movl %%edx, 12(%3)\n"
30704+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30705+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30706+ "13: movl %%eax, 16(%3)\n"
30707+ "14: movl %%edx, 20(%3)\n"
30708+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30709+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30710+ "17: movl %%eax, 24(%3)\n"
30711+ "18: movl %%edx, 28(%3)\n"
30712+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30713+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30714+ "21: movl %%eax, 32(%3)\n"
30715+ "22: movl %%edx, 36(%3)\n"
30716+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30717+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30718+ "25: movl %%eax, 40(%3)\n"
30719+ "26: movl %%edx, 44(%3)\n"
30720+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30721+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30722+ "29: movl %%eax, 48(%3)\n"
30723+ "30: movl %%edx, 52(%3)\n"
30724+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30725+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30726+ "33: movl %%eax, 56(%3)\n"
30727+ "34: movl %%edx, 60(%3)\n"
30728+ " addl $-64, %0\n"
30729+ " addl $64, %4\n"
30730+ " addl $64, %3\n"
30731+ " cmpl $63, %0\n"
30732+ " ja 1b\n"
30733+ "35: movl %0, %%eax\n"
30734+ " shrl $2, %0\n"
30735+ " andl $3, %%eax\n"
30736+ " cld\n"
30737+ "99: rep; "__copyuser_seg" movsl\n"
30738+ "36: movl %%eax, %0\n"
30739+ "37: rep; "__copyuser_seg" movsb\n"
30740+ "100:\n"
30741 ".section .fixup,\"ax\"\n"
30742 "101: lea 0(%%eax,%0,4),%0\n"
30743 " jmp 100b\n"
30744@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30745 int d0, d1;
30746 __asm__ __volatile__(
30747 " .align 2,0x90\n"
30748- "0: movl 32(%4), %%eax\n"
30749+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30750 " cmpl $67, %0\n"
30751 " jbe 2f\n"
30752- "1: movl 64(%4), %%eax\n"
30753+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30754 " .align 2,0x90\n"
30755- "2: movl 0(%4), %%eax\n"
30756- "21: movl 4(%4), %%edx\n"
30757+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30758+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30759 " movl %%eax, 0(%3)\n"
30760 " movl %%edx, 4(%3)\n"
30761- "3: movl 8(%4), %%eax\n"
30762- "31: movl 12(%4),%%edx\n"
30763+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30764+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30765 " movl %%eax, 8(%3)\n"
30766 " movl %%edx, 12(%3)\n"
30767- "4: movl 16(%4), %%eax\n"
30768- "41: movl 20(%4), %%edx\n"
30769+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30770+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30771 " movl %%eax, 16(%3)\n"
30772 " movl %%edx, 20(%3)\n"
30773- "10: movl 24(%4), %%eax\n"
30774- "51: movl 28(%4), %%edx\n"
30775+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30776+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30777 " movl %%eax, 24(%3)\n"
30778 " movl %%edx, 28(%3)\n"
30779- "11: movl 32(%4), %%eax\n"
30780- "61: movl 36(%4), %%edx\n"
30781+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30782+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30783 " movl %%eax, 32(%3)\n"
30784 " movl %%edx, 36(%3)\n"
30785- "12: movl 40(%4), %%eax\n"
30786- "71: movl 44(%4), %%edx\n"
30787+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30788+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30789 " movl %%eax, 40(%3)\n"
30790 " movl %%edx, 44(%3)\n"
30791- "13: movl 48(%4), %%eax\n"
30792- "81: movl 52(%4), %%edx\n"
30793+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30794+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30795 " movl %%eax, 48(%3)\n"
30796 " movl %%edx, 52(%3)\n"
30797- "14: movl 56(%4), %%eax\n"
30798- "91: movl 60(%4), %%edx\n"
30799+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30800+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30801 " movl %%eax, 56(%3)\n"
30802 " movl %%edx, 60(%3)\n"
30803 " addl $-64, %0\n"
30804@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30805 " shrl $2, %0\n"
30806 " andl $3, %%eax\n"
30807 " cld\n"
30808- "6: rep; movsl\n"
30809+ "6: rep; "__copyuser_seg" movsl\n"
30810 " movl %%eax,%0\n"
30811- "7: rep; movsb\n"
30812+ "7: rep; "__copyuser_seg" movsb\n"
30813 "8:\n"
30814 ".section .fixup,\"ax\"\n"
30815 "9: lea 0(%%eax,%0,4),%0\n"
30816@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30817
30818 __asm__ __volatile__(
30819 " .align 2,0x90\n"
30820- "0: movl 32(%4), %%eax\n"
30821+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30822 " cmpl $67, %0\n"
30823 " jbe 2f\n"
30824- "1: movl 64(%4), %%eax\n"
30825+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30826 " .align 2,0x90\n"
30827- "2: movl 0(%4), %%eax\n"
30828- "21: movl 4(%4), %%edx\n"
30829+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30830+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30831 " movnti %%eax, 0(%3)\n"
30832 " movnti %%edx, 4(%3)\n"
30833- "3: movl 8(%4), %%eax\n"
30834- "31: movl 12(%4),%%edx\n"
30835+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30836+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30837 " movnti %%eax, 8(%3)\n"
30838 " movnti %%edx, 12(%3)\n"
30839- "4: movl 16(%4), %%eax\n"
30840- "41: movl 20(%4), %%edx\n"
30841+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30842+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30843 " movnti %%eax, 16(%3)\n"
30844 " movnti %%edx, 20(%3)\n"
30845- "10: movl 24(%4), %%eax\n"
30846- "51: movl 28(%4), %%edx\n"
30847+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30848+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30849 " movnti %%eax, 24(%3)\n"
30850 " movnti %%edx, 28(%3)\n"
30851- "11: movl 32(%4), %%eax\n"
30852- "61: movl 36(%4), %%edx\n"
30853+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30854+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30855 " movnti %%eax, 32(%3)\n"
30856 " movnti %%edx, 36(%3)\n"
30857- "12: movl 40(%4), %%eax\n"
30858- "71: movl 44(%4), %%edx\n"
30859+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30860+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30861 " movnti %%eax, 40(%3)\n"
30862 " movnti %%edx, 44(%3)\n"
30863- "13: movl 48(%4), %%eax\n"
30864- "81: movl 52(%4), %%edx\n"
30865+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30866+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30867 " movnti %%eax, 48(%3)\n"
30868 " movnti %%edx, 52(%3)\n"
30869- "14: movl 56(%4), %%eax\n"
30870- "91: movl 60(%4), %%edx\n"
30871+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30872+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30873 " movnti %%eax, 56(%3)\n"
30874 " movnti %%edx, 60(%3)\n"
30875 " addl $-64, %0\n"
30876@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30877 " shrl $2, %0\n"
30878 " andl $3, %%eax\n"
30879 " cld\n"
30880- "6: rep; movsl\n"
30881+ "6: rep; "__copyuser_seg" movsl\n"
30882 " movl %%eax,%0\n"
30883- "7: rep; movsb\n"
30884+ "7: rep; "__copyuser_seg" movsb\n"
30885 "8:\n"
30886 ".section .fixup,\"ax\"\n"
30887 "9: lea 0(%%eax,%0,4),%0\n"
30888@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30889
30890 __asm__ __volatile__(
30891 " .align 2,0x90\n"
30892- "0: movl 32(%4), %%eax\n"
30893+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30894 " cmpl $67, %0\n"
30895 " jbe 2f\n"
30896- "1: movl 64(%4), %%eax\n"
30897+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30898 " .align 2,0x90\n"
30899- "2: movl 0(%4), %%eax\n"
30900- "21: movl 4(%4), %%edx\n"
30901+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30902+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30903 " movnti %%eax, 0(%3)\n"
30904 " movnti %%edx, 4(%3)\n"
30905- "3: movl 8(%4), %%eax\n"
30906- "31: movl 12(%4),%%edx\n"
30907+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30908+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30909 " movnti %%eax, 8(%3)\n"
30910 " movnti %%edx, 12(%3)\n"
30911- "4: movl 16(%4), %%eax\n"
30912- "41: movl 20(%4), %%edx\n"
30913+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30914+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30915 " movnti %%eax, 16(%3)\n"
30916 " movnti %%edx, 20(%3)\n"
30917- "10: movl 24(%4), %%eax\n"
30918- "51: movl 28(%4), %%edx\n"
30919+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30920+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30921 " movnti %%eax, 24(%3)\n"
30922 " movnti %%edx, 28(%3)\n"
30923- "11: movl 32(%4), %%eax\n"
30924- "61: movl 36(%4), %%edx\n"
30925+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30926+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30927 " movnti %%eax, 32(%3)\n"
30928 " movnti %%edx, 36(%3)\n"
30929- "12: movl 40(%4), %%eax\n"
30930- "71: movl 44(%4), %%edx\n"
30931+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30932+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30933 " movnti %%eax, 40(%3)\n"
30934 " movnti %%edx, 44(%3)\n"
30935- "13: movl 48(%4), %%eax\n"
30936- "81: movl 52(%4), %%edx\n"
30937+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30938+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30939 " movnti %%eax, 48(%3)\n"
30940 " movnti %%edx, 52(%3)\n"
30941- "14: movl 56(%4), %%eax\n"
30942- "91: movl 60(%4), %%edx\n"
30943+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30944+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30945 " movnti %%eax, 56(%3)\n"
30946 " movnti %%edx, 60(%3)\n"
30947 " addl $-64, %0\n"
30948@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30949 " shrl $2, %0\n"
30950 " andl $3, %%eax\n"
30951 " cld\n"
30952- "6: rep; movsl\n"
30953+ "6: rep; "__copyuser_seg" movsl\n"
30954 " movl %%eax,%0\n"
30955- "7: rep; movsb\n"
30956+ "7: rep; "__copyuser_seg" movsb\n"
30957 "8:\n"
30958 ".section .fixup,\"ax\"\n"
30959 "9: lea 0(%%eax,%0,4),%0\n"
30960@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30961 */
30962 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30963 unsigned long size);
30964-unsigned long __copy_user_intel(void __user *to, const void *from,
30965+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30966+ unsigned long size);
30967+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30968 unsigned long size);
30969 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30970 const void __user *from, unsigned long size);
30971 #endif /* CONFIG_X86_INTEL_USERCOPY */
30972
30973 /* Generic arbitrary sized copy. */
30974-#define __copy_user(to, from, size) \
30975+#define __copy_user(to, from, size, prefix, set, restore) \
30976 do { \
30977 int __d0, __d1, __d2; \
30978 __asm__ __volatile__( \
30979+ set \
30980 " cmp $7,%0\n" \
30981 " jbe 1f\n" \
30982 " movl %1,%0\n" \
30983 " negl %0\n" \
30984 " andl $7,%0\n" \
30985 " subl %0,%3\n" \
30986- "4: rep; movsb\n" \
30987+ "4: rep; "prefix"movsb\n" \
30988 " movl %3,%0\n" \
30989 " shrl $2,%0\n" \
30990 " andl $3,%3\n" \
30991 " .align 2,0x90\n" \
30992- "0: rep; movsl\n" \
30993+ "0: rep; "prefix"movsl\n" \
30994 " movl %3,%0\n" \
30995- "1: rep; movsb\n" \
30996+ "1: rep; "prefix"movsb\n" \
30997 "2:\n" \
30998+ restore \
30999 ".section .fixup,\"ax\"\n" \
31000 "5: addl %3,%0\n" \
31001 " jmp 2b\n" \
31002@@ -538,14 +650,14 @@ do { \
31003 " negl %0\n" \
31004 " andl $7,%0\n" \
31005 " subl %0,%3\n" \
31006- "4: rep; movsb\n" \
31007+ "4: rep; "__copyuser_seg"movsb\n" \
31008 " movl %3,%0\n" \
31009 " shrl $2,%0\n" \
31010 " andl $3,%3\n" \
31011 " .align 2,0x90\n" \
31012- "0: rep; movsl\n" \
31013+ "0: rep; "__copyuser_seg"movsl\n" \
31014 " movl %3,%0\n" \
31015- "1: rep; movsb\n" \
31016+ "1: rep; "__copyuser_seg"movsb\n" \
31017 "2:\n" \
31018 ".section .fixup,\"ax\"\n" \
31019 "5: addl %3,%0\n" \
31020@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31021 {
31022 stac();
31023 if (movsl_is_ok(to, from, n))
31024- __copy_user(to, from, n);
31025+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31026 else
31027- n = __copy_user_intel(to, from, n);
31028+ n = __generic_copy_to_user_intel(to, from, n);
31029 clac();
31030 return n;
31031 }
31032@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31033 {
31034 stac();
31035 if (movsl_is_ok(to, from, n))
31036- __copy_user(to, from, n);
31037+ __copy_user(to, from, n, __copyuser_seg, "", "");
31038 else
31039- n = __copy_user_intel((void __user *)to,
31040- (const void *)from, n);
31041+ n = __generic_copy_from_user_intel(to, from, n);
31042 clac();
31043 return n;
31044 }
31045@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31046 if (n > 64 && cpu_has_xmm2)
31047 n = __copy_user_intel_nocache(to, from, n);
31048 else
31049- __copy_user(to, from, n);
31050+ __copy_user(to, from, n, __copyuser_seg, "", "");
31051 #else
31052- __copy_user(to, from, n);
31053+ __copy_user(to, from, n, __copyuser_seg, "", "");
31054 #endif
31055 clac();
31056 return n;
31057 }
31058 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31059
31060-/**
31061- * copy_to_user: - Copy a block of data into user space.
31062- * @to: Destination address, in user space.
31063- * @from: Source address, in kernel space.
31064- * @n: Number of bytes to copy.
31065- *
31066- * Context: User context only. This function may sleep.
31067- *
31068- * Copy data from kernel space to user space.
31069- *
31070- * Returns number of bytes that could not be copied.
31071- * On success, this will be zero.
31072- */
31073-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31074+#ifdef CONFIG_PAX_MEMORY_UDEREF
31075+void __set_fs(mm_segment_t x)
31076 {
31077- if (access_ok(VERIFY_WRITE, to, n))
31078- n = __copy_to_user(to, from, n);
31079- return n;
31080+ switch (x.seg) {
31081+ case 0:
31082+ loadsegment(gs, 0);
31083+ break;
31084+ case TASK_SIZE_MAX:
31085+ loadsegment(gs, __USER_DS);
31086+ break;
31087+ case -1UL:
31088+ loadsegment(gs, __KERNEL_DS);
31089+ break;
31090+ default:
31091+ BUG();
31092+ }
31093 }
31094-EXPORT_SYMBOL(_copy_to_user);
31095+EXPORT_SYMBOL(__set_fs);
31096
31097-/**
31098- * copy_from_user: - Copy a block of data from user space.
31099- * @to: Destination address, in kernel space.
31100- * @from: Source address, in user space.
31101- * @n: Number of bytes to copy.
31102- *
31103- * Context: User context only. This function may sleep.
31104- *
31105- * Copy data from user space to kernel space.
31106- *
31107- * Returns number of bytes that could not be copied.
31108- * On success, this will be zero.
31109- *
31110- * If some data could not be copied, this function will pad the copied
31111- * data to the requested size using zero bytes.
31112- */
31113-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31114+void set_fs(mm_segment_t x)
31115 {
31116- if (access_ok(VERIFY_READ, from, n))
31117- n = __copy_from_user(to, from, n);
31118- else
31119- memset(to, 0, n);
31120- return n;
31121+ current_thread_info()->addr_limit = x;
31122+ __set_fs(x);
31123 }
31124-EXPORT_SYMBOL(_copy_from_user);
31125+EXPORT_SYMBOL(set_fs);
31126+#endif
31127diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31128index c905e89..01ab928 100644
31129--- a/arch/x86/lib/usercopy_64.c
31130+++ b/arch/x86/lib/usercopy_64.c
31131@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31132 might_fault();
31133 /* no memory constraint because it doesn't change any memory gcc knows
31134 about */
31135+ pax_open_userland();
31136 stac();
31137 asm volatile(
31138 " testq %[size8],%[size8]\n"
31139@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31140 _ASM_EXTABLE(0b,3b)
31141 _ASM_EXTABLE(1b,2b)
31142 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31143- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31144+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31145 [zero] "r" (0UL), [eight] "r" (8UL));
31146 clac();
31147+ pax_close_userland();
31148 return size;
31149 }
31150 EXPORT_SYMBOL(__clear_user);
31151@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31152 }
31153 EXPORT_SYMBOL(clear_user);
31154
31155-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31156+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31157 {
31158- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31159- return copy_user_generic((__force void *)to, (__force void *)from, len);
31160- }
31161- return len;
31162+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31163+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31164+ return len;
31165 }
31166 EXPORT_SYMBOL(copy_in_user);
31167
31168@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31169 * it is not necessary to optimize tail handling.
31170 */
31171 __visible unsigned long
31172-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31173+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31174 {
31175 char c;
31176 unsigned zero_len;
31177
31178+ clac();
31179+ pax_close_userland();
31180 for (; len; --len, to++) {
31181 if (__get_user_nocheck(c, from++, sizeof(char)))
31182 break;
31183@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31184 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31185 if (__put_user_nocheck(c, to++, sizeof(char)))
31186 break;
31187- clac();
31188 return len;
31189 }
31190diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31191index 6a19ad9..1c48f9a 100644
31192--- a/arch/x86/mm/Makefile
31193+++ b/arch/x86/mm/Makefile
31194@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31195 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31196
31197 obj-$(CONFIG_MEMTEST) += memtest.o
31198+
31199+quote:="
31200+obj-$(CONFIG_X86_64) += uderef_64.o
31201+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31202diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31203index 903ec1e..c4166b2 100644
31204--- a/arch/x86/mm/extable.c
31205+++ b/arch/x86/mm/extable.c
31206@@ -6,12 +6,24 @@
31207 static inline unsigned long
31208 ex_insn_addr(const struct exception_table_entry *x)
31209 {
31210- return (unsigned long)&x->insn + x->insn;
31211+ unsigned long reloc = 0;
31212+
31213+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31214+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31215+#endif
31216+
31217+ return (unsigned long)&x->insn + x->insn + reloc;
31218 }
31219 static inline unsigned long
31220 ex_fixup_addr(const struct exception_table_entry *x)
31221 {
31222- return (unsigned long)&x->fixup + x->fixup;
31223+ unsigned long reloc = 0;
31224+
31225+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31226+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31227+#endif
31228+
31229+ return (unsigned long)&x->fixup + x->fixup + reloc;
31230 }
31231
31232 int fixup_exception(struct pt_regs *regs)
31233@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31234 unsigned long new_ip;
31235
31236 #ifdef CONFIG_PNPBIOS
31237- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31238+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31239 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31240 extern u32 pnp_bios_is_utter_crap;
31241 pnp_bios_is_utter_crap = 1;
31242@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31243 i += 4;
31244 p->fixup -= i;
31245 i += 4;
31246+
31247+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31248+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31249+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31250+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31251+#endif
31252+
31253 }
31254 }
31255
31256diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31257index a10c8c7..35a5abb 100644
31258--- a/arch/x86/mm/fault.c
31259+++ b/arch/x86/mm/fault.c
31260@@ -14,11 +14,18 @@
31261 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31262 #include <linux/prefetch.h> /* prefetchw */
31263 #include <linux/context_tracking.h> /* exception_enter(), ... */
31264+#include <linux/unistd.h>
31265+#include <linux/compiler.h>
31266
31267 #include <asm/traps.h> /* dotraplinkage, ... */
31268 #include <asm/pgalloc.h> /* pgd_*(), ... */
31269 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31270 #include <asm/fixmap.h> /* VSYSCALL_START */
31271+#include <asm/tlbflush.h>
31272+
31273+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31274+#include <asm/stacktrace.h>
31275+#endif
31276
31277 #define CREATE_TRACE_POINTS
31278 #include <asm/trace/exceptions.h>
31279@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31280 int ret = 0;
31281
31282 /* kprobe_running() needs smp_processor_id() */
31283- if (kprobes_built_in() && !user_mode_vm(regs)) {
31284+ if (kprobes_built_in() && !user_mode(regs)) {
31285 preempt_disable();
31286 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31287 ret = 1;
31288@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31289 return !instr_lo || (instr_lo>>1) == 1;
31290 case 0x00:
31291 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31292- if (probe_kernel_address(instr, opcode))
31293+ if (user_mode(regs)) {
31294+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31295+ return 0;
31296+ } else if (probe_kernel_address(instr, opcode))
31297 return 0;
31298
31299 *prefetch = (instr_lo == 0xF) &&
31300@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31301 while (instr < max_instr) {
31302 unsigned char opcode;
31303
31304- if (probe_kernel_address(instr, opcode))
31305+ if (user_mode(regs)) {
31306+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31307+ break;
31308+ } else if (probe_kernel_address(instr, opcode))
31309 break;
31310
31311 instr++;
31312@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31313 force_sig_info(si_signo, &info, tsk);
31314 }
31315
31316+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31317+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31318+#endif
31319+
31320+#ifdef CONFIG_PAX_EMUTRAMP
31321+static int pax_handle_fetch_fault(struct pt_regs *regs);
31322+#endif
31323+
31324+#ifdef CONFIG_PAX_PAGEEXEC
31325+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31326+{
31327+ pgd_t *pgd;
31328+ pud_t *pud;
31329+ pmd_t *pmd;
31330+
31331+ pgd = pgd_offset(mm, address);
31332+ if (!pgd_present(*pgd))
31333+ return NULL;
31334+ pud = pud_offset(pgd, address);
31335+ if (!pud_present(*pud))
31336+ return NULL;
31337+ pmd = pmd_offset(pud, address);
31338+ if (!pmd_present(*pmd))
31339+ return NULL;
31340+ return pmd;
31341+}
31342+#endif
31343+
31344 DEFINE_SPINLOCK(pgd_lock);
31345 LIST_HEAD(pgd_list);
31346
31347@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31348 for (address = VMALLOC_START & PMD_MASK;
31349 address >= TASK_SIZE && address < FIXADDR_TOP;
31350 address += PMD_SIZE) {
31351+
31352+#ifdef CONFIG_PAX_PER_CPU_PGD
31353+ unsigned long cpu;
31354+#else
31355 struct page *page;
31356+#endif
31357
31358 spin_lock(&pgd_lock);
31359+
31360+#ifdef CONFIG_PAX_PER_CPU_PGD
31361+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31362+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31363+ pmd_t *ret;
31364+
31365+ ret = vmalloc_sync_one(pgd, address);
31366+ if (!ret)
31367+ break;
31368+ pgd = get_cpu_pgd(cpu, kernel);
31369+#else
31370 list_for_each_entry(page, &pgd_list, lru) {
31371+ pgd_t *pgd;
31372 spinlock_t *pgt_lock;
31373 pmd_t *ret;
31374
31375@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31376 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31377
31378 spin_lock(pgt_lock);
31379- ret = vmalloc_sync_one(page_address(page), address);
31380+ pgd = page_address(page);
31381+#endif
31382+
31383+ ret = vmalloc_sync_one(pgd, address);
31384+
31385+#ifndef CONFIG_PAX_PER_CPU_PGD
31386 spin_unlock(pgt_lock);
31387+#endif
31388
31389 if (!ret)
31390 break;
31391@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31392 * an interrupt in the middle of a task switch..
31393 */
31394 pgd_paddr = read_cr3();
31395+
31396+#ifdef CONFIG_PAX_PER_CPU_PGD
31397+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31398+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31399+#endif
31400+
31401 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31402 if (!pmd_k)
31403 return -1;
31404@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31405 * happen within a race in page table update. In the later
31406 * case just flush:
31407 */
31408- pgd = pgd_offset(current->active_mm, address);
31409+
31410 pgd_ref = pgd_offset_k(address);
31411 if (pgd_none(*pgd_ref))
31412 return -1;
31413
31414+#ifdef CONFIG_PAX_PER_CPU_PGD
31415+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31416+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31417+ if (pgd_none(*pgd)) {
31418+ set_pgd(pgd, *pgd_ref);
31419+ arch_flush_lazy_mmu_mode();
31420+ } else {
31421+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31422+ }
31423+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31424+#else
31425+ pgd = pgd_offset(current->active_mm, address);
31426+#endif
31427+
31428 if (pgd_none(*pgd)) {
31429 set_pgd(pgd, *pgd_ref);
31430 arch_flush_lazy_mmu_mode();
31431@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31432 static int is_errata100(struct pt_regs *regs, unsigned long address)
31433 {
31434 #ifdef CONFIG_X86_64
31435- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31436+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31437 return 1;
31438 #endif
31439 return 0;
31440@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31441 }
31442
31443 static const char nx_warning[] = KERN_CRIT
31444-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31445+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31446
31447 static void
31448 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31449@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31450 if (!oops_may_print())
31451 return;
31452
31453- if (error_code & PF_INSTR) {
31454+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31455 unsigned int level;
31456
31457 pte_t *pte = lookup_address(address, &level);
31458
31459 if (pte && pte_present(*pte) && !pte_exec(*pte))
31460- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31461+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31462 }
31463
31464+#ifdef CONFIG_PAX_KERNEXEC
31465+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31466+ if (current->signal->curr_ip)
31467+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31468+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31469+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31470+ else
31471+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31472+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31473+ }
31474+#endif
31475+
31476 printk(KERN_ALERT "BUG: unable to handle kernel ");
31477 if (address < PAGE_SIZE)
31478 printk(KERN_CONT "NULL pointer dereference");
31479@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31480 return;
31481 }
31482 #endif
31483+
31484+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31485+ if (pax_is_fetch_fault(regs, error_code, address)) {
31486+
31487+#ifdef CONFIG_PAX_EMUTRAMP
31488+ switch (pax_handle_fetch_fault(regs)) {
31489+ case 2:
31490+ return;
31491+ }
31492+#endif
31493+
31494+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31495+ do_group_exit(SIGKILL);
31496+ }
31497+#endif
31498+
31499 /* Kernel addresses are always protection faults: */
31500 if (address >= TASK_SIZE)
31501 error_code |= PF_PROT;
31502@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31503 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31504 printk(KERN_ERR
31505 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31506- tsk->comm, tsk->pid, address);
31507+ tsk->comm, task_pid_nr(tsk), address);
31508 code = BUS_MCEERR_AR;
31509 }
31510 #endif
31511@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31512 return 1;
31513 }
31514
31515+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31516+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31517+{
31518+ pte_t *pte;
31519+ pmd_t *pmd;
31520+ spinlock_t *ptl;
31521+ unsigned char pte_mask;
31522+
31523+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31524+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31525+ return 0;
31526+
31527+ /* PaX: it's our fault, let's handle it if we can */
31528+
31529+ /* PaX: take a look at read faults before acquiring any locks */
31530+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31531+ /* instruction fetch attempt from a protected page in user mode */
31532+ up_read(&mm->mmap_sem);
31533+
31534+#ifdef CONFIG_PAX_EMUTRAMP
31535+ switch (pax_handle_fetch_fault(regs)) {
31536+ case 2:
31537+ return 1;
31538+ }
31539+#endif
31540+
31541+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31542+ do_group_exit(SIGKILL);
31543+ }
31544+
31545+ pmd = pax_get_pmd(mm, address);
31546+ if (unlikely(!pmd))
31547+ return 0;
31548+
31549+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31550+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31551+ pte_unmap_unlock(pte, ptl);
31552+ return 0;
31553+ }
31554+
31555+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31556+ /* write attempt to a protected page in user mode */
31557+ pte_unmap_unlock(pte, ptl);
31558+ return 0;
31559+ }
31560+
31561+#ifdef CONFIG_SMP
31562+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31563+#else
31564+ if (likely(address > get_limit(regs->cs)))
31565+#endif
31566+ {
31567+ set_pte(pte, pte_mkread(*pte));
31568+ __flush_tlb_one(address);
31569+ pte_unmap_unlock(pte, ptl);
31570+ up_read(&mm->mmap_sem);
31571+ return 1;
31572+ }
31573+
31574+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31575+
31576+ /*
31577+ * PaX: fill DTLB with user rights and retry
31578+ */
31579+ __asm__ __volatile__ (
31580+ "orb %2,(%1)\n"
31581+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31582+/*
31583+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31584+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31585+ * page fault when examined during a TLB load attempt. this is true not only
31586+ * for PTEs holding a non-present entry but also present entries that will
31587+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31588+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31589+ * for our target pages since their PTEs are simply not in the TLBs at all.
31590+
31591+ * the best thing in omitting it is that we gain around 15-20% speed in the
31592+ * fast path of the page fault handler and can get rid of tracing since we
31593+ * can no longer flush unintended entries.
31594+ */
31595+ "invlpg (%0)\n"
31596+#endif
31597+ __copyuser_seg"testb $0,(%0)\n"
31598+ "xorb %3,(%1)\n"
31599+ :
31600+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31601+ : "memory", "cc");
31602+ pte_unmap_unlock(pte, ptl);
31603+ up_read(&mm->mmap_sem);
31604+ return 1;
31605+}
31606+#endif
31607+
31608 /*
31609 * Handle a spurious fault caused by a stale TLB entry.
31610 *
31611@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31612 static inline int
31613 access_error(unsigned long error_code, struct vm_area_struct *vma)
31614 {
31615+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31616+ return 1;
31617+
31618 if (error_code & PF_WRITE) {
31619 /* write, present and write, not present: */
31620 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31621@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31622 if (error_code & PF_USER)
31623 return false;
31624
31625- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31626+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31627 return false;
31628
31629 return true;
31630@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31631 tsk = current;
31632 mm = tsk->mm;
31633
31634+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31635+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31636+ if (!search_exception_tables(regs->ip)) {
31637+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31638+ bad_area_nosemaphore(regs, error_code, address);
31639+ return;
31640+ }
31641+ if (address < pax_user_shadow_base) {
31642+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31643+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31644+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31645+ } else
31646+ address -= pax_user_shadow_base;
31647+ }
31648+#endif
31649+
31650 /*
31651 * Detect and handle instructions that would cause a page fault for
31652 * both a tracked kernel page and a userspace page.
31653@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31654 * User-mode registers count as a user access even for any
31655 * potential system fault or CPU buglet:
31656 */
31657- if (user_mode_vm(regs)) {
31658+ if (user_mode(regs)) {
31659 local_irq_enable();
31660 error_code |= PF_USER;
31661 flags |= FAULT_FLAG_USER;
31662@@ -1162,6 +1386,11 @@ retry:
31663 might_sleep();
31664 }
31665
31666+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31667+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31668+ return;
31669+#endif
31670+
31671 vma = find_vma(mm, address);
31672 if (unlikely(!vma)) {
31673 bad_area(regs, error_code, address);
31674@@ -1173,18 +1402,24 @@ retry:
31675 bad_area(regs, error_code, address);
31676 return;
31677 }
31678- if (error_code & PF_USER) {
31679- /*
31680- * Accessing the stack below %sp is always a bug.
31681- * The large cushion allows instructions like enter
31682- * and pusha to work. ("enter $65535, $31" pushes
31683- * 32 pointers and then decrements %sp by 65535.)
31684- */
31685- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31686- bad_area(regs, error_code, address);
31687- return;
31688- }
31689+ /*
31690+ * Accessing the stack below %sp is always a bug.
31691+ * The large cushion allows instructions like enter
31692+ * and pusha to work. ("enter $65535, $31" pushes
31693+ * 32 pointers and then decrements %sp by 65535.)
31694+ */
31695+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31696+ bad_area(regs, error_code, address);
31697+ return;
31698 }
31699+
31700+#ifdef CONFIG_PAX_SEGMEXEC
31701+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31702+ bad_area(regs, error_code, address);
31703+ return;
31704+ }
31705+#endif
31706+
31707 if (unlikely(expand_stack(vma, address))) {
31708 bad_area(regs, error_code, address);
31709 return;
31710@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31711 exception_exit(prev_state);
31712 }
31713 #endif /* CONFIG_TRACING */
31714+
31715+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31716+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31717+{
31718+ struct mm_struct *mm = current->mm;
31719+ unsigned long ip = regs->ip;
31720+
31721+ if (v8086_mode(regs))
31722+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31723+
31724+#ifdef CONFIG_PAX_PAGEEXEC
31725+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31726+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31727+ return true;
31728+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31729+ return true;
31730+ return false;
31731+ }
31732+#endif
31733+
31734+#ifdef CONFIG_PAX_SEGMEXEC
31735+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31736+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31737+ return true;
31738+ return false;
31739+ }
31740+#endif
31741+
31742+ return false;
31743+}
31744+#endif
31745+
31746+#ifdef CONFIG_PAX_EMUTRAMP
31747+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31748+{
31749+ int err;
31750+
31751+ do { /* PaX: libffi trampoline emulation */
31752+ unsigned char mov, jmp;
31753+ unsigned int addr1, addr2;
31754+
31755+#ifdef CONFIG_X86_64
31756+ if ((regs->ip + 9) >> 32)
31757+ break;
31758+#endif
31759+
31760+ err = get_user(mov, (unsigned char __user *)regs->ip);
31761+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31762+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31763+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31764+
31765+ if (err)
31766+ break;
31767+
31768+ if (mov == 0xB8 && jmp == 0xE9) {
31769+ regs->ax = addr1;
31770+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31771+ return 2;
31772+ }
31773+ } while (0);
31774+
31775+ do { /* PaX: gcc trampoline emulation #1 */
31776+ unsigned char mov1, mov2;
31777+ unsigned short jmp;
31778+ unsigned int addr1, addr2;
31779+
31780+#ifdef CONFIG_X86_64
31781+ if ((regs->ip + 11) >> 32)
31782+ break;
31783+#endif
31784+
31785+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31786+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31787+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31788+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31789+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31790+
31791+ if (err)
31792+ break;
31793+
31794+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31795+ regs->cx = addr1;
31796+ regs->ax = addr2;
31797+ regs->ip = addr2;
31798+ return 2;
31799+ }
31800+ } while (0);
31801+
31802+ do { /* PaX: gcc trampoline emulation #2 */
31803+ unsigned char mov, jmp;
31804+ unsigned int addr1, addr2;
31805+
31806+#ifdef CONFIG_X86_64
31807+ if ((regs->ip + 9) >> 32)
31808+ break;
31809+#endif
31810+
31811+ err = get_user(mov, (unsigned char __user *)regs->ip);
31812+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31813+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31814+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31815+
31816+ if (err)
31817+ break;
31818+
31819+ if (mov == 0xB9 && jmp == 0xE9) {
31820+ regs->cx = addr1;
31821+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31822+ return 2;
31823+ }
31824+ } while (0);
31825+
31826+ return 1; /* PaX in action */
31827+}
31828+
31829+#ifdef CONFIG_X86_64
31830+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31831+{
31832+ int err;
31833+
31834+ do { /* PaX: libffi trampoline emulation */
31835+ unsigned short mov1, mov2, jmp1;
31836+ unsigned char stcclc, jmp2;
31837+ unsigned long addr1, addr2;
31838+
31839+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31840+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31841+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31842+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31843+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31844+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31845+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31846+
31847+ if (err)
31848+ break;
31849+
31850+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31851+ regs->r11 = addr1;
31852+ regs->r10 = addr2;
31853+ if (stcclc == 0xF8)
31854+ regs->flags &= ~X86_EFLAGS_CF;
31855+ else
31856+ regs->flags |= X86_EFLAGS_CF;
31857+ regs->ip = addr1;
31858+ return 2;
31859+ }
31860+ } while (0);
31861+
31862+ do { /* PaX: gcc trampoline emulation #1 */
31863+ unsigned short mov1, mov2, jmp1;
31864+ unsigned char jmp2;
31865+ unsigned int addr1;
31866+ unsigned long addr2;
31867+
31868+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31869+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31870+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31871+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31872+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31873+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31874+
31875+ if (err)
31876+ break;
31877+
31878+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31879+ regs->r11 = addr1;
31880+ regs->r10 = addr2;
31881+ regs->ip = addr1;
31882+ return 2;
31883+ }
31884+ } while (0);
31885+
31886+ do { /* PaX: gcc trampoline emulation #2 */
31887+ unsigned short mov1, mov2, jmp1;
31888+ unsigned char jmp2;
31889+ unsigned long addr1, addr2;
31890+
31891+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31892+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31893+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31894+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31895+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31896+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31897+
31898+ if (err)
31899+ break;
31900+
31901+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31902+ regs->r11 = addr1;
31903+ regs->r10 = addr2;
31904+ regs->ip = addr1;
31905+ return 2;
31906+ }
31907+ } while (0);
31908+
31909+ return 1; /* PaX in action */
31910+}
31911+#endif
31912+
31913+/*
31914+ * PaX: decide what to do with offenders (regs->ip = fault address)
31915+ *
31916+ * returns 1 when task should be killed
31917+ * 2 when gcc trampoline was detected
31918+ */
31919+static int pax_handle_fetch_fault(struct pt_regs *regs)
31920+{
31921+ if (v8086_mode(regs))
31922+ return 1;
31923+
31924+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31925+ return 1;
31926+
31927+#ifdef CONFIG_X86_32
31928+ return pax_handle_fetch_fault_32(regs);
31929+#else
31930+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31931+ return pax_handle_fetch_fault_32(regs);
31932+ else
31933+ return pax_handle_fetch_fault_64(regs);
31934+#endif
31935+}
31936+#endif
31937+
31938+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31939+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31940+{
31941+ long i;
31942+
31943+ printk(KERN_ERR "PAX: bytes at PC: ");
31944+ for (i = 0; i < 20; i++) {
31945+ unsigned char c;
31946+ if (get_user(c, (unsigned char __force_user *)pc+i))
31947+ printk(KERN_CONT "?? ");
31948+ else
31949+ printk(KERN_CONT "%02x ", c);
31950+ }
31951+ printk("\n");
31952+
31953+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31954+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31955+ unsigned long c;
31956+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31957+#ifdef CONFIG_X86_32
31958+ printk(KERN_CONT "???????? ");
31959+#else
31960+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31961+ printk(KERN_CONT "???????? ???????? ");
31962+ else
31963+ printk(KERN_CONT "???????????????? ");
31964+#endif
31965+ } else {
31966+#ifdef CONFIG_X86_64
31967+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31968+ printk(KERN_CONT "%08x ", (unsigned int)c);
31969+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31970+ } else
31971+#endif
31972+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31973+ }
31974+ }
31975+ printk("\n");
31976+}
31977+#endif
31978+
31979+/**
31980+ * probe_kernel_write(): safely attempt to write to a location
31981+ * @dst: address to write to
31982+ * @src: pointer to the data that shall be written
31983+ * @size: size of the data chunk
31984+ *
31985+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31986+ * happens, handle that and return -EFAULT.
31987+ */
31988+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31989+{
31990+ long ret;
31991+ mm_segment_t old_fs = get_fs();
31992+
31993+ set_fs(KERNEL_DS);
31994+ pagefault_disable();
31995+ pax_open_kernel();
31996+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31997+ pax_close_kernel();
31998+ pagefault_enable();
31999+ set_fs(old_fs);
32000+
32001+ return ret ? -EFAULT : 0;
32002+}
32003diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32004index 207d9aef..69030980 100644
32005--- a/arch/x86/mm/gup.c
32006+++ b/arch/x86/mm/gup.c
32007@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32008 addr = start;
32009 len = (unsigned long) nr_pages << PAGE_SHIFT;
32010 end = start + len;
32011- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32012+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32013 (void __user *)start, len)))
32014 return 0;
32015
32016@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32017 goto slow_irqon;
32018 #endif
32019
32020+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32021+ (void __user *)start, len)))
32022+ return 0;
32023+
32024 /*
32025 * XXX: batch / limit 'nr', to avoid large irq off latency
32026 * needs some instrumenting to determine the common sizes used by
32027diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32028index 4500142..53a363c 100644
32029--- a/arch/x86/mm/highmem_32.c
32030+++ b/arch/x86/mm/highmem_32.c
32031@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32032 idx = type + KM_TYPE_NR*smp_processor_id();
32033 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32034 BUG_ON(!pte_none(*(kmap_pte-idx)));
32035+
32036+ pax_open_kernel();
32037 set_pte(kmap_pte-idx, mk_pte(page, prot));
32038+ pax_close_kernel();
32039+
32040 arch_flush_lazy_mmu_mode();
32041
32042 return (void *)vaddr;
32043diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32044index 8c9f647..57cb402 100644
32045--- a/arch/x86/mm/hugetlbpage.c
32046+++ b/arch/x86/mm/hugetlbpage.c
32047@@ -90,23 +90,24 @@ int pmd_huge_support(void)
32048 #ifdef CONFIG_HUGETLB_PAGE
32049 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32050 unsigned long addr, unsigned long len,
32051- unsigned long pgoff, unsigned long flags)
32052+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32053 {
32054 struct hstate *h = hstate_file(file);
32055 struct vm_unmapped_area_info info;
32056-
32057+
32058 info.flags = 0;
32059 info.length = len;
32060 info.low_limit = current->mm->mmap_legacy_base;
32061 info.high_limit = TASK_SIZE;
32062 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32063 info.align_offset = 0;
32064+ info.threadstack_offset = offset;
32065 return vm_unmapped_area(&info);
32066 }
32067
32068 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32069 unsigned long addr0, unsigned long len,
32070- unsigned long pgoff, unsigned long flags)
32071+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32072 {
32073 struct hstate *h = hstate_file(file);
32074 struct vm_unmapped_area_info info;
32075@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32076 info.high_limit = current->mm->mmap_base;
32077 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32078 info.align_offset = 0;
32079+ info.threadstack_offset = offset;
32080 addr = vm_unmapped_area(&info);
32081
32082 /*
32083@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32084 VM_BUG_ON(addr != -ENOMEM);
32085 info.flags = 0;
32086 info.low_limit = TASK_UNMAPPED_BASE;
32087+
32088+#ifdef CONFIG_PAX_RANDMMAP
32089+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32090+ info.low_limit += current->mm->delta_mmap;
32091+#endif
32092+
32093 info.high_limit = TASK_SIZE;
32094 addr = vm_unmapped_area(&info);
32095 }
32096@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32097 struct hstate *h = hstate_file(file);
32098 struct mm_struct *mm = current->mm;
32099 struct vm_area_struct *vma;
32100+ unsigned long pax_task_size = TASK_SIZE;
32101+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32102
32103 if (len & ~huge_page_mask(h))
32104 return -EINVAL;
32105- if (len > TASK_SIZE)
32106+
32107+#ifdef CONFIG_PAX_SEGMEXEC
32108+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32109+ pax_task_size = SEGMEXEC_TASK_SIZE;
32110+#endif
32111+
32112+ pax_task_size -= PAGE_SIZE;
32113+
32114+ if (len > pax_task_size)
32115 return -ENOMEM;
32116
32117 if (flags & MAP_FIXED) {
32118@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32119 return addr;
32120 }
32121
32122+#ifdef CONFIG_PAX_RANDMMAP
32123+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32124+#endif
32125+
32126 if (addr) {
32127 addr = ALIGN(addr, huge_page_size(h));
32128 vma = find_vma(mm, addr);
32129- if (TASK_SIZE - len >= addr &&
32130- (!vma || addr + len <= vma->vm_start))
32131+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32132 return addr;
32133 }
32134 if (mm->get_unmapped_area == arch_get_unmapped_area)
32135 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32136- pgoff, flags);
32137+ pgoff, flags, offset);
32138 else
32139 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32140- pgoff, flags);
32141+ pgoff, flags, offset);
32142 }
32143 #endif /* CONFIG_HUGETLB_PAGE */
32144
32145diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32146index f971306..e83e0f6 100644
32147--- a/arch/x86/mm/init.c
32148+++ b/arch/x86/mm/init.c
32149@@ -4,6 +4,7 @@
32150 #include <linux/swap.h>
32151 #include <linux/memblock.h>
32152 #include <linux/bootmem.h> /* for max_low_pfn */
32153+#include <linux/tboot.h>
32154
32155 #include <asm/cacheflush.h>
32156 #include <asm/e820.h>
32157@@ -17,6 +18,8 @@
32158 #include <asm/proto.h>
32159 #include <asm/dma.h> /* for MAX_DMA_PFN */
32160 #include <asm/microcode.h>
32161+#include <asm/desc.h>
32162+#include <asm/bios_ebda.h>
32163
32164 #include "mm_internal.h"
32165
32166@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32167 early_ioremap_page_table_range_init();
32168 #endif
32169
32170+#ifdef CONFIG_PAX_PER_CPU_PGD
32171+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32172+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32173+ KERNEL_PGD_PTRS);
32174+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32175+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32176+ KERNEL_PGD_PTRS);
32177+ load_cr3(get_cpu_pgd(0, kernel));
32178+#else
32179 load_cr3(swapper_pg_dir);
32180+#endif
32181+
32182 __flush_tlb_all();
32183
32184 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32185@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32186 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32187 * mmio resources as well as potential bios/acpi data regions.
32188 */
32189+
32190+#ifdef CONFIG_GRKERNSEC_KMEM
32191+static unsigned int ebda_start __read_only;
32192+static unsigned int ebda_end __read_only;
32193+#endif
32194+
32195 int devmem_is_allowed(unsigned long pagenr)
32196 {
32197- if (pagenr < 256)
32198+#ifdef CONFIG_GRKERNSEC_KMEM
32199+ /* allow BDA */
32200+ if (!pagenr)
32201 return 1;
32202+ /* allow EBDA */
32203+ if (pagenr >= ebda_start && pagenr < ebda_end)
32204+ return 1;
32205+ /* if tboot is in use, allow access to its hardcoded serial log range */
32206+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32207+ return 1;
32208+#else
32209+ if (!pagenr)
32210+ return 1;
32211+#ifdef CONFIG_VM86
32212+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32213+ return 1;
32214+#endif
32215+#endif
32216+
32217+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32218+ return 1;
32219+#ifdef CONFIG_GRKERNSEC_KMEM
32220+ /* throw out everything else below 1MB */
32221+ if (pagenr <= 256)
32222+ return 0;
32223+#endif
32224 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32225 return 0;
32226 if (!page_is_ram(pagenr))
32227@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32228 #endif
32229 }
32230
32231+#ifdef CONFIG_GRKERNSEC_KMEM
32232+static inline void gr_init_ebda(void)
32233+{
32234+ unsigned int ebda_addr;
32235+ unsigned int ebda_size = 0;
32236+
32237+ ebda_addr = get_bios_ebda();
32238+ if (ebda_addr) {
32239+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32240+ ebda_size <<= 10;
32241+ }
32242+ if (ebda_addr && ebda_size) {
32243+ ebda_start = ebda_addr >> PAGE_SHIFT;
32244+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32245+ } else {
32246+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32247+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32248+ }
32249+}
32250+#else
32251+static inline void gr_init_ebda(void) { }
32252+#endif
32253+
32254 void free_initmem(void)
32255 {
32256+#ifdef CONFIG_PAX_KERNEXEC
32257+#ifdef CONFIG_X86_32
32258+ /* PaX: limit KERNEL_CS to actual size */
32259+ unsigned long addr, limit;
32260+ struct desc_struct d;
32261+ int cpu;
32262+#else
32263+ pgd_t *pgd;
32264+ pud_t *pud;
32265+ pmd_t *pmd;
32266+ unsigned long addr, end;
32267+#endif
32268+#endif
32269+
32270+ gr_init_ebda();
32271+
32272+#ifdef CONFIG_PAX_KERNEXEC
32273+#ifdef CONFIG_X86_32
32274+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32275+ limit = (limit - 1UL) >> PAGE_SHIFT;
32276+
32277+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32278+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32279+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32280+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32281+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32282+ }
32283+
32284+ /* PaX: make KERNEL_CS read-only */
32285+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32286+ if (!paravirt_enabled())
32287+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32288+/*
32289+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32290+ pgd = pgd_offset_k(addr);
32291+ pud = pud_offset(pgd, addr);
32292+ pmd = pmd_offset(pud, addr);
32293+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32294+ }
32295+*/
32296+#ifdef CONFIG_X86_PAE
32297+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32298+/*
32299+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32300+ pgd = pgd_offset_k(addr);
32301+ pud = pud_offset(pgd, addr);
32302+ pmd = pmd_offset(pud, addr);
32303+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32304+ }
32305+*/
32306+#endif
32307+
32308+#ifdef CONFIG_MODULES
32309+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32310+#endif
32311+
32312+#else
32313+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32314+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32315+ pgd = pgd_offset_k(addr);
32316+ pud = pud_offset(pgd, addr);
32317+ pmd = pmd_offset(pud, addr);
32318+ if (!pmd_present(*pmd))
32319+ continue;
32320+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32321+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32322+ else
32323+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32324+ }
32325+
32326+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32327+ end = addr + KERNEL_IMAGE_SIZE;
32328+ for (; addr < end; addr += PMD_SIZE) {
32329+ pgd = pgd_offset_k(addr);
32330+ pud = pud_offset(pgd, addr);
32331+ pmd = pmd_offset(pud, addr);
32332+ if (!pmd_present(*pmd))
32333+ continue;
32334+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32335+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32336+ }
32337+#endif
32338+
32339+ flush_tlb_all();
32340+#endif
32341+
32342 free_init_pages("unused kernel",
32343 (unsigned long)(&__init_begin),
32344 (unsigned long)(&__init_end));
32345diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32346index e395048..cd38278 100644
32347--- a/arch/x86/mm/init_32.c
32348+++ b/arch/x86/mm/init_32.c
32349@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32350 bool __read_mostly __vmalloc_start_set = false;
32351
32352 /*
32353- * Creates a middle page table and puts a pointer to it in the
32354- * given global directory entry. This only returns the gd entry
32355- * in non-PAE compilation mode, since the middle layer is folded.
32356- */
32357-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32358-{
32359- pud_t *pud;
32360- pmd_t *pmd_table;
32361-
32362-#ifdef CONFIG_X86_PAE
32363- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32364- pmd_table = (pmd_t *)alloc_low_page();
32365- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32366- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32367- pud = pud_offset(pgd, 0);
32368- BUG_ON(pmd_table != pmd_offset(pud, 0));
32369-
32370- return pmd_table;
32371- }
32372-#endif
32373- pud = pud_offset(pgd, 0);
32374- pmd_table = pmd_offset(pud, 0);
32375-
32376- return pmd_table;
32377-}
32378-
32379-/*
32380 * Create a page table and place a pointer to it in a middle page
32381 * directory entry:
32382 */
32383@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32384 pte_t *page_table = (pte_t *)alloc_low_page();
32385
32386 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32387+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32388+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32389+#else
32390 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32391+#endif
32392 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32393 }
32394
32395 return pte_offset_kernel(pmd, 0);
32396 }
32397
32398+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32399+{
32400+ pud_t *pud;
32401+ pmd_t *pmd_table;
32402+
32403+ pud = pud_offset(pgd, 0);
32404+ pmd_table = pmd_offset(pud, 0);
32405+
32406+ return pmd_table;
32407+}
32408+
32409 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32410 {
32411 int pgd_idx = pgd_index(vaddr);
32412@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32413 int pgd_idx, pmd_idx;
32414 unsigned long vaddr;
32415 pgd_t *pgd;
32416+ pud_t *pud;
32417 pmd_t *pmd;
32418 pte_t *pte = NULL;
32419 unsigned long count = page_table_range_init_count(start, end);
32420@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32421 pgd = pgd_base + pgd_idx;
32422
32423 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32424- pmd = one_md_table_init(pgd);
32425- pmd = pmd + pmd_index(vaddr);
32426+ pud = pud_offset(pgd, vaddr);
32427+ pmd = pmd_offset(pud, vaddr);
32428+
32429+#ifdef CONFIG_X86_PAE
32430+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32431+#endif
32432+
32433 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32434 pmd++, pmd_idx++) {
32435 pte = page_table_kmap_check(one_page_table_init(pmd),
32436@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32437 }
32438 }
32439
32440-static inline int is_kernel_text(unsigned long addr)
32441+static inline int is_kernel_text(unsigned long start, unsigned long end)
32442 {
32443- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32444- return 1;
32445- return 0;
32446+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32447+ end <= ktla_ktva((unsigned long)_stext)) &&
32448+ (start >= ktla_ktva((unsigned long)_einittext) ||
32449+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32450+
32451+#ifdef CONFIG_ACPI_SLEEP
32452+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32453+#endif
32454+
32455+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32456+ return 0;
32457+ return 1;
32458 }
32459
32460 /*
32461@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32462 unsigned long last_map_addr = end;
32463 unsigned long start_pfn, end_pfn;
32464 pgd_t *pgd_base = swapper_pg_dir;
32465- int pgd_idx, pmd_idx, pte_ofs;
32466+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32467 unsigned long pfn;
32468 pgd_t *pgd;
32469+ pud_t *pud;
32470 pmd_t *pmd;
32471 pte_t *pte;
32472 unsigned pages_2m, pages_4k;
32473@@ -291,8 +295,13 @@ repeat:
32474 pfn = start_pfn;
32475 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32476 pgd = pgd_base + pgd_idx;
32477- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32478- pmd = one_md_table_init(pgd);
32479+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32480+ pud = pud_offset(pgd, 0);
32481+ pmd = pmd_offset(pud, 0);
32482+
32483+#ifdef CONFIG_X86_PAE
32484+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32485+#endif
32486
32487 if (pfn >= end_pfn)
32488 continue;
32489@@ -304,14 +313,13 @@ repeat:
32490 #endif
32491 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32492 pmd++, pmd_idx++) {
32493- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32494+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32495
32496 /*
32497 * Map with big pages if possible, otherwise
32498 * create normal page tables:
32499 */
32500 if (use_pse) {
32501- unsigned int addr2;
32502 pgprot_t prot = PAGE_KERNEL_LARGE;
32503 /*
32504 * first pass will use the same initial
32505@@ -322,11 +330,7 @@ repeat:
32506 _PAGE_PSE);
32507
32508 pfn &= PMD_MASK >> PAGE_SHIFT;
32509- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32510- PAGE_OFFSET + PAGE_SIZE-1;
32511-
32512- if (is_kernel_text(addr) ||
32513- is_kernel_text(addr2))
32514+ if (is_kernel_text(address, address + PMD_SIZE))
32515 prot = PAGE_KERNEL_LARGE_EXEC;
32516
32517 pages_2m++;
32518@@ -343,7 +347,7 @@ repeat:
32519 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32520 pte += pte_ofs;
32521 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32522- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32523+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32524 pgprot_t prot = PAGE_KERNEL;
32525 /*
32526 * first pass will use the same initial
32527@@ -351,7 +355,7 @@ repeat:
32528 */
32529 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32530
32531- if (is_kernel_text(addr))
32532+ if (is_kernel_text(address, address + PAGE_SIZE))
32533 prot = PAGE_KERNEL_EXEC;
32534
32535 pages_4k++;
32536@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32537
32538 pud = pud_offset(pgd, va);
32539 pmd = pmd_offset(pud, va);
32540- if (!pmd_present(*pmd))
32541+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32542 break;
32543
32544 /* should not be large page here */
32545@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32546
32547 static void __init pagetable_init(void)
32548 {
32549- pgd_t *pgd_base = swapper_pg_dir;
32550-
32551- permanent_kmaps_init(pgd_base);
32552+ permanent_kmaps_init(swapper_pg_dir);
32553 }
32554
32555-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32556+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32557 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32558
32559 /* user-defined highmem size */
32560@@ -787,10 +789,10 @@ void __init mem_init(void)
32561 ((unsigned long)&__init_end -
32562 (unsigned long)&__init_begin) >> 10,
32563
32564- (unsigned long)&_etext, (unsigned long)&_edata,
32565- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32566+ (unsigned long)&_sdata, (unsigned long)&_edata,
32567+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32568
32569- (unsigned long)&_text, (unsigned long)&_etext,
32570+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32571 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32572
32573 /*
32574@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32575 if (!kernel_set_to_readonly)
32576 return;
32577
32578+ start = ktla_ktva(start);
32579 pr_debug("Set kernel text: %lx - %lx for read write\n",
32580 start, start+size);
32581
32582@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32583 if (!kernel_set_to_readonly)
32584 return;
32585
32586+ start = ktla_ktva(start);
32587 pr_debug("Set kernel text: %lx - %lx for read only\n",
32588 start, start+size);
32589
32590@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32591 unsigned long start = PFN_ALIGN(_text);
32592 unsigned long size = PFN_ALIGN(_etext) - start;
32593
32594+ start = ktla_ktva(start);
32595 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32596 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32597 size >> 10);
32598diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32599index f35c66c..84b95ef 100644
32600--- a/arch/x86/mm/init_64.c
32601+++ b/arch/x86/mm/init_64.c
32602@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32603 * around without checking the pgd every time.
32604 */
32605
32606-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32607+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32608 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32609
32610 int force_personality32;
32611@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32612
32613 for (address = start; address <= end; address += PGDIR_SIZE) {
32614 const pgd_t *pgd_ref = pgd_offset_k(address);
32615+
32616+#ifdef CONFIG_PAX_PER_CPU_PGD
32617+ unsigned long cpu;
32618+#else
32619 struct page *page;
32620+#endif
32621
32622 if (pgd_none(*pgd_ref))
32623 continue;
32624
32625 spin_lock(&pgd_lock);
32626+
32627+#ifdef CONFIG_PAX_PER_CPU_PGD
32628+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32629+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32630+
32631+ if (pgd_none(*pgd))
32632+ set_pgd(pgd, *pgd_ref);
32633+ else
32634+ BUG_ON(pgd_page_vaddr(*pgd)
32635+ != pgd_page_vaddr(*pgd_ref));
32636+ pgd = pgd_offset_cpu(cpu, kernel, address);
32637+#else
32638 list_for_each_entry(page, &pgd_list, lru) {
32639 pgd_t *pgd;
32640 spinlock_t *pgt_lock;
32641@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32642 /* the pgt_lock only for Xen */
32643 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32644 spin_lock(pgt_lock);
32645+#endif
32646
32647 if (pgd_none(*pgd))
32648 set_pgd(pgd, *pgd_ref);
32649@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32650 BUG_ON(pgd_page_vaddr(*pgd)
32651 != pgd_page_vaddr(*pgd_ref));
32652
32653+#ifndef CONFIG_PAX_PER_CPU_PGD
32654 spin_unlock(pgt_lock);
32655+#endif
32656+
32657 }
32658 spin_unlock(&pgd_lock);
32659 }
32660@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32661 {
32662 if (pgd_none(*pgd)) {
32663 pud_t *pud = (pud_t *)spp_getpage();
32664- pgd_populate(&init_mm, pgd, pud);
32665+ pgd_populate_kernel(&init_mm, pgd, pud);
32666 if (pud != pud_offset(pgd, 0))
32667 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32668 pud, pud_offset(pgd, 0));
32669@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32670 {
32671 if (pud_none(*pud)) {
32672 pmd_t *pmd = (pmd_t *) spp_getpage();
32673- pud_populate(&init_mm, pud, pmd);
32674+ pud_populate_kernel(&init_mm, pud, pmd);
32675 if (pmd != pmd_offset(pud, 0))
32676 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32677 pmd, pmd_offset(pud, 0));
32678@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32679 pmd = fill_pmd(pud, vaddr);
32680 pte = fill_pte(pmd, vaddr);
32681
32682+ pax_open_kernel();
32683 set_pte(pte, new_pte);
32684+ pax_close_kernel();
32685
32686 /*
32687 * It's enough to flush this one mapping.
32688@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32689 pgd = pgd_offset_k((unsigned long)__va(phys));
32690 if (pgd_none(*pgd)) {
32691 pud = (pud_t *) spp_getpage();
32692- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32693- _PAGE_USER));
32694+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32695 }
32696 pud = pud_offset(pgd, (unsigned long)__va(phys));
32697 if (pud_none(*pud)) {
32698 pmd = (pmd_t *) spp_getpage();
32699- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32700- _PAGE_USER));
32701+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32702 }
32703 pmd = pmd_offset(pud, phys);
32704 BUG_ON(!pmd_none(*pmd));
32705@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32706 prot);
32707
32708 spin_lock(&init_mm.page_table_lock);
32709- pud_populate(&init_mm, pud, pmd);
32710+ pud_populate_kernel(&init_mm, pud, pmd);
32711 spin_unlock(&init_mm.page_table_lock);
32712 }
32713 __flush_tlb_all();
32714@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32715 page_size_mask);
32716
32717 spin_lock(&init_mm.page_table_lock);
32718- pgd_populate(&init_mm, pgd, pud);
32719+ pgd_populate_kernel(&init_mm, pgd, pud);
32720 spin_unlock(&init_mm.page_table_lock);
32721 pgd_changed = true;
32722 }
32723@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32724 static struct vm_area_struct gate_vma = {
32725 .vm_start = VSYSCALL_START,
32726 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32727- .vm_page_prot = PAGE_READONLY_EXEC,
32728- .vm_flags = VM_READ | VM_EXEC
32729+ .vm_page_prot = PAGE_READONLY,
32730+ .vm_flags = VM_READ
32731 };
32732
32733 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32734@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32735
32736 const char *arch_vma_name(struct vm_area_struct *vma)
32737 {
32738- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32739+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32740 return "[vdso]";
32741 if (vma == &gate_vma)
32742 return "[vsyscall]";
32743diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32744index 7b179b4..6bd17777 100644
32745--- a/arch/x86/mm/iomap_32.c
32746+++ b/arch/x86/mm/iomap_32.c
32747@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32748 type = kmap_atomic_idx_push();
32749 idx = type + KM_TYPE_NR * smp_processor_id();
32750 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32751+
32752+ pax_open_kernel();
32753 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32754+ pax_close_kernel();
32755+
32756 arch_flush_lazy_mmu_mode();
32757
32758 return (void *)vaddr;
32759diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32760index 799580c..72f9fe0 100644
32761--- a/arch/x86/mm/ioremap.c
32762+++ b/arch/x86/mm/ioremap.c
32763@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32764 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32765 int is_ram = page_is_ram(pfn);
32766
32767- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32768+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32769 return NULL;
32770 WARN_ON_ONCE(is_ram);
32771 }
32772@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32773 *
32774 * Caller must ensure there is only one unmapping for the same pointer.
32775 */
32776-void iounmap(volatile void __iomem *addr)
32777+void iounmap(const volatile void __iomem *addr)
32778 {
32779 struct vm_struct *p, *o;
32780
32781@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32782
32783 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32784 if (page_is_ram(start >> PAGE_SHIFT))
32785+#ifdef CONFIG_HIGHMEM
32786+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32787+#endif
32788 return __va(phys);
32789
32790 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32791@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32792 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32793 {
32794 if (page_is_ram(phys >> PAGE_SHIFT))
32795+#ifdef CONFIG_HIGHMEM
32796+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32797+#endif
32798 return;
32799
32800 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32801@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32802 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32803
32804 static __initdata int after_paging_init;
32805-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32806+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32807
32808 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32809 {
32810@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32811 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32812
32813 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32814- memset(bm_pte, 0, sizeof(bm_pte));
32815- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32816+ pmd_populate_user(&init_mm, pmd, bm_pte);
32817
32818 /*
32819 * The boot-ioremap range spans multiple pmds, for which
32820diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32821index d87dd6d..bf3fa66 100644
32822--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32823+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32824@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32825 * memory (e.g. tracked pages)? For now, we need this to avoid
32826 * invoking kmemcheck for PnP BIOS calls.
32827 */
32828- if (regs->flags & X86_VM_MASK)
32829+ if (v8086_mode(regs))
32830 return false;
32831- if (regs->cs != __KERNEL_CS)
32832+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32833 return false;
32834
32835 pte = kmemcheck_pte_lookup(address);
32836diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32837index 25e7e13..1964579 100644
32838--- a/arch/x86/mm/mmap.c
32839+++ b/arch/x86/mm/mmap.c
32840@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32841 * Leave an at least ~128 MB hole with possible stack randomization.
32842 */
32843 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32844-#define MAX_GAP (TASK_SIZE/6*5)
32845+#define MAX_GAP (pax_task_size/6*5)
32846
32847 static int mmap_is_legacy(void)
32848 {
32849@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32850 return rnd << PAGE_SHIFT;
32851 }
32852
32853-static unsigned long mmap_base(void)
32854+static unsigned long mmap_base(struct mm_struct *mm)
32855 {
32856 unsigned long gap = rlimit(RLIMIT_STACK);
32857+ unsigned long pax_task_size = TASK_SIZE;
32858+
32859+#ifdef CONFIG_PAX_SEGMEXEC
32860+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32861+ pax_task_size = SEGMEXEC_TASK_SIZE;
32862+#endif
32863
32864 if (gap < MIN_GAP)
32865 gap = MIN_GAP;
32866 else if (gap > MAX_GAP)
32867 gap = MAX_GAP;
32868
32869- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32870+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32871 }
32872
32873 /*
32874 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32875 * does, but not when emulating X86_32
32876 */
32877-static unsigned long mmap_legacy_base(void)
32878+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32879 {
32880- if (mmap_is_ia32())
32881+ if (mmap_is_ia32()) {
32882+
32883+#ifdef CONFIG_PAX_SEGMEXEC
32884+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32885+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32886+ else
32887+#endif
32888+
32889 return TASK_UNMAPPED_BASE;
32890- else
32891+ } else
32892 return TASK_UNMAPPED_BASE + mmap_rnd();
32893 }
32894
32895@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32896 */
32897 void arch_pick_mmap_layout(struct mm_struct *mm)
32898 {
32899- mm->mmap_legacy_base = mmap_legacy_base();
32900- mm->mmap_base = mmap_base();
32901+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32902+ mm->mmap_base = mmap_base(mm);
32903+
32904+#ifdef CONFIG_PAX_RANDMMAP
32905+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32906+ mm->mmap_legacy_base += mm->delta_mmap;
32907+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32908+ }
32909+#endif
32910
32911 if (mmap_is_legacy()) {
32912 mm->mmap_base = mm->mmap_legacy_base;
32913diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32914index 0057a7a..95c7edd 100644
32915--- a/arch/x86/mm/mmio-mod.c
32916+++ b/arch/x86/mm/mmio-mod.c
32917@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32918 break;
32919 default:
32920 {
32921- unsigned char *ip = (unsigned char *)instptr;
32922+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32923 my_trace->opcode = MMIO_UNKNOWN_OP;
32924 my_trace->width = 0;
32925 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32926@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32927 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32928 void __iomem *addr)
32929 {
32930- static atomic_t next_id;
32931+ static atomic_unchecked_t next_id;
32932 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32933 /* These are page-unaligned. */
32934 struct mmiotrace_map map = {
32935@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32936 .private = trace
32937 },
32938 .phys = offset,
32939- .id = atomic_inc_return(&next_id)
32940+ .id = atomic_inc_return_unchecked(&next_id)
32941 };
32942 map.map_id = trace->id;
32943
32944@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32945 ioremap_trace_core(offset, size, addr);
32946 }
32947
32948-static void iounmap_trace_core(volatile void __iomem *addr)
32949+static void iounmap_trace_core(const volatile void __iomem *addr)
32950 {
32951 struct mmiotrace_map map = {
32952 .phys = 0,
32953@@ -328,7 +328,7 @@ not_enabled:
32954 }
32955 }
32956
32957-void mmiotrace_iounmap(volatile void __iomem *addr)
32958+void mmiotrace_iounmap(const volatile void __iomem *addr)
32959 {
32960 might_sleep();
32961 if (is_enabled()) /* recheck and proper locking in *_core() */
32962diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32963index 27aa0455..0eb1406 100644
32964--- a/arch/x86/mm/numa.c
32965+++ b/arch/x86/mm/numa.c
32966@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32967 return true;
32968 }
32969
32970-static int __init numa_register_memblks(struct numa_meminfo *mi)
32971+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32972 {
32973 unsigned long uninitialized_var(pfn_align);
32974 int i, nid;
32975diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32976index 461bc82..4e091a3 100644
32977--- a/arch/x86/mm/pageattr-test.c
32978+++ b/arch/x86/mm/pageattr-test.c
32979@@ -35,7 +35,7 @@ enum {
32980
32981 static int pte_testbit(pte_t pte)
32982 {
32983- return pte_flags(pte) & _PAGE_UNUSED1;
32984+ return pte_flags(pte) & _PAGE_CPA_TEST;
32985 }
32986
32987 struct split_state {
32988diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32989index a348868..3c64310 100644
32990--- a/arch/x86/mm/pageattr.c
32991+++ b/arch/x86/mm/pageattr.c
32992@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32993 */
32994 #ifdef CONFIG_PCI_BIOS
32995 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32996- pgprot_val(forbidden) |= _PAGE_NX;
32997+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32998 #endif
32999
33000 /*
33001@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33002 * Does not cover __inittext since that is gone later on. On
33003 * 64bit we do not enforce !NX on the low mapping
33004 */
33005- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33006- pgprot_val(forbidden) |= _PAGE_NX;
33007+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33008+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33009
33010+#ifdef CONFIG_DEBUG_RODATA
33011 /*
33012 * The .rodata section needs to be read-only. Using the pfn
33013 * catches all aliases.
33014@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33015 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33016 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33017 pgprot_val(forbidden) |= _PAGE_RW;
33018+#endif
33019
33020 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33021 /*
33022@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33023 }
33024 #endif
33025
33026+#ifdef CONFIG_PAX_KERNEXEC
33027+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33028+ pgprot_val(forbidden) |= _PAGE_RW;
33029+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33030+ }
33031+#endif
33032+
33033 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33034
33035 return prot;
33036@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33037 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33038 {
33039 /* change init_mm */
33040+ pax_open_kernel();
33041 set_pte_atomic(kpte, pte);
33042+
33043 #ifdef CONFIG_X86_32
33044 if (!SHARED_KERNEL_PMD) {
33045+
33046+#ifdef CONFIG_PAX_PER_CPU_PGD
33047+ unsigned long cpu;
33048+#else
33049 struct page *page;
33050+#endif
33051
33052+#ifdef CONFIG_PAX_PER_CPU_PGD
33053+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33054+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33055+#else
33056 list_for_each_entry(page, &pgd_list, lru) {
33057- pgd_t *pgd;
33058+ pgd_t *pgd = (pgd_t *)page_address(page);
33059+#endif
33060+
33061 pud_t *pud;
33062 pmd_t *pmd;
33063
33064- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33065+ pgd += pgd_index(address);
33066 pud = pud_offset(pgd, address);
33067 pmd = pmd_offset(pud, address);
33068 set_pte_atomic((pte_t *)pmd, pte);
33069 }
33070 }
33071 #endif
33072+ pax_close_kernel();
33073 }
33074
33075 static int
33076diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33077index 6574388..87e9bef 100644
33078--- a/arch/x86/mm/pat.c
33079+++ b/arch/x86/mm/pat.c
33080@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33081
33082 if (!entry) {
33083 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33084- current->comm, current->pid, start, end - 1);
33085+ current->comm, task_pid_nr(current), start, end - 1);
33086 return -EINVAL;
33087 }
33088
33089@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33090
33091 while (cursor < to) {
33092 if (!devmem_is_allowed(pfn)) {
33093- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33094- current->comm, from, to - 1);
33095+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33096+ current->comm, from, to - 1, cursor);
33097 return 0;
33098 }
33099 cursor += PAGE_SIZE;
33100@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33101 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33102 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33103 "for [mem %#010Lx-%#010Lx]\n",
33104- current->comm, current->pid,
33105+ current->comm, task_pid_nr(current),
33106 cattr_name(flags),
33107 base, (unsigned long long)(base + size-1));
33108 return -EINVAL;
33109@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33110 flags = lookup_memtype(paddr);
33111 if (want_flags != flags) {
33112 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33113- current->comm, current->pid,
33114+ current->comm, task_pid_nr(current),
33115 cattr_name(want_flags),
33116 (unsigned long long)paddr,
33117 (unsigned long long)(paddr + size - 1),
33118@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33119 free_memtype(paddr, paddr + size);
33120 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33121 " for [mem %#010Lx-%#010Lx], got %s\n",
33122- current->comm, current->pid,
33123+ current->comm, task_pid_nr(current),
33124 cattr_name(want_flags),
33125 (unsigned long long)paddr,
33126 (unsigned long long)(paddr + size - 1),
33127diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33128index 415f6c4..d319983 100644
33129--- a/arch/x86/mm/pat_rbtree.c
33130+++ b/arch/x86/mm/pat_rbtree.c
33131@@ -160,7 +160,7 @@ success:
33132
33133 failure:
33134 printk(KERN_INFO "%s:%d conflicting memory types "
33135- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33136+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33137 end, cattr_name(found_type), cattr_name(match->type));
33138 return -EBUSY;
33139 }
33140diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33141index 9f0614d..92ae64a 100644
33142--- a/arch/x86/mm/pf_in.c
33143+++ b/arch/x86/mm/pf_in.c
33144@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33145 int i;
33146 enum reason_type rv = OTHERS;
33147
33148- p = (unsigned char *)ins_addr;
33149+ p = (unsigned char *)ktla_ktva(ins_addr);
33150 p += skip_prefix(p, &prf);
33151 p += get_opcode(p, &opcode);
33152
33153@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33154 struct prefix_bits prf;
33155 int i;
33156
33157- p = (unsigned char *)ins_addr;
33158+ p = (unsigned char *)ktla_ktva(ins_addr);
33159 p += skip_prefix(p, &prf);
33160 p += get_opcode(p, &opcode);
33161
33162@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33163 struct prefix_bits prf;
33164 int i;
33165
33166- p = (unsigned char *)ins_addr;
33167+ p = (unsigned char *)ktla_ktva(ins_addr);
33168 p += skip_prefix(p, &prf);
33169 p += get_opcode(p, &opcode);
33170
33171@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33172 struct prefix_bits prf;
33173 int i;
33174
33175- p = (unsigned char *)ins_addr;
33176+ p = (unsigned char *)ktla_ktva(ins_addr);
33177 p += skip_prefix(p, &prf);
33178 p += get_opcode(p, &opcode);
33179 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33180@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33181 struct prefix_bits prf;
33182 int i;
33183
33184- p = (unsigned char *)ins_addr;
33185+ p = (unsigned char *)ktla_ktva(ins_addr);
33186 p += skip_prefix(p, &prf);
33187 p += get_opcode(p, &opcode);
33188 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33189diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33190index c96314a..433b127 100644
33191--- a/arch/x86/mm/pgtable.c
33192+++ b/arch/x86/mm/pgtable.c
33193@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33194 list_del(&page->lru);
33195 }
33196
33197-#define UNSHARED_PTRS_PER_PGD \
33198- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33199+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33200+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33201
33202+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33203+{
33204+ unsigned int count = USER_PGD_PTRS;
33205
33206+ if (!pax_user_shadow_base)
33207+ return;
33208+
33209+ while (count--)
33210+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33211+}
33212+#endif
33213+
33214+#ifdef CONFIG_PAX_PER_CPU_PGD
33215+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33216+{
33217+ unsigned int count = USER_PGD_PTRS;
33218+
33219+ while (count--) {
33220+ pgd_t pgd;
33221+
33222+#ifdef CONFIG_X86_64
33223+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33224+#else
33225+ pgd = *src++;
33226+#endif
33227+
33228+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33229+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33230+#endif
33231+
33232+ *dst++ = pgd;
33233+ }
33234+
33235+}
33236+#endif
33237+
33238+#ifdef CONFIG_X86_64
33239+#define pxd_t pud_t
33240+#define pyd_t pgd_t
33241+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33242+#define pgtable_pxd_page_ctor(page) true
33243+#define pgtable_pxd_page_dtor(page)
33244+#define pxd_free(mm, pud) pud_free((mm), (pud))
33245+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33246+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33247+#define PYD_SIZE PGDIR_SIZE
33248+#else
33249+#define pxd_t pmd_t
33250+#define pyd_t pud_t
33251+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33252+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33253+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33254+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33255+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33256+#define pyd_offset(mm, address) pud_offset((mm), (address))
33257+#define PYD_SIZE PUD_SIZE
33258+#endif
33259+
33260+#ifdef CONFIG_PAX_PER_CPU_PGD
33261+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33262+static inline void pgd_dtor(pgd_t *pgd) {}
33263+#else
33264 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33265 {
33266 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33267@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33268 pgd_list_del(pgd);
33269 spin_unlock(&pgd_lock);
33270 }
33271+#endif
33272
33273 /*
33274 * List of all pgd's needed for non-PAE so it can invalidate entries
33275@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33276 * -- nyc
33277 */
33278
33279-#ifdef CONFIG_X86_PAE
33280+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33281 /*
33282 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33283 * updating the top-level pagetable entries to guarantee the
33284@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33285 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33286 * and initialize the kernel pmds here.
33287 */
33288-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33289+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33290
33291 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33292 {
33293@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33294 */
33295 flush_tlb_mm(mm);
33296 }
33297+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33298+#define PREALLOCATED_PXDS USER_PGD_PTRS
33299 #else /* !CONFIG_X86_PAE */
33300
33301 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33302-#define PREALLOCATED_PMDS 0
33303+#define PREALLOCATED_PXDS 0
33304
33305 #endif /* CONFIG_X86_PAE */
33306
33307-static void free_pmds(pmd_t *pmds[])
33308+static void free_pxds(pxd_t *pxds[])
33309 {
33310 int i;
33311
33312- for(i = 0; i < PREALLOCATED_PMDS; i++)
33313- if (pmds[i]) {
33314- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33315- free_page((unsigned long)pmds[i]);
33316+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33317+ if (pxds[i]) {
33318+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33319+ free_page((unsigned long)pxds[i]);
33320 }
33321 }
33322
33323-static int preallocate_pmds(pmd_t *pmds[])
33324+static int preallocate_pxds(pxd_t *pxds[])
33325 {
33326 int i;
33327 bool failed = false;
33328
33329- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33330- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33331- if (!pmd)
33332+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33333+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33334+ if (!pxd)
33335 failed = true;
33336- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33337- free_page((unsigned long)pmd);
33338- pmd = NULL;
33339+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33340+ free_page((unsigned long)pxd);
33341+ pxd = NULL;
33342 failed = true;
33343 }
33344- pmds[i] = pmd;
33345+ pxds[i] = pxd;
33346 }
33347
33348 if (failed) {
33349- free_pmds(pmds);
33350+ free_pxds(pxds);
33351 return -ENOMEM;
33352 }
33353
33354@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33355 * preallocate which never got a corresponding vma will need to be
33356 * freed manually.
33357 */
33358-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33359+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33360 {
33361 int i;
33362
33363- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33364+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33365 pgd_t pgd = pgdp[i];
33366
33367 if (pgd_val(pgd) != 0) {
33368- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33369+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33370
33371- pgdp[i] = native_make_pgd(0);
33372+ set_pgd(pgdp + i, native_make_pgd(0));
33373
33374- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33375- pmd_free(mm, pmd);
33376+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33377+ pxd_free(mm, pxd);
33378 }
33379 }
33380 }
33381
33382-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33383+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33384 {
33385- pud_t *pud;
33386+ pyd_t *pyd;
33387 int i;
33388
33389- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33390+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33391 return;
33392
33393- pud = pud_offset(pgd, 0);
33394-
33395- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33396- pmd_t *pmd = pmds[i];
33397+#ifdef CONFIG_X86_64
33398+ pyd = pyd_offset(mm, 0L);
33399+#else
33400+ pyd = pyd_offset(pgd, 0L);
33401+#endif
33402
33403+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33404+ pxd_t *pxd = pxds[i];
33405 if (i >= KERNEL_PGD_BOUNDARY)
33406- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33407- sizeof(pmd_t) * PTRS_PER_PMD);
33408+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33409+ sizeof(pxd_t) * PTRS_PER_PMD);
33410
33411- pud_populate(mm, pud, pmd);
33412+ pyd_populate(mm, pyd, pxd);
33413 }
33414 }
33415
33416 pgd_t *pgd_alloc(struct mm_struct *mm)
33417 {
33418 pgd_t *pgd;
33419- pmd_t *pmds[PREALLOCATED_PMDS];
33420+ pxd_t *pxds[PREALLOCATED_PXDS];
33421
33422 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33423
33424@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33425
33426 mm->pgd = pgd;
33427
33428- if (preallocate_pmds(pmds) != 0)
33429+ if (preallocate_pxds(pxds) != 0)
33430 goto out_free_pgd;
33431
33432 if (paravirt_pgd_alloc(mm) != 0)
33433- goto out_free_pmds;
33434+ goto out_free_pxds;
33435
33436 /*
33437 * Make sure that pre-populating the pmds is atomic with
33438@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33439 spin_lock(&pgd_lock);
33440
33441 pgd_ctor(mm, pgd);
33442- pgd_prepopulate_pmd(mm, pgd, pmds);
33443+ pgd_prepopulate_pxd(mm, pgd, pxds);
33444
33445 spin_unlock(&pgd_lock);
33446
33447 return pgd;
33448
33449-out_free_pmds:
33450- free_pmds(pmds);
33451+out_free_pxds:
33452+ free_pxds(pxds);
33453 out_free_pgd:
33454 free_page((unsigned long)pgd);
33455 out:
33456@@ -313,7 +380,7 @@ out:
33457
33458 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33459 {
33460- pgd_mop_up_pmds(mm, pgd);
33461+ pgd_mop_up_pxds(mm, pgd);
33462 pgd_dtor(pgd);
33463 paravirt_pgd_free(mm, pgd);
33464 free_page((unsigned long)pgd);
33465diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33466index a69bcb8..19068ab 100644
33467--- a/arch/x86/mm/pgtable_32.c
33468+++ b/arch/x86/mm/pgtable_32.c
33469@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33470 return;
33471 }
33472 pte = pte_offset_kernel(pmd, vaddr);
33473+
33474+ pax_open_kernel();
33475 if (pte_val(pteval))
33476 set_pte_at(&init_mm, vaddr, pte, pteval);
33477 else
33478 pte_clear(&init_mm, vaddr, pte);
33479+ pax_close_kernel();
33480
33481 /*
33482 * It's enough to flush this one mapping.
33483diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33484index e666cbb..61788c45 100644
33485--- a/arch/x86/mm/physaddr.c
33486+++ b/arch/x86/mm/physaddr.c
33487@@ -10,7 +10,7 @@
33488 #ifdef CONFIG_X86_64
33489
33490 #ifdef CONFIG_DEBUG_VIRTUAL
33491-unsigned long __phys_addr(unsigned long x)
33492+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33493 {
33494 unsigned long y = x - __START_KERNEL_map;
33495
33496@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33497 #else
33498
33499 #ifdef CONFIG_DEBUG_VIRTUAL
33500-unsigned long __phys_addr(unsigned long x)
33501+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33502 {
33503 unsigned long phys_addr = x - PAGE_OFFSET;
33504 /* VMALLOC_* aren't constants */
33505diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33506index 90555bf..f5f1828 100644
33507--- a/arch/x86/mm/setup_nx.c
33508+++ b/arch/x86/mm/setup_nx.c
33509@@ -5,8 +5,10 @@
33510 #include <asm/pgtable.h>
33511 #include <asm/proto.h>
33512
33513+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33514 static int disable_nx;
33515
33516+#ifndef CONFIG_PAX_PAGEEXEC
33517 /*
33518 * noexec = on|off
33519 *
33520@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33521 return 0;
33522 }
33523 early_param("noexec", noexec_setup);
33524+#endif
33525+
33526+#endif
33527
33528 void x86_configure_nx(void)
33529 {
33530+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33531 if (cpu_has_nx && !disable_nx)
33532 __supported_pte_mask |= _PAGE_NX;
33533 else
33534+#endif
33535 __supported_pte_mask &= ~_PAGE_NX;
33536 }
33537
33538diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33539index dd8dda1..9e9b0f6 100644
33540--- a/arch/x86/mm/tlb.c
33541+++ b/arch/x86/mm/tlb.c
33542@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33543 BUG();
33544 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33545 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33546+
33547+#ifndef CONFIG_PAX_PER_CPU_PGD
33548 load_cr3(swapper_pg_dir);
33549+#endif
33550+
33551 }
33552 }
33553 EXPORT_SYMBOL_GPL(leave_mm);
33554diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33555new file mode 100644
33556index 0000000..dace51c
33557--- /dev/null
33558+++ b/arch/x86/mm/uderef_64.c
33559@@ -0,0 +1,37 @@
33560+#include <linux/mm.h>
33561+#include <asm/pgtable.h>
33562+#include <asm/uaccess.h>
33563+
33564+#ifdef CONFIG_PAX_MEMORY_UDEREF
33565+/* PaX: due to the special call convention these functions must
33566+ * - remain leaf functions under all configurations,
33567+ * - never be called directly, only dereferenced from the wrappers.
33568+ */
33569+void __pax_open_userland(void)
33570+{
33571+ unsigned int cpu;
33572+
33573+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33574+ return;
33575+
33576+ cpu = raw_get_cpu();
33577+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33578+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33579+ raw_put_cpu_no_resched();
33580+}
33581+EXPORT_SYMBOL(__pax_open_userland);
33582+
33583+void __pax_close_userland(void)
33584+{
33585+ unsigned int cpu;
33586+
33587+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33588+ return;
33589+
33590+ cpu = raw_get_cpu();
33591+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33592+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33593+ raw_put_cpu_no_resched();
33594+}
33595+EXPORT_SYMBOL(__pax_close_userland);
33596+#endif
33597diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33598index 0149575..f746de8 100644
33599--- a/arch/x86/net/bpf_jit.S
33600+++ b/arch/x86/net/bpf_jit.S
33601@@ -9,6 +9,7 @@
33602 */
33603 #include <linux/linkage.h>
33604 #include <asm/dwarf2.h>
33605+#include <asm/alternative-asm.h>
33606
33607 /*
33608 * Calling convention :
33609@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33610 jle bpf_slow_path_word
33611 mov (SKBDATA,%rsi),%eax
33612 bswap %eax /* ntohl() */
33613+ pax_force_retaddr
33614 ret
33615
33616 sk_load_half:
33617@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33618 jle bpf_slow_path_half
33619 movzwl (SKBDATA,%rsi),%eax
33620 rol $8,%ax # ntohs()
33621+ pax_force_retaddr
33622 ret
33623
33624 sk_load_byte:
33625@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33626 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33627 jle bpf_slow_path_byte
33628 movzbl (SKBDATA,%rsi),%eax
33629+ pax_force_retaddr
33630 ret
33631
33632 /**
33633@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33634 movzbl (SKBDATA,%rsi),%ebx
33635 and $15,%bl
33636 shl $2,%bl
33637+ pax_force_retaddr
33638 ret
33639
33640 /* rsi contains offset and can be scratched */
33641@@ -109,6 +114,7 @@ bpf_slow_path_word:
33642 js bpf_error
33643 mov -12(%rbp),%eax
33644 bswap %eax
33645+ pax_force_retaddr
33646 ret
33647
33648 bpf_slow_path_half:
33649@@ -117,12 +123,14 @@ bpf_slow_path_half:
33650 mov -12(%rbp),%ax
33651 rol $8,%ax
33652 movzwl %ax,%eax
33653+ pax_force_retaddr
33654 ret
33655
33656 bpf_slow_path_byte:
33657 bpf_slow_path_common(1)
33658 js bpf_error
33659 movzbl -12(%rbp),%eax
33660+ pax_force_retaddr
33661 ret
33662
33663 bpf_slow_path_byte_msh:
33664@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33665 and $15,%al
33666 shl $2,%al
33667 xchg %eax,%ebx
33668+ pax_force_retaddr
33669 ret
33670
33671 #define sk_negative_common(SIZE) \
33672@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33673 sk_negative_common(4)
33674 mov (%rax), %eax
33675 bswap %eax
33676+ pax_force_retaddr
33677 ret
33678
33679 bpf_slow_path_half_neg:
33680@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33681 mov (%rax),%ax
33682 rol $8,%ax
33683 movzwl %ax,%eax
33684+ pax_force_retaddr
33685 ret
33686
33687 bpf_slow_path_byte_neg:
33688@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33689 .globl sk_load_byte_negative_offset
33690 sk_negative_common(1)
33691 movzbl (%rax), %eax
33692+ pax_force_retaddr
33693 ret
33694
33695 bpf_slow_path_byte_msh_neg:
33696@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33697 and $15,%al
33698 shl $2,%al
33699 xchg %eax,%ebx
33700+ pax_force_retaddr
33701 ret
33702
33703 bpf_error:
33704@@ -197,4 +210,5 @@ bpf_error:
33705 xor %eax,%eax
33706 mov -8(%rbp),%rbx
33707 leaveq
33708+ pax_force_retaddr
33709 ret
33710diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33711index 4ed75dd..3cf24f0b 100644
33712--- a/arch/x86/net/bpf_jit_comp.c
33713+++ b/arch/x86/net/bpf_jit_comp.c
33714@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33715 return ptr + len;
33716 }
33717
33718+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33719+#define MAX_INSTR_CODE_SIZE 96
33720+#else
33721+#define MAX_INSTR_CODE_SIZE 64
33722+#endif
33723+
33724 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33725
33726 #define EMIT1(b1) EMIT(b1, 1)
33727 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33728 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33729 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33730+
33731+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33732+/* original constant will appear in ecx */
33733+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33734+do { \
33735+ /* mov ecx, randkey */ \
33736+ EMIT1(0xb9); \
33737+ EMIT(_key, 4); \
33738+ /* xor ecx, randkey ^ off */ \
33739+ EMIT2(0x81, 0xf1); \
33740+ EMIT((_key) ^ (_off), 4); \
33741+} while (0)
33742+
33743+#define EMIT1_off32(b1, _off) \
33744+do { \
33745+ switch (b1) { \
33746+ case 0x05: /* add eax, imm32 */ \
33747+ case 0x2d: /* sub eax, imm32 */ \
33748+ case 0x25: /* and eax, imm32 */ \
33749+ case 0x0d: /* or eax, imm32 */ \
33750+ case 0xb8: /* mov eax, imm32 */ \
33751+ case 0x35: /* xor eax, imm32 */ \
33752+ case 0x3d: /* cmp eax, imm32 */ \
33753+ case 0xa9: /* test eax, imm32 */ \
33754+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33755+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33756+ break; \
33757+ case 0xbb: /* mov ebx, imm32 */ \
33758+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33759+ /* mov ebx, ecx */ \
33760+ EMIT2(0x89, 0xcb); \
33761+ break; \
33762+ case 0xbe: /* mov esi, imm32 */ \
33763+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33764+ /* mov esi, ecx */ \
33765+ EMIT2(0x89, 0xce); \
33766+ break; \
33767+ case 0xe8: /* call rel imm32, always to known funcs */ \
33768+ EMIT1(b1); \
33769+ EMIT(_off, 4); \
33770+ break; \
33771+ case 0xe9: /* jmp rel imm32 */ \
33772+ EMIT1(b1); \
33773+ EMIT(_off, 4); \
33774+ /* prevent fall-through, we're not called if off = 0 */ \
33775+ EMIT(0xcccccccc, 4); \
33776+ EMIT(0xcccccccc, 4); \
33777+ break; \
33778+ default: \
33779+ BUILD_BUG(); \
33780+ } \
33781+} while (0)
33782+
33783+#define EMIT2_off32(b1, b2, _off) \
33784+do { \
33785+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33786+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33787+ EMIT(randkey, 4); \
33788+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33789+ EMIT((_off) - randkey, 4); \
33790+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33791+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33792+ /* imul eax, ecx */ \
33793+ EMIT3(0x0f, 0xaf, 0xc1); \
33794+ } else { \
33795+ BUILD_BUG(); \
33796+ } \
33797+} while (0)
33798+#else
33799 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33800+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33801+#endif
33802
33803 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33804 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33805@@ -91,6 +168,24 @@ do { \
33806 #define X86_JBE 0x76
33807 #define X86_JA 0x77
33808
33809+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33810+#define APPEND_FLOW_VERIFY() \
33811+do { \
33812+ /* mov ecx, randkey */ \
33813+ EMIT1(0xb9); \
33814+ EMIT(randkey, 4); \
33815+ /* cmp ecx, randkey */ \
33816+ EMIT2(0x81, 0xf9); \
33817+ EMIT(randkey, 4); \
33818+ /* jz after 8 int 3s */ \
33819+ EMIT2(0x74, 0x08); \
33820+ EMIT(0xcccccccc, 4); \
33821+ EMIT(0xcccccccc, 4); \
33822+} while (0)
33823+#else
33824+#define APPEND_FLOW_VERIFY() do { } while (0)
33825+#endif
33826+
33827 #define EMIT_COND_JMP(op, offset) \
33828 do { \
33829 if (is_near(offset)) \
33830@@ -98,6 +193,7 @@ do { \
33831 else { \
33832 EMIT2(0x0f, op + 0x10); \
33833 EMIT(offset, 4); /* jxx .+off32 */ \
33834+ APPEND_FLOW_VERIFY(); \
33835 } \
33836 } while (0)
33837
33838@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33839 return -1;
33840 }
33841
33842-struct bpf_binary_header {
33843- unsigned int pages;
33844- /* Note : for security reasons, bpf code will follow a randomly
33845- * sized amount of int3 instructions
33846- */
33847- u8 image[];
33848-};
33849-
33850-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33851+/* Note : for security reasons, bpf code will follow a randomly
33852+ * sized amount of int3 instructions
33853+ */
33854+static u8 *bpf_alloc_binary(unsigned int proglen,
33855 u8 **image_ptr)
33856 {
33857 unsigned int sz, hole;
33858- struct bpf_binary_header *header;
33859+ u8 *header;
33860
33861 /* Most of BPF filters are really small,
33862 * but if some of them fill a page, allow at least
33863 * 128 extra bytes to insert a random section of int3
33864 */
33865- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33866- header = module_alloc(sz);
33867+ sz = round_up(proglen + 128, PAGE_SIZE);
33868+ header = module_alloc_exec(sz);
33869 if (!header)
33870 return NULL;
33871
33872+ pax_open_kernel();
33873 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33874+ pax_close_kernel();
33875
33876- header->pages = sz / PAGE_SIZE;
33877- hole = sz - (proglen + sizeof(*header));
33878+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33879
33880 /* insert a random number of int3 instructions before BPF code */
33881- *image_ptr = &header->image[prandom_u32() % hole];
33882+ *image_ptr = &header[prandom_u32() % hole];
33883 return header;
33884 }
33885
33886 void bpf_jit_compile(struct sk_filter *fp)
33887 {
33888- u8 temp[64];
33889+ u8 temp[MAX_INSTR_CODE_SIZE];
33890 u8 *prog;
33891 unsigned int proglen, oldproglen = 0;
33892 int ilen, i;
33893 int t_offset, f_offset;
33894 u8 t_op, f_op, seen = 0, pass;
33895 u8 *image = NULL;
33896- struct bpf_binary_header *header = NULL;
33897+ u8 *header = NULL;
33898 u8 *func;
33899 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33900 unsigned int cleanup_addr; /* epilogue code offset */
33901 unsigned int *addrs;
33902 const struct sock_filter *filter = fp->insns;
33903 int flen = fp->len;
33904+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33905+ unsigned int randkey;
33906+#endif
33907
33908 if (!bpf_jit_enable)
33909 return;
33910@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33911 return;
33912
33913 /* Before first pass, make a rough estimation of addrs[]
33914- * each bpf instruction is translated to less than 64 bytes
33915+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33916 */
33917 for (proglen = 0, i = 0; i < flen; i++) {
33918- proglen += 64;
33919+ proglen += MAX_INSTR_CODE_SIZE;
33920 addrs[i] = proglen;
33921 }
33922 cleanup_addr = proglen; /* epilogue address */
33923@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33924 for (i = 0; i < flen; i++) {
33925 unsigned int K = filter[i].k;
33926
33927+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33928+ randkey = prandom_u32();
33929+#endif
33930+
33931 switch (filter[i].code) {
33932 case BPF_S_ALU_ADD_X: /* A += X; */
33933 seen |= SEEN_XREG;
33934@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33935 case BPF_S_ALU_MUL_K: /* A *= K */
33936 if (is_imm8(K))
33937 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33938- else {
33939- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33940- EMIT(K, 4);
33941- }
33942+ else
33943+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33944 break;
33945 case BPF_S_ALU_DIV_X: /* A /= X; */
33946 seen |= SEEN_XREG;
33947@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33948 break;
33949 }
33950 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33951+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33952+ DILUTE_CONST_SEQUENCE(K, randkey);
33953+#else
33954 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33955+#endif
33956 EMIT2(0xf7, 0xf1); /* div %ecx */
33957 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33958 break;
33959@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33960 if (K == 1)
33961 break;
33962 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33963+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33964+ DILUTE_CONST_SEQUENCE(K, randkey);
33965+#else
33966 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33967+#endif
33968 EMIT2(0xf7, 0xf1); /* div %ecx */
33969 break;
33970 case BPF_S_ALU_AND_X:
33971@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33972 if (is_imm8(K)) {
33973 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33974 } else {
33975- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33976- EMIT(K, 4);
33977+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33978 }
33979 } else {
33980 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33981@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33982 if (unlikely(proglen + ilen > oldproglen)) {
33983 pr_err("bpb_jit_compile fatal error\n");
33984 kfree(addrs);
33985- module_free(NULL, header);
33986+ module_free_exec(NULL, image);
33987 return;
33988 }
33989+ pax_open_kernel();
33990 memcpy(image + proglen, temp, ilen);
33991+ pax_close_kernel();
33992 }
33993 proglen += ilen;
33994 addrs[i] = proglen;
33995@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33996
33997 if (image) {
33998 bpf_flush_icache(header, image + proglen);
33999- set_memory_ro((unsigned long)header, header->pages);
34000 fp->bpf_func = (void *)image;
34001 }
34002 out:
34003@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34004 {
34005 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34006 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34007- struct bpf_binary_header *header = (void *)addr;
34008
34009- set_memory_rw(addr, header->pages);
34010- module_free(NULL, header);
34011+ set_memory_rw(addr, 1);
34012+ module_free_exec(NULL, (void *)addr);
34013 kfree(fp);
34014 }
34015
34016diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34017index 5d04be5..2beeaa2 100644
34018--- a/arch/x86/oprofile/backtrace.c
34019+++ b/arch/x86/oprofile/backtrace.c
34020@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34021 struct stack_frame_ia32 *fp;
34022 unsigned long bytes;
34023
34024- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34025+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34026 if (bytes != 0)
34027 return NULL;
34028
34029- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34030+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34031
34032 oprofile_add_trace(bufhead[0].return_address);
34033
34034@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34035 struct stack_frame bufhead[2];
34036 unsigned long bytes;
34037
34038- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34039+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34040 if (bytes != 0)
34041 return NULL;
34042
34043@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34044 {
34045 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34046
34047- if (!user_mode_vm(regs)) {
34048+ if (!user_mode(regs)) {
34049 unsigned long stack = kernel_stack_pointer(regs);
34050 if (depth)
34051 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34052diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34053index 6890d84..1dad1f1 100644
34054--- a/arch/x86/oprofile/nmi_int.c
34055+++ b/arch/x86/oprofile/nmi_int.c
34056@@ -23,6 +23,7 @@
34057 #include <asm/nmi.h>
34058 #include <asm/msr.h>
34059 #include <asm/apic.h>
34060+#include <asm/pgtable.h>
34061
34062 #include "op_counter.h"
34063 #include "op_x86_model.h"
34064@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34065 if (ret)
34066 return ret;
34067
34068- if (!model->num_virt_counters)
34069- model->num_virt_counters = model->num_counters;
34070+ if (!model->num_virt_counters) {
34071+ pax_open_kernel();
34072+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34073+ pax_close_kernel();
34074+ }
34075
34076 mux_init(ops);
34077
34078diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34079index 50d86c0..7985318 100644
34080--- a/arch/x86/oprofile/op_model_amd.c
34081+++ b/arch/x86/oprofile/op_model_amd.c
34082@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34083 num_counters = AMD64_NUM_COUNTERS;
34084 }
34085
34086- op_amd_spec.num_counters = num_counters;
34087- op_amd_spec.num_controls = num_counters;
34088- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34089+ pax_open_kernel();
34090+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34091+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34092+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34093+ pax_close_kernel();
34094
34095 return 0;
34096 }
34097diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34098index d90528e..0127e2b 100644
34099--- a/arch/x86/oprofile/op_model_ppro.c
34100+++ b/arch/x86/oprofile/op_model_ppro.c
34101@@ -19,6 +19,7 @@
34102 #include <asm/msr.h>
34103 #include <asm/apic.h>
34104 #include <asm/nmi.h>
34105+#include <asm/pgtable.h>
34106
34107 #include "op_x86_model.h"
34108 #include "op_counter.h"
34109@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34110
34111 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34112
34113- op_arch_perfmon_spec.num_counters = num_counters;
34114- op_arch_perfmon_spec.num_controls = num_counters;
34115+ pax_open_kernel();
34116+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34117+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34118+ pax_close_kernel();
34119 }
34120
34121 static int arch_perfmon_init(struct oprofile_operations *ignore)
34122diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34123index 71e8a67..6a313bb 100644
34124--- a/arch/x86/oprofile/op_x86_model.h
34125+++ b/arch/x86/oprofile/op_x86_model.h
34126@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34127 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34128 struct op_msrs const * const msrs);
34129 #endif
34130-};
34131+} __do_const;
34132
34133 struct op_counter_config;
34134
34135diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34136index 84b9d67..260e5ff 100644
34137--- a/arch/x86/pci/intel_mid_pci.c
34138+++ b/arch/x86/pci/intel_mid_pci.c
34139@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34140 pr_info("Intel MID platform detected, using MID PCI ops\n");
34141 pci_mmcfg_late_init();
34142 pcibios_enable_irq = intel_mid_pci_irq_enable;
34143- pci_root_ops = intel_mid_pci_ops;
34144+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34145 pci_soc_mode = 1;
34146 /* Continue with standard init */
34147 return 1;
34148diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34149index 372e9b8..e775a6c 100644
34150--- a/arch/x86/pci/irq.c
34151+++ b/arch/x86/pci/irq.c
34152@@ -50,7 +50,7 @@ struct irq_router {
34153 struct irq_router_handler {
34154 u16 vendor;
34155 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34156-};
34157+} __do_const;
34158
34159 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34160 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34161@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34162 return 0;
34163 }
34164
34165-static __initdata struct irq_router_handler pirq_routers[] = {
34166+static __initconst const struct irq_router_handler pirq_routers[] = {
34167 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34168 { PCI_VENDOR_ID_AL, ali_router_probe },
34169 { PCI_VENDOR_ID_ITE, ite_router_probe },
34170@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34171 static void __init pirq_find_router(struct irq_router *r)
34172 {
34173 struct irq_routing_table *rt = pirq_table;
34174- struct irq_router_handler *h;
34175+ const struct irq_router_handler *h;
34176
34177 #ifdef CONFIG_PCI_BIOS
34178 if (!rt->signature) {
34179@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34180 return 0;
34181 }
34182
34183-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34184+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34185 {
34186 .callback = fix_broken_hp_bios_irq9,
34187 .ident = "HP Pavilion N5400 Series Laptop",
34188diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34189index c77b24a..c979855 100644
34190--- a/arch/x86/pci/pcbios.c
34191+++ b/arch/x86/pci/pcbios.c
34192@@ -79,7 +79,7 @@ union bios32 {
34193 static struct {
34194 unsigned long address;
34195 unsigned short segment;
34196-} bios32_indirect = { 0, __KERNEL_CS };
34197+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34198
34199 /*
34200 * Returns the entry point for the given service, NULL on error
34201@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34202 unsigned long length; /* %ecx */
34203 unsigned long entry; /* %edx */
34204 unsigned long flags;
34205+ struct desc_struct d, *gdt;
34206
34207 local_irq_save(flags);
34208- __asm__("lcall *(%%edi); cld"
34209+
34210+ gdt = get_cpu_gdt_table(smp_processor_id());
34211+
34212+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34213+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34214+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34215+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34216+
34217+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34218 : "=a" (return_code),
34219 "=b" (address),
34220 "=c" (length),
34221 "=d" (entry)
34222 : "0" (service),
34223 "1" (0),
34224- "D" (&bios32_indirect));
34225+ "D" (&bios32_indirect),
34226+ "r"(__PCIBIOS_DS)
34227+ : "memory");
34228+
34229+ pax_open_kernel();
34230+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34231+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34232+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34233+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34234+ pax_close_kernel();
34235+
34236 local_irq_restore(flags);
34237
34238 switch (return_code) {
34239- case 0:
34240- return address + entry;
34241- case 0x80: /* Not present */
34242- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34243- return 0;
34244- default: /* Shouldn't happen */
34245- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34246- service, return_code);
34247+ case 0: {
34248+ int cpu;
34249+ unsigned char flags;
34250+
34251+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34252+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34253+ printk(KERN_WARNING "bios32_service: not valid\n");
34254 return 0;
34255+ }
34256+ address = address + PAGE_OFFSET;
34257+ length += 16UL; /* some BIOSs underreport this... */
34258+ flags = 4;
34259+ if (length >= 64*1024*1024) {
34260+ length >>= PAGE_SHIFT;
34261+ flags |= 8;
34262+ }
34263+
34264+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34265+ gdt = get_cpu_gdt_table(cpu);
34266+ pack_descriptor(&d, address, length, 0x9b, flags);
34267+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34268+ pack_descriptor(&d, address, length, 0x93, flags);
34269+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34270+ }
34271+ return entry;
34272+ }
34273+ case 0x80: /* Not present */
34274+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34275+ return 0;
34276+ default: /* Shouldn't happen */
34277+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34278+ service, return_code);
34279+ return 0;
34280 }
34281 }
34282
34283 static struct {
34284 unsigned long address;
34285 unsigned short segment;
34286-} pci_indirect = { 0, __KERNEL_CS };
34287+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34288
34289-static int pci_bios_present;
34290+static int pci_bios_present __read_only;
34291
34292 static int check_pcibios(void)
34293 {
34294@@ -131,11 +174,13 @@ static int check_pcibios(void)
34295 unsigned long flags, pcibios_entry;
34296
34297 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34298- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34299+ pci_indirect.address = pcibios_entry;
34300
34301 local_irq_save(flags);
34302- __asm__(
34303- "lcall *(%%edi); cld\n\t"
34304+ __asm__("movw %w6, %%ds\n\t"
34305+ "lcall *%%ss:(%%edi); cld\n\t"
34306+ "push %%ss\n\t"
34307+ "pop %%ds\n\t"
34308 "jc 1f\n\t"
34309 "xor %%ah, %%ah\n"
34310 "1:"
34311@@ -144,7 +189,8 @@ static int check_pcibios(void)
34312 "=b" (ebx),
34313 "=c" (ecx)
34314 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34315- "D" (&pci_indirect)
34316+ "D" (&pci_indirect),
34317+ "r" (__PCIBIOS_DS)
34318 : "memory");
34319 local_irq_restore(flags);
34320
34321@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34322
34323 switch (len) {
34324 case 1:
34325- __asm__("lcall *(%%esi); cld\n\t"
34326+ __asm__("movw %w6, %%ds\n\t"
34327+ "lcall *%%ss:(%%esi); cld\n\t"
34328+ "push %%ss\n\t"
34329+ "pop %%ds\n\t"
34330 "jc 1f\n\t"
34331 "xor %%ah, %%ah\n"
34332 "1:"
34333@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34334 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34335 "b" (bx),
34336 "D" ((long)reg),
34337- "S" (&pci_indirect));
34338+ "S" (&pci_indirect),
34339+ "r" (__PCIBIOS_DS));
34340 /*
34341 * Zero-extend the result beyond 8 bits, do not trust the
34342 * BIOS having done it:
34343@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34344 *value &= 0xff;
34345 break;
34346 case 2:
34347- __asm__("lcall *(%%esi); cld\n\t"
34348+ __asm__("movw %w6, %%ds\n\t"
34349+ "lcall *%%ss:(%%esi); cld\n\t"
34350+ "push %%ss\n\t"
34351+ "pop %%ds\n\t"
34352 "jc 1f\n\t"
34353 "xor %%ah, %%ah\n"
34354 "1:"
34355@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34356 : "1" (PCIBIOS_READ_CONFIG_WORD),
34357 "b" (bx),
34358 "D" ((long)reg),
34359- "S" (&pci_indirect));
34360+ "S" (&pci_indirect),
34361+ "r" (__PCIBIOS_DS));
34362 /*
34363 * Zero-extend the result beyond 16 bits, do not trust the
34364 * BIOS having done it:
34365@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34366 *value &= 0xffff;
34367 break;
34368 case 4:
34369- __asm__("lcall *(%%esi); cld\n\t"
34370+ __asm__("movw %w6, %%ds\n\t"
34371+ "lcall *%%ss:(%%esi); cld\n\t"
34372+ "push %%ss\n\t"
34373+ "pop %%ds\n\t"
34374 "jc 1f\n\t"
34375 "xor %%ah, %%ah\n"
34376 "1:"
34377@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34378 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34379 "b" (bx),
34380 "D" ((long)reg),
34381- "S" (&pci_indirect));
34382+ "S" (&pci_indirect),
34383+ "r" (__PCIBIOS_DS));
34384 break;
34385 }
34386
34387@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34388
34389 switch (len) {
34390 case 1:
34391- __asm__("lcall *(%%esi); cld\n\t"
34392+ __asm__("movw %w6, %%ds\n\t"
34393+ "lcall *%%ss:(%%esi); cld\n\t"
34394+ "push %%ss\n\t"
34395+ "pop %%ds\n\t"
34396 "jc 1f\n\t"
34397 "xor %%ah, %%ah\n"
34398 "1:"
34399@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34400 "c" (value),
34401 "b" (bx),
34402 "D" ((long)reg),
34403- "S" (&pci_indirect));
34404+ "S" (&pci_indirect),
34405+ "r" (__PCIBIOS_DS));
34406 break;
34407 case 2:
34408- __asm__("lcall *(%%esi); cld\n\t"
34409+ __asm__("movw %w6, %%ds\n\t"
34410+ "lcall *%%ss:(%%esi); cld\n\t"
34411+ "push %%ss\n\t"
34412+ "pop %%ds\n\t"
34413 "jc 1f\n\t"
34414 "xor %%ah, %%ah\n"
34415 "1:"
34416@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34417 "c" (value),
34418 "b" (bx),
34419 "D" ((long)reg),
34420- "S" (&pci_indirect));
34421+ "S" (&pci_indirect),
34422+ "r" (__PCIBIOS_DS));
34423 break;
34424 case 4:
34425- __asm__("lcall *(%%esi); cld\n\t"
34426+ __asm__("movw %w6, %%ds\n\t"
34427+ "lcall *%%ss:(%%esi); cld\n\t"
34428+ "push %%ss\n\t"
34429+ "pop %%ds\n\t"
34430 "jc 1f\n\t"
34431 "xor %%ah, %%ah\n"
34432 "1:"
34433@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34434 "c" (value),
34435 "b" (bx),
34436 "D" ((long)reg),
34437- "S" (&pci_indirect));
34438+ "S" (&pci_indirect),
34439+ "r" (__PCIBIOS_DS));
34440 break;
34441 }
34442
34443@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34444
34445 DBG("PCI: Fetching IRQ routing table... ");
34446 __asm__("push %%es\n\t"
34447+ "movw %w8, %%ds\n\t"
34448 "push %%ds\n\t"
34449 "pop %%es\n\t"
34450- "lcall *(%%esi); cld\n\t"
34451+ "lcall *%%ss:(%%esi); cld\n\t"
34452 "pop %%es\n\t"
34453+ "push %%ss\n\t"
34454+ "pop %%ds\n"
34455 "jc 1f\n\t"
34456 "xor %%ah, %%ah\n"
34457 "1:"
34458@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34459 "1" (0),
34460 "D" ((long) &opt),
34461 "S" (&pci_indirect),
34462- "m" (opt)
34463+ "m" (opt),
34464+ "r" (__PCIBIOS_DS)
34465 : "memory");
34466 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34467 if (ret & 0xff00)
34468@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34469 {
34470 int ret;
34471
34472- __asm__("lcall *(%%esi); cld\n\t"
34473+ __asm__("movw %w5, %%ds\n\t"
34474+ "lcall *%%ss:(%%esi); cld\n\t"
34475+ "push %%ss\n\t"
34476+ "pop %%ds\n"
34477 "jc 1f\n\t"
34478 "xor %%ah, %%ah\n"
34479 "1:"
34480@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34481 : "0" (PCIBIOS_SET_PCI_HW_INT),
34482 "b" ((dev->bus->number << 8) | dev->devfn),
34483 "c" ((irq << 8) | (pin + 10)),
34484- "S" (&pci_indirect));
34485+ "S" (&pci_indirect),
34486+ "r" (__PCIBIOS_DS));
34487 return !(ret & 0xff00);
34488 }
34489 EXPORT_SYMBOL(pcibios_set_irq_routing);
34490diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34491index 9ee3491..872192f 100644
34492--- a/arch/x86/platform/efi/efi_32.c
34493+++ b/arch/x86/platform/efi/efi_32.c
34494@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34495 {
34496 struct desc_ptr gdt_descr;
34497
34498+#ifdef CONFIG_PAX_KERNEXEC
34499+ struct desc_struct d;
34500+#endif
34501+
34502 local_irq_save(efi_rt_eflags);
34503
34504 load_cr3(initial_page_table);
34505 __flush_tlb_all();
34506
34507+#ifdef CONFIG_PAX_KERNEXEC
34508+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34509+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34510+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34511+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34512+#endif
34513+
34514 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34515 gdt_descr.size = GDT_SIZE - 1;
34516 load_gdt(&gdt_descr);
34517@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34518 {
34519 struct desc_ptr gdt_descr;
34520
34521+#ifdef CONFIG_PAX_KERNEXEC
34522+ struct desc_struct d;
34523+
34524+ memset(&d, 0, sizeof d);
34525+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34526+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34527+#endif
34528+
34529 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34530 gdt_descr.size = GDT_SIZE - 1;
34531 load_gdt(&gdt_descr);
34532
34533+#ifdef CONFIG_PAX_PER_CPU_PGD
34534+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34535+#else
34536 load_cr3(swapper_pg_dir);
34537+#endif
34538+
34539 __flush_tlb_all();
34540
34541 local_irq_restore(efi_rt_eflags);
34542diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34543index 666b74a..673d88f 100644
34544--- a/arch/x86/platform/efi/efi_64.c
34545+++ b/arch/x86/platform/efi/efi_64.c
34546@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34547 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34548 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34549 }
34550+
34551+#ifdef CONFIG_PAX_PER_CPU_PGD
34552+ load_cr3(swapper_pg_dir);
34553+#endif
34554+
34555 __flush_tlb_all();
34556 }
34557
34558@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34559 for (pgd = 0; pgd < n_pgds; pgd++)
34560 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34561 kfree(save_pgd);
34562+
34563+#ifdef CONFIG_PAX_PER_CPU_PGD
34564+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34565+#endif
34566+
34567 __flush_tlb_all();
34568 local_irq_restore(efi_flags);
34569 early_code_mapping_set_exec(0);
34570diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34571index fbe66e6..eae5e38 100644
34572--- a/arch/x86/platform/efi/efi_stub_32.S
34573+++ b/arch/x86/platform/efi/efi_stub_32.S
34574@@ -6,7 +6,9 @@
34575 */
34576
34577 #include <linux/linkage.h>
34578+#include <linux/init.h>
34579 #include <asm/page_types.h>
34580+#include <asm/segment.h>
34581
34582 /*
34583 * efi_call_phys(void *, ...) is a function with variable parameters.
34584@@ -20,7 +22,7 @@
34585 * service functions will comply with gcc calling convention, too.
34586 */
34587
34588-.text
34589+__INIT
34590 ENTRY(efi_call_phys)
34591 /*
34592 * 0. The function can only be called in Linux kernel. So CS has been
34593@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34594 * The mapping of lower virtual memory has been created in prelog and
34595 * epilog.
34596 */
34597- movl $1f, %edx
34598- subl $__PAGE_OFFSET, %edx
34599- jmp *%edx
34600+#ifdef CONFIG_PAX_KERNEXEC
34601+ movl $(__KERNEXEC_EFI_DS), %edx
34602+ mov %edx, %ds
34603+ mov %edx, %es
34604+ mov %edx, %ss
34605+ addl $2f,(1f)
34606+ ljmp *(1f)
34607+
34608+__INITDATA
34609+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34610+.previous
34611+
34612+2:
34613+ subl $2b,(1b)
34614+#else
34615+ jmp 1f-__PAGE_OFFSET
34616 1:
34617+#endif
34618
34619 /*
34620 * 2. Now on the top of stack is the return
34621@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34622 * parameter 2, ..., param n. To make things easy, we save the return
34623 * address of efi_call_phys in a global variable.
34624 */
34625- popl %edx
34626- movl %edx, saved_return_addr
34627- /* get the function pointer into ECX*/
34628- popl %ecx
34629- movl %ecx, efi_rt_function_ptr
34630- movl $2f, %edx
34631- subl $__PAGE_OFFSET, %edx
34632- pushl %edx
34633+ popl (saved_return_addr)
34634+ popl (efi_rt_function_ptr)
34635
34636 /*
34637 * 3. Clear PG bit in %CR0.
34638@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34639 /*
34640 * 5. Call the physical function.
34641 */
34642- jmp *%ecx
34643+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34644
34645-2:
34646 /*
34647 * 6. After EFI runtime service returns, control will return to
34648 * following instruction. We'd better readjust stack pointer first.
34649@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34650 movl %cr0, %edx
34651 orl $0x80000000, %edx
34652 movl %edx, %cr0
34653- jmp 1f
34654-1:
34655+
34656 /*
34657 * 8. Now restore the virtual mode from flat mode by
34658 * adding EIP with PAGE_OFFSET.
34659 */
34660- movl $1f, %edx
34661- jmp *%edx
34662+#ifdef CONFIG_PAX_KERNEXEC
34663+ movl $(__KERNEL_DS), %edx
34664+ mov %edx, %ds
34665+ mov %edx, %es
34666+ mov %edx, %ss
34667+ ljmp $(__KERNEL_CS),$1f
34668+#else
34669+ jmp 1f+__PAGE_OFFSET
34670+#endif
34671 1:
34672
34673 /*
34674 * 9. Balance the stack. And because EAX contain the return value,
34675 * we'd better not clobber it.
34676 */
34677- leal efi_rt_function_ptr, %edx
34678- movl (%edx), %ecx
34679- pushl %ecx
34680+ pushl (efi_rt_function_ptr)
34681
34682 /*
34683- * 10. Push the saved return address onto the stack and return.
34684+ * 10. Return to the saved return address.
34685 */
34686- leal saved_return_addr, %edx
34687- movl (%edx), %ecx
34688- pushl %ecx
34689- ret
34690+ jmpl *(saved_return_addr)
34691 ENDPROC(efi_call_phys)
34692 .previous
34693
34694-.data
34695+__INITDATA
34696 saved_return_addr:
34697 .long 0
34698 efi_rt_function_ptr:
34699diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34700index 88073b1..1cc2f53 100644
34701--- a/arch/x86/platform/efi/efi_stub_64.S
34702+++ b/arch/x86/platform/efi/efi_stub_64.S
34703@@ -7,6 +7,7 @@
34704 */
34705
34706 #include <linux/linkage.h>
34707+#include <asm/alternative-asm.h>
34708
34709 #define SAVE_XMM \
34710 mov %rsp, %rax; \
34711@@ -77,6 +78,7 @@ ENTRY(efi_call0)
34712 RESTORE_PGT
34713 addq $32, %rsp
34714 RESTORE_XMM
34715+ pax_force_retaddr 0, 1
34716 ret
34717 ENDPROC(efi_call0)
34718
34719@@ -89,6 +91,7 @@ ENTRY(efi_call1)
34720 RESTORE_PGT
34721 addq $32, %rsp
34722 RESTORE_XMM
34723+ pax_force_retaddr 0, 1
34724 ret
34725 ENDPROC(efi_call1)
34726
34727@@ -101,6 +104,7 @@ ENTRY(efi_call2)
34728 RESTORE_PGT
34729 addq $32, %rsp
34730 RESTORE_XMM
34731+ pax_force_retaddr 0, 1
34732 ret
34733 ENDPROC(efi_call2)
34734
34735@@ -114,6 +118,7 @@ ENTRY(efi_call3)
34736 RESTORE_PGT
34737 addq $32, %rsp
34738 RESTORE_XMM
34739+ pax_force_retaddr 0, 1
34740 ret
34741 ENDPROC(efi_call3)
34742
34743@@ -128,6 +133,7 @@ ENTRY(efi_call4)
34744 RESTORE_PGT
34745 addq $32, %rsp
34746 RESTORE_XMM
34747+ pax_force_retaddr 0, 1
34748 ret
34749 ENDPROC(efi_call4)
34750
34751@@ -143,6 +149,7 @@ ENTRY(efi_call5)
34752 RESTORE_PGT
34753 addq $48, %rsp
34754 RESTORE_XMM
34755+ pax_force_retaddr 0, 1
34756 ret
34757 ENDPROC(efi_call5)
34758
34759@@ -161,6 +168,7 @@ ENTRY(efi_call6)
34760 RESTORE_PGT
34761 addq $48, %rsp
34762 RESTORE_XMM
34763+ pax_force_retaddr 0, 1
34764 ret
34765 ENDPROC(efi_call6)
34766
34767diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34768index 1bbedc4..eb795b5 100644
34769--- a/arch/x86/platform/intel-mid/intel-mid.c
34770+++ b/arch/x86/platform/intel-mid/intel-mid.c
34771@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34772 {
34773 };
34774
34775-static void intel_mid_reboot(void)
34776+static void __noreturn intel_mid_reboot(void)
34777 {
34778 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34779+ BUG();
34780 }
34781
34782 static unsigned long __init intel_mid_calibrate_tsc(void)
34783diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34784index d6ee929..3637cb5 100644
34785--- a/arch/x86/platform/olpc/olpc_dt.c
34786+++ b/arch/x86/platform/olpc/olpc_dt.c
34787@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34788 return res;
34789 }
34790
34791-static struct of_pdt_ops prom_olpc_ops __initdata = {
34792+static struct of_pdt_ops prom_olpc_ops __initconst = {
34793 .nextprop = olpc_dt_nextprop,
34794 .getproplen = olpc_dt_getproplen,
34795 .getproperty = olpc_dt_getproperty,
34796diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34797index 424f4c9..f2a2988 100644
34798--- a/arch/x86/power/cpu.c
34799+++ b/arch/x86/power/cpu.c
34800@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34801 static void fix_processor_context(void)
34802 {
34803 int cpu = smp_processor_id();
34804- struct tss_struct *t = &per_cpu(init_tss, cpu);
34805-#ifdef CONFIG_X86_64
34806- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34807- tss_desc tss;
34808-#endif
34809+ struct tss_struct *t = init_tss + cpu;
34810+
34811 set_tss_desc(cpu, t); /*
34812 * This just modifies memory; should not be
34813 * necessary. But... This is necessary, because
34814@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34815 */
34816
34817 #ifdef CONFIG_X86_64
34818- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34819- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34820- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34821-
34822 syscall_init(); /* This sets MSR_*STAR and related */
34823 #endif
34824 load_TR_desc(); /* This does ltr */
34825diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34826index bad628a..a102610 100644
34827--- a/arch/x86/realmode/init.c
34828+++ b/arch/x86/realmode/init.c
34829@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34830 __va(real_mode_header->trampoline_header);
34831
34832 #ifdef CONFIG_X86_32
34833- trampoline_header->start = __pa_symbol(startup_32_smp);
34834+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34835+
34836+#ifdef CONFIG_PAX_KERNEXEC
34837+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34838+#endif
34839+
34840+ trampoline_header->boot_cs = __BOOT_CS;
34841 trampoline_header->gdt_limit = __BOOT_DS + 7;
34842 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34843 #else
34844@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34845 *trampoline_cr4_features = read_cr4();
34846
34847 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34848- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34849+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34850 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34851 #endif
34852 }
34853diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34854index 3497f14..cc73b92 100644
34855--- a/arch/x86/realmode/rm/Makefile
34856+++ b/arch/x86/realmode/rm/Makefile
34857@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34858
34859 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34860 -I$(srctree)/arch/x86/boot
34861+ifdef CONSTIFY_PLUGIN
34862+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34863+endif
34864 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34865 GCOV_PROFILE := n
34866diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34867index a28221d..93c40f1 100644
34868--- a/arch/x86/realmode/rm/header.S
34869+++ b/arch/x86/realmode/rm/header.S
34870@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34871 #endif
34872 /* APM/BIOS reboot */
34873 .long pa_machine_real_restart_asm
34874-#ifdef CONFIG_X86_64
34875+#ifdef CONFIG_X86_32
34876+ .long __KERNEL_CS
34877+#else
34878 .long __KERNEL32_CS
34879 #endif
34880 END(real_mode_header)
34881diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34882index 48ddd76..c26749f 100644
34883--- a/arch/x86/realmode/rm/trampoline_32.S
34884+++ b/arch/x86/realmode/rm/trampoline_32.S
34885@@ -24,6 +24,12 @@
34886 #include <asm/page_types.h>
34887 #include "realmode.h"
34888
34889+#ifdef CONFIG_PAX_KERNEXEC
34890+#define ta(X) (X)
34891+#else
34892+#define ta(X) (pa_ ## X)
34893+#endif
34894+
34895 .text
34896 .code16
34897
34898@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
34899
34900 cli # We should be safe anyway
34901
34902- movl tr_start, %eax # where we need to go
34903-
34904 movl $0xA5A5A5A5, trampoline_status
34905 # write marker for master knows we're running
34906
34907@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
34908 movw $1, %dx # protected mode (PE) bit
34909 lmsw %dx # into protected mode
34910
34911- ljmpl $__BOOT_CS, $pa_startup_32
34912+ ljmpl *(trampoline_header)
34913
34914 .section ".text32","ax"
34915 .code32
34916@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34917 .balign 8
34918 GLOBAL(trampoline_header)
34919 tr_start: .space 4
34920- tr_gdt_pad: .space 2
34921+ tr_boot_cs: .space 2
34922 tr_gdt: .space 6
34923 END(trampoline_header)
34924
34925diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34926index dac7b20..72dbaca 100644
34927--- a/arch/x86/realmode/rm/trampoline_64.S
34928+++ b/arch/x86/realmode/rm/trampoline_64.S
34929@@ -93,6 +93,7 @@ ENTRY(startup_32)
34930 movl %edx, %gs
34931
34932 movl pa_tr_cr4, %eax
34933+ andl $~X86_CR4_PCIDE, %eax
34934 movl %eax, %cr4 # Enable PAE mode
34935
34936 # Setup trampoline 4 level pagetables
34937@@ -106,7 +107,7 @@ ENTRY(startup_32)
34938 wrmsr
34939
34940 # Enable paging and in turn activate Long Mode
34941- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34942+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34943 movl %eax, %cr0
34944
34945 /*
34946diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34947index e812034..c747134 100644
34948--- a/arch/x86/tools/Makefile
34949+++ b/arch/x86/tools/Makefile
34950@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34951
34952 $(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
34953
34954-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34955+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34956 hostprogs-y += relocs
34957 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34958 relocs: $(obj)/relocs
34959diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34960index cfbdbdb..1aa763c 100644
34961--- a/arch/x86/tools/relocs.c
34962+++ b/arch/x86/tools/relocs.c
34963@@ -1,5 +1,7 @@
34964 /* This is included from relocs_32/64.c */
34965
34966+#include "../../../include/generated/autoconf.h"
34967+
34968 #define ElfW(type) _ElfW(ELF_BITS, type)
34969 #define _ElfW(bits, type) __ElfW(bits, type)
34970 #define __ElfW(bits, type) Elf##bits##_##type
34971@@ -11,6 +13,7 @@
34972 #define Elf_Sym ElfW(Sym)
34973
34974 static Elf_Ehdr ehdr;
34975+static Elf_Phdr *phdr;
34976
34977 struct relocs {
34978 uint32_t *offset;
34979@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34980 }
34981 }
34982
34983+static void read_phdrs(FILE *fp)
34984+{
34985+ unsigned int i;
34986+
34987+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34988+ if (!phdr) {
34989+ die("Unable to allocate %d program headers\n",
34990+ ehdr.e_phnum);
34991+ }
34992+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34993+ die("Seek to %d failed: %s\n",
34994+ ehdr.e_phoff, strerror(errno));
34995+ }
34996+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34997+ die("Cannot read ELF program headers: %s\n",
34998+ strerror(errno));
34999+ }
35000+ for(i = 0; i < ehdr.e_phnum; i++) {
35001+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35002+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35003+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35004+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35005+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35006+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35007+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35008+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35009+ }
35010+
35011+}
35012+
35013 static void read_shdrs(FILE *fp)
35014 {
35015- int i;
35016+ unsigned int i;
35017 Elf_Shdr shdr;
35018
35019 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35020@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35021
35022 static void read_strtabs(FILE *fp)
35023 {
35024- int i;
35025+ unsigned int i;
35026 for (i = 0; i < ehdr.e_shnum; i++) {
35027 struct section *sec = &secs[i];
35028 if (sec->shdr.sh_type != SHT_STRTAB) {
35029@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35030
35031 static void read_symtabs(FILE *fp)
35032 {
35033- int i,j;
35034+ unsigned int i,j;
35035 for (i = 0; i < ehdr.e_shnum; i++) {
35036 struct section *sec = &secs[i];
35037 if (sec->shdr.sh_type != SHT_SYMTAB) {
35038@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35039 }
35040
35041
35042-static void read_relocs(FILE *fp)
35043+static void read_relocs(FILE *fp, int use_real_mode)
35044 {
35045- int i,j;
35046+ unsigned int i,j;
35047+ uint32_t base;
35048+
35049 for (i = 0; i < ehdr.e_shnum; i++) {
35050 struct section *sec = &secs[i];
35051 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35052@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35053 die("Cannot read symbol table: %s\n",
35054 strerror(errno));
35055 }
35056+ base = 0;
35057+
35058+#ifdef CONFIG_X86_32
35059+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35060+ if (phdr[j].p_type != PT_LOAD )
35061+ continue;
35062+ 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)
35063+ continue;
35064+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35065+ break;
35066+ }
35067+#endif
35068+
35069 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35070 Elf_Rel *rel = &sec->reltab[j];
35071- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35072+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35073 rel->r_info = elf_xword_to_cpu(rel->r_info);
35074 #if (SHT_REL_TYPE == SHT_RELA)
35075 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35076@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35077
35078 static void print_absolute_symbols(void)
35079 {
35080- int i;
35081+ unsigned int i;
35082 const char *format;
35083
35084 if (ELF_BITS == 64)
35085@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35086 for (i = 0; i < ehdr.e_shnum; i++) {
35087 struct section *sec = &secs[i];
35088 char *sym_strtab;
35089- int j;
35090+ unsigned int j;
35091
35092 if (sec->shdr.sh_type != SHT_SYMTAB) {
35093 continue;
35094@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35095
35096 static void print_absolute_relocs(void)
35097 {
35098- int i, printed = 0;
35099+ unsigned int i, printed = 0;
35100 const char *format;
35101
35102 if (ELF_BITS == 64)
35103@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35104 struct section *sec_applies, *sec_symtab;
35105 char *sym_strtab;
35106 Elf_Sym *sh_symtab;
35107- int j;
35108+ unsigned int j;
35109 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35110 continue;
35111 }
35112@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35113 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35114 Elf_Sym *sym, const char *symname))
35115 {
35116- int i;
35117+ unsigned int i;
35118 /* Walk through the relocations */
35119 for (i = 0; i < ehdr.e_shnum; i++) {
35120 char *sym_strtab;
35121 Elf_Sym *sh_symtab;
35122 struct section *sec_applies, *sec_symtab;
35123- int j;
35124+ unsigned int j;
35125 struct section *sec = &secs[i];
35126
35127 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35128@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35129 {
35130 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35131 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35132+ char *sym_strtab = sec->link->link->strtab;
35133+
35134+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35135+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35136+ return 0;
35137+
35138+#ifdef CONFIG_PAX_KERNEXEC
35139+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35140+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35141+ return 0;
35142+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35143+ return 0;
35144+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35145+ return 0;
35146+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35147+ return 0;
35148+#endif
35149
35150 switch (r_type) {
35151 case R_386_NONE:
35152@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35153
35154 static void emit_relocs(int as_text, int use_real_mode)
35155 {
35156- int i;
35157+ unsigned int i;
35158 int (*write_reloc)(uint32_t, FILE *) = write32;
35159 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35160 const char *symname);
35161@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35162 {
35163 regex_init(use_real_mode);
35164 read_ehdr(fp);
35165+ read_phdrs(fp);
35166 read_shdrs(fp);
35167 read_strtabs(fp);
35168 read_symtabs(fp);
35169- read_relocs(fp);
35170+ read_relocs(fp, use_real_mode);
35171 if (ELF_BITS == 64)
35172 percpu_init();
35173 if (show_absolute_syms) {
35174diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35175index 80ffa5b..a33bd15 100644
35176--- a/arch/x86/um/tls_32.c
35177+++ b/arch/x86/um/tls_32.c
35178@@ -260,7 +260,7 @@ out:
35179 if (unlikely(task == current &&
35180 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35181 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35182- "without flushed TLS.", current->pid);
35183+ "without flushed TLS.", task_pid_nr(current));
35184 }
35185
35186 return 0;
35187diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35188index fd14be1..e3c79c0 100644
35189--- a/arch/x86/vdso/Makefile
35190+++ b/arch/x86/vdso/Makefile
35191@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35192 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35193 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35194
35195-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35196+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35197 GCOV_PROFILE := n
35198
35199 #
35200diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35201index d6bfb87..876ee18 100644
35202--- a/arch/x86/vdso/vdso32-setup.c
35203+++ b/arch/x86/vdso/vdso32-setup.c
35204@@ -25,6 +25,7 @@
35205 #include <asm/tlbflush.h>
35206 #include <asm/vdso.h>
35207 #include <asm/proto.h>
35208+#include <asm/mman.h>
35209
35210 enum {
35211 VDSO_DISABLED = 0,
35212@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35213 void enable_sep_cpu(void)
35214 {
35215 int cpu = get_cpu();
35216- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35217+ struct tss_struct *tss = init_tss + cpu;
35218
35219 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35220 put_cpu();
35221@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35222 gate_vma.vm_start = FIXADDR_USER_START;
35223 gate_vma.vm_end = FIXADDR_USER_END;
35224 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35225- gate_vma.vm_page_prot = __P101;
35226+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35227
35228 return 0;
35229 }
35230@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35231 if (compat)
35232 addr = VDSO_HIGH_BASE;
35233 else {
35234- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35235+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35236 if (IS_ERR_VALUE(addr)) {
35237 ret = addr;
35238 goto up_fail;
35239 }
35240 }
35241
35242- current->mm->context.vdso = (void *)addr;
35243+ current->mm->context.vdso = addr;
35244
35245 if (compat_uses_vma || !compat) {
35246 /*
35247@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35248 }
35249
35250 current_thread_info()->sysenter_return =
35251- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35252+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35253
35254 up_fail:
35255 if (ret)
35256- current->mm->context.vdso = NULL;
35257+ current->mm->context.vdso = 0;
35258
35259 up_write(&mm->mmap_sem);
35260
35261@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35262
35263 const char *arch_vma_name(struct vm_area_struct *vma)
35264 {
35265- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35266+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35267 return "[vdso]";
35268+
35269+#ifdef CONFIG_PAX_SEGMEXEC
35270+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35271+ return "[vdso]";
35272+#endif
35273+
35274 return NULL;
35275 }
35276
35277@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35278 * Check to see if the corresponding task was created in compat vdso
35279 * mode.
35280 */
35281- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35282+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35283 return &gate_vma;
35284 return NULL;
35285 }
35286diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35287index 431e875..cbb23f3 100644
35288--- a/arch/x86/vdso/vma.c
35289+++ b/arch/x86/vdso/vma.c
35290@@ -16,8 +16,6 @@
35291 #include <asm/vdso.h>
35292 #include <asm/page.h>
35293
35294-unsigned int __read_mostly vdso_enabled = 1;
35295-
35296 extern char vdso_start[], vdso_end[];
35297 extern unsigned short vdso_sync_cpuid;
35298
35299@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35300 * unaligned here as a result of stack start randomization.
35301 */
35302 addr = PAGE_ALIGN(addr);
35303- addr = align_vdso_addr(addr);
35304
35305 return addr;
35306 }
35307@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35308 unsigned size)
35309 {
35310 struct mm_struct *mm = current->mm;
35311- unsigned long addr;
35312+ unsigned long addr = 0;
35313 int ret;
35314
35315- if (!vdso_enabled)
35316- return 0;
35317-
35318 down_write(&mm->mmap_sem);
35319+
35320+#ifdef CONFIG_PAX_RANDMMAP
35321+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35322+#endif
35323+
35324 addr = vdso_addr(mm->start_stack, size);
35325+ addr = align_vdso_addr(addr);
35326 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35327 if (IS_ERR_VALUE(addr)) {
35328 ret = addr;
35329 goto up_fail;
35330 }
35331
35332- current->mm->context.vdso = (void *)addr;
35333+ mm->context.vdso = addr;
35334
35335 ret = install_special_mapping(mm, addr, size,
35336 VM_READ|VM_EXEC|
35337 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35338 pages);
35339- if (ret) {
35340- current->mm->context.vdso = NULL;
35341- goto up_fail;
35342- }
35343+ if (ret)
35344+ mm->context.vdso = 0;
35345
35346 up_fail:
35347 up_write(&mm->mmap_sem);
35348@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35349 vdsox32_size);
35350 }
35351 #endif
35352-
35353-static __init int vdso_setup(char *s)
35354-{
35355- vdso_enabled = simple_strtoul(s, NULL, 0);
35356- return 0;
35357-}
35358-__setup("vdso=", vdso_setup);
35359diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35360index 01b9026..1e476df 100644
35361--- a/arch/x86/xen/Kconfig
35362+++ b/arch/x86/xen/Kconfig
35363@@ -9,6 +9,7 @@ config XEN
35364 select XEN_HAVE_PVMMU
35365 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35366 depends on X86_TSC
35367+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35368 help
35369 This is the Linux Xen port. Enabling this will allow the
35370 kernel to boot in a paravirtualized environment under the
35371diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35372index 201d09a..e4723e5 100644
35373--- a/arch/x86/xen/enlighten.c
35374+++ b/arch/x86/xen/enlighten.c
35375@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35376
35377 struct shared_info xen_dummy_shared_info;
35378
35379-void *xen_initial_gdt;
35380-
35381 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35382 __read_mostly int xen_have_vector_callback;
35383 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35384@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35385 {
35386 unsigned long va = dtr->address;
35387 unsigned int size = dtr->size + 1;
35388- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35389- unsigned long frames[pages];
35390+ unsigned long frames[65536 / PAGE_SIZE];
35391 int f;
35392
35393 /*
35394@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35395 {
35396 unsigned long va = dtr->address;
35397 unsigned int size = dtr->size + 1;
35398- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35399- unsigned long frames[pages];
35400+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35401 int f;
35402
35403 /*
35404@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35405 * 8-byte entries, or 16 4k pages..
35406 */
35407
35408- BUG_ON(size > 65536);
35409+ BUG_ON(size > GDT_SIZE);
35410 BUG_ON(va & ~PAGE_MASK);
35411
35412 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35413@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35414 return 0;
35415 }
35416
35417-static void set_xen_basic_apic_ops(void)
35418+static void __init set_xen_basic_apic_ops(void)
35419 {
35420 apic->read = xen_apic_read;
35421 apic->write = xen_apic_write;
35422@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35423 #endif
35424 };
35425
35426-static void xen_reboot(int reason)
35427+static __noreturn void xen_reboot(int reason)
35428 {
35429 struct sched_shutdown r = { .reason = reason };
35430
35431- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35432- BUG();
35433+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35434+ BUG();
35435 }
35436
35437-static void xen_restart(char *msg)
35438+static __noreturn void xen_restart(char *msg)
35439 {
35440 xen_reboot(SHUTDOWN_reboot);
35441 }
35442
35443-static void xen_emergency_restart(void)
35444+static __noreturn void xen_emergency_restart(void)
35445 {
35446 xen_reboot(SHUTDOWN_reboot);
35447 }
35448
35449-static void xen_machine_halt(void)
35450+static __noreturn void xen_machine_halt(void)
35451 {
35452 xen_reboot(SHUTDOWN_poweroff);
35453 }
35454
35455-static void xen_machine_power_off(void)
35456+static __noreturn void xen_machine_power_off(void)
35457 {
35458 if (pm_power_off)
35459 pm_power_off();
35460@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35461 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35462
35463 /* Work out if we support NX */
35464- x86_configure_nx();
35465+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35466+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35467+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35468+ unsigned l, h;
35469+
35470+ __supported_pte_mask |= _PAGE_NX;
35471+ rdmsr(MSR_EFER, l, h);
35472+ l |= EFER_NX;
35473+ wrmsr(MSR_EFER, l, h);
35474+ }
35475+#endif
35476
35477 /* Get mfn list */
35478 xen_build_dynamic_phys_to_machine();
35479@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35480
35481 machine_ops = xen_machine_ops;
35482
35483- /*
35484- * The only reliable way to retain the initial address of the
35485- * percpu gdt_page is to remember it here, so we can go and
35486- * mark it RW later, when the initial percpu area is freed.
35487- */
35488- xen_initial_gdt = &per_cpu(gdt_page, 0);
35489-
35490 xen_smp_init();
35491
35492 #ifdef CONFIG_ACPI_NUMA
35493diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35494index 2423ef0..4f6fb5b 100644
35495--- a/arch/x86/xen/mmu.c
35496+++ b/arch/x86/xen/mmu.c
35497@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35498 return val;
35499 }
35500
35501-static pteval_t pte_pfn_to_mfn(pteval_t val)
35502+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35503 {
35504 if (val & _PAGE_PRESENT) {
35505 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35506@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35507 /* L3_k[510] -> level2_kernel_pgt
35508 * L3_i[511] -> level2_fixmap_pgt */
35509 convert_pfn_mfn(level3_kernel_pgt);
35510+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35511+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35512+ convert_pfn_mfn(level3_vmemmap_pgt);
35513 }
35514 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35515 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35516@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35517 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35518 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35519 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35520+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35521+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35522+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35523 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35524 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35525+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35526 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35527 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35528
35529@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35530 pv_mmu_ops.set_pud = xen_set_pud;
35531 #if PAGETABLE_LEVELS == 4
35532 pv_mmu_ops.set_pgd = xen_set_pgd;
35533+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35534 #endif
35535
35536 /* This will work as long as patching hasn't happened yet
35537@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35538 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35539 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35540 .set_pgd = xen_set_pgd_hyper,
35541+ .set_pgd_batched = xen_set_pgd_hyper,
35542
35543 .alloc_pud = xen_alloc_pmd_init,
35544 .release_pud = xen_release_pmd_init,
35545diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35546index a18eadd..2e2f10e 100644
35547--- a/arch/x86/xen/smp.c
35548+++ b/arch/x86/xen/smp.c
35549@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35550
35551 if (xen_pv_domain()) {
35552 if (!xen_feature(XENFEAT_writable_page_tables))
35553- /* We've switched to the "real" per-cpu gdt, so make
35554- * sure the old memory can be recycled. */
35555- make_lowmem_page_readwrite(xen_initial_gdt);
35556-
35557 #ifdef CONFIG_X86_32
35558 /*
35559 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35560 * expects __USER_DS
35561 */
35562- loadsegment(ds, __USER_DS);
35563- loadsegment(es, __USER_DS);
35564+ loadsegment(ds, __KERNEL_DS);
35565+ loadsegment(es, __KERNEL_DS);
35566 #endif
35567
35568 xen_filter_cpu_maps();
35569@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35570 #ifdef CONFIG_X86_32
35571 /* Note: PVH is not yet supported on x86_32. */
35572 ctxt->user_regs.fs = __KERNEL_PERCPU;
35573- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35574+ savesegment(gs, ctxt->user_regs.gs);
35575 #endif
35576 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35577
35578@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35579 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35580 ctxt->flags = VGCF_IN_KERNEL;
35581 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35582- ctxt->user_regs.ds = __USER_DS;
35583- ctxt->user_regs.es = __USER_DS;
35584+ ctxt->user_regs.ds = __KERNEL_DS;
35585+ ctxt->user_regs.es = __KERNEL_DS;
35586 ctxt->user_regs.ss = __KERNEL_DS;
35587
35588 xen_copy_trap_info(ctxt->trap_ctxt);
35589@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35590 int rc;
35591
35592 per_cpu(current_task, cpu) = idle;
35593+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35594 #ifdef CONFIG_X86_32
35595 irq_ctx_init(cpu);
35596 #else
35597 clear_tsk_thread_flag(idle, TIF_FORK);
35598- per_cpu(kernel_stack, cpu) =
35599- (unsigned long)task_stack_page(idle) -
35600- KERNEL_STACK_OFFSET + THREAD_SIZE;
35601+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35602 #endif
35603 xen_setup_runstate_info(cpu);
35604 xen_setup_timer(cpu);
35605@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35606
35607 void __init xen_smp_init(void)
35608 {
35609- smp_ops = xen_smp_ops;
35610+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35611 xen_fill_possible_map();
35612 }
35613
35614diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35615index 33ca6e4..0ded929 100644
35616--- a/arch/x86/xen/xen-asm_32.S
35617+++ b/arch/x86/xen/xen-asm_32.S
35618@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35619 ESP_OFFSET=4 # bytes pushed onto stack
35620
35621 /*
35622- * Store vcpu_info pointer for easy access. Do it this way to
35623- * avoid having to reload %fs
35624+ * Store vcpu_info pointer for easy access.
35625 */
35626 #ifdef CONFIG_SMP
35627- GET_THREAD_INFO(%eax)
35628- movl %ss:TI_cpu(%eax), %eax
35629- movl %ss:__per_cpu_offset(,%eax,4), %eax
35630- mov %ss:xen_vcpu(%eax), %eax
35631+ push %fs
35632+ mov $(__KERNEL_PERCPU), %eax
35633+ mov %eax, %fs
35634+ mov PER_CPU_VAR(xen_vcpu), %eax
35635+ pop %fs
35636 #else
35637 movl %ss:xen_vcpu, %eax
35638 #endif
35639diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35640index 485b695..fda3e7c 100644
35641--- a/arch/x86/xen/xen-head.S
35642+++ b/arch/x86/xen/xen-head.S
35643@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35644 #ifdef CONFIG_X86_32
35645 mov %esi,xen_start_info
35646 mov $init_thread_union+THREAD_SIZE,%esp
35647+#ifdef CONFIG_SMP
35648+ movl $cpu_gdt_table,%edi
35649+ movl $__per_cpu_load,%eax
35650+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35651+ rorl $16,%eax
35652+ movb %al,__KERNEL_PERCPU + 4(%edi)
35653+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35654+ movl $__per_cpu_end - 1,%eax
35655+ subl $__per_cpu_start,%eax
35656+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35657+#endif
35658 #else
35659 mov %rsi,xen_start_info
35660 mov $init_thread_union+THREAD_SIZE,%rsp
35661diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35662index 1cb6f4c..9981524 100644
35663--- a/arch/x86/xen/xen-ops.h
35664+++ b/arch/x86/xen/xen-ops.h
35665@@ -10,8 +10,6 @@
35666 extern const char xen_hypervisor_callback[];
35667 extern const char xen_failsafe_callback[];
35668
35669-extern void *xen_initial_gdt;
35670-
35671 struct trap_info;
35672 void xen_copy_trap_info(struct trap_info *traps);
35673
35674diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35675index 525bd3d..ef888b1 100644
35676--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35677+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35678@@ -119,9 +119,9 @@
35679 ----------------------------------------------------------------------*/
35680
35681 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35682-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35683 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35684 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35685+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35686
35687 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35688 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35689diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35690index 2f33760..835e50a 100644
35691--- a/arch/xtensa/variants/fsf/include/variant/core.h
35692+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35693@@ -11,6 +11,7 @@
35694 #ifndef _XTENSA_CORE_H
35695 #define _XTENSA_CORE_H
35696
35697+#include <linux/const.h>
35698
35699 /****************************************************************************
35700 Parameters Useful for Any Code, USER or PRIVILEGED
35701@@ -112,9 +113,9 @@
35702 ----------------------------------------------------------------------*/
35703
35704 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35705-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35706 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35707 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35708+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35709
35710 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35711 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35712diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35713index af00795..2bb8105 100644
35714--- a/arch/xtensa/variants/s6000/include/variant/core.h
35715+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35716@@ -11,6 +11,7 @@
35717 #ifndef _XTENSA_CORE_CONFIGURATION_H
35718 #define _XTENSA_CORE_CONFIGURATION_H
35719
35720+#include <linux/const.h>
35721
35722 /****************************************************************************
35723 Parameters Useful for Any Code, USER or PRIVILEGED
35724@@ -118,9 +119,9 @@
35725 ----------------------------------------------------------------------*/
35726
35727 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35728-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35729 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35730 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35731+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35732
35733 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35734 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35735diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35736index 4e491d9..c8e18e4 100644
35737--- a/block/blk-cgroup.c
35738+++ b/block/blk-cgroup.c
35739@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35740 static struct cgroup_subsys_state *
35741 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35742 {
35743- static atomic64_t id_seq = ATOMIC64_INIT(0);
35744+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35745 struct blkcg *blkcg;
35746
35747 if (!parent_css) {
35748@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35749
35750 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35751 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35752- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35753+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35754 done:
35755 spin_lock_init(&blkcg->lock);
35756 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35757diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35758index 1855bf5..af12b06 100644
35759--- a/block/blk-iopoll.c
35760+++ b/block/blk-iopoll.c
35761@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35762 }
35763 EXPORT_SYMBOL(blk_iopoll_complete);
35764
35765-static void blk_iopoll_softirq(struct softirq_action *h)
35766+static __latent_entropy void blk_iopoll_softirq(void)
35767 {
35768 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35769 int rearm = 0, budget = blk_iopoll_budget;
35770diff --git a/block/blk-map.c b/block/blk-map.c
35771index ae4ae10..c470b8d 100644
35772--- a/block/blk-map.c
35773+++ b/block/blk-map.c
35774@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35775 if (!len || !kbuf)
35776 return -EINVAL;
35777
35778- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35779+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35780 if (do_copy)
35781 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35782 else
35783diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35784index 57790c1..5e988dd 100644
35785--- a/block/blk-softirq.c
35786+++ b/block/blk-softirq.c
35787@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35788 * Softirq action handler - move entries to local list and loop over them
35789 * while passing them to the queue registered handler.
35790 */
35791-static void blk_done_softirq(struct softirq_action *h)
35792+static __latent_entropy void blk_done_softirq(void)
35793 {
35794 struct list_head *cpu_list, local_list;
35795
35796diff --git a/block/bsg.c b/block/bsg.c
35797index 420a5a9..23834aa 100644
35798--- a/block/bsg.c
35799+++ b/block/bsg.c
35800@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35801 struct sg_io_v4 *hdr, struct bsg_device *bd,
35802 fmode_t has_write_perm)
35803 {
35804+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35805+ unsigned char *cmdptr;
35806+
35807 if (hdr->request_len > BLK_MAX_CDB) {
35808 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35809 if (!rq->cmd)
35810 return -ENOMEM;
35811- }
35812+ cmdptr = rq->cmd;
35813+ } else
35814+ cmdptr = tmpcmd;
35815
35816- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35817+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35818 hdr->request_len))
35819 return -EFAULT;
35820
35821+ if (cmdptr != rq->cmd)
35822+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35823+
35824 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35825 if (blk_verify_command(rq->cmd, has_write_perm))
35826 return -EPERM;
35827diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35828index fbd5a67..f24fd95 100644
35829--- a/block/compat_ioctl.c
35830+++ b/block/compat_ioctl.c
35831@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35832 cgc = compat_alloc_user_space(sizeof(*cgc));
35833 cgc32 = compat_ptr(arg);
35834
35835- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35836+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35837 get_user(data, &cgc32->buffer) ||
35838 put_user(compat_ptr(data), &cgc->buffer) ||
35839 copy_in_user(&cgc->buflen, &cgc32->buflen,
35840@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35841 err |= __get_user(f->spec1, &uf->spec1);
35842 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35843 err |= __get_user(name, &uf->name);
35844- f->name = compat_ptr(name);
35845+ f->name = (void __force_kernel *)compat_ptr(name);
35846 if (err) {
35847 err = -EFAULT;
35848 goto out;
35849diff --git a/block/genhd.c b/block/genhd.c
35850index 791f419..89f21c4 100644
35851--- a/block/genhd.c
35852+++ b/block/genhd.c
35853@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35854
35855 /*
35856 * Register device numbers dev..(dev+range-1)
35857- * range must be nonzero
35858+ * Noop if @range is zero.
35859 * The hash chain is sorted on range, so that subranges can override.
35860 */
35861 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35862 struct kobject *(*probe)(dev_t, int *, void *),
35863 int (*lock)(dev_t, void *), void *data)
35864 {
35865- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35866+ if (range)
35867+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35868 }
35869
35870 EXPORT_SYMBOL(blk_register_region);
35871
35872+/* undo blk_register_region(), noop if @range is zero */
35873 void blk_unregister_region(dev_t devt, unsigned long range)
35874 {
35875- kobj_unmap(bdev_map, devt, range);
35876+ if (range)
35877+ kobj_unmap(bdev_map, devt, range);
35878 }
35879
35880 EXPORT_SYMBOL(blk_unregister_region);
35881diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35882index dc51f46..d5446a8 100644
35883--- a/block/partitions/efi.c
35884+++ b/block/partitions/efi.c
35885@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35886 if (!gpt)
35887 return NULL;
35888
35889+ if (!le32_to_cpu(gpt->num_partition_entries))
35890+ return NULL;
35891+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35892+ if (!pte)
35893+ return NULL;
35894+
35895 count = le32_to_cpu(gpt->num_partition_entries) *
35896 le32_to_cpu(gpt->sizeof_partition_entry);
35897- if (!count)
35898- return NULL;
35899- pte = kmalloc(count, GFP_KERNEL);
35900- if (!pte)
35901- return NULL;
35902-
35903 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35904 (u8 *) pte, count) < count) {
35905 kfree(pte);
35906diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35907index 2648797..92ed21f 100644
35908--- a/block/scsi_ioctl.c
35909+++ b/block/scsi_ioctl.c
35910@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35911 return put_user(0, p);
35912 }
35913
35914-static int sg_get_timeout(struct request_queue *q)
35915+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35916 {
35917 return jiffies_to_clock_t(q->sg_timeout);
35918 }
35919@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35920 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35921 struct sg_io_hdr *hdr, fmode_t mode)
35922 {
35923- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35924+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35925+ unsigned char *cmdptr;
35926+
35927+ if (rq->cmd != rq->__cmd)
35928+ cmdptr = rq->cmd;
35929+ else
35930+ cmdptr = tmpcmd;
35931+
35932+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35933 return -EFAULT;
35934+
35935+ if (cmdptr != rq->cmd)
35936+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35937+
35938 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35939 return -EPERM;
35940
35941@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35942 int err;
35943 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35944 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35945+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35946+ unsigned char *cmdptr;
35947
35948 if (!sic)
35949 return -EINVAL;
35950@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35951 */
35952 err = -EFAULT;
35953 rq->cmd_len = cmdlen;
35954- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35955+
35956+ if (rq->cmd != rq->__cmd)
35957+ cmdptr = rq->cmd;
35958+ else
35959+ cmdptr = tmpcmd;
35960+
35961+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35962 goto error;
35963
35964+ if (rq->cmd != cmdptr)
35965+ memcpy(rq->cmd, cmdptr, cmdlen);
35966+
35967 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35968 goto error;
35969
35970diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35971index 7bdd61b..afec999 100644
35972--- a/crypto/cryptd.c
35973+++ b/crypto/cryptd.c
35974@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35975
35976 struct cryptd_blkcipher_request_ctx {
35977 crypto_completion_t complete;
35978-};
35979+} __no_const;
35980
35981 struct cryptd_hash_ctx {
35982 struct crypto_shash *child;
35983@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35984
35985 struct cryptd_aead_request_ctx {
35986 crypto_completion_t complete;
35987-};
35988+} __no_const;
35989
35990 static void cryptd_queue_worker(struct work_struct *work);
35991
35992diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35993index 309d345..1632720 100644
35994--- a/crypto/pcrypt.c
35995+++ b/crypto/pcrypt.c
35996@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35997 int ret;
35998
35999 pinst->kobj.kset = pcrypt_kset;
36000- ret = kobject_add(&pinst->kobj, NULL, name);
36001+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36002 if (!ret)
36003 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36004
36005diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36006index 15dddc1..b61cf0c 100644
36007--- a/drivers/acpi/acpica/hwxfsleep.c
36008+++ b/drivers/acpi/acpica/hwxfsleep.c
36009@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36010 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36011
36012 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36013- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36014- acpi_hw_extended_sleep},
36015- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36016- acpi_hw_extended_wake_prep},
36017- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36018+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36019+ .extended_function = acpi_hw_extended_sleep},
36020+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36021+ .extended_function = acpi_hw_extended_wake_prep},
36022+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36023+ .extended_function = acpi_hw_extended_wake}
36024 };
36025
36026 /*
36027diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36028index e5bcd91..74f050d 100644
36029--- a/drivers/acpi/apei/apei-internal.h
36030+++ b/drivers/acpi/apei/apei-internal.h
36031@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36032 struct apei_exec_ins_type {
36033 u32 flags;
36034 apei_exec_ins_func_t run;
36035-};
36036+} __do_const;
36037
36038 struct apei_exec_context {
36039 u32 ip;
36040diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36041index dab7cb7..f0d2994 100644
36042--- a/drivers/acpi/apei/ghes.c
36043+++ b/drivers/acpi/apei/ghes.c
36044@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36045 const struct acpi_hest_generic *generic,
36046 const struct acpi_generic_status *estatus)
36047 {
36048- static atomic_t seqno;
36049+ static atomic_unchecked_t seqno;
36050 unsigned int curr_seqno;
36051 char pfx_seq[64];
36052
36053@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36054 else
36055 pfx = KERN_ERR;
36056 }
36057- curr_seqno = atomic_inc_return(&seqno);
36058+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36059 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36060 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36061 pfx_seq, generic->header.source_id);
36062diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36063index a83e3c6..c3d617f 100644
36064--- a/drivers/acpi/bgrt.c
36065+++ b/drivers/acpi/bgrt.c
36066@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36067 if (!bgrt_image)
36068 return -ENODEV;
36069
36070- bin_attr_image.private = bgrt_image;
36071- bin_attr_image.size = bgrt_image_size;
36072+ pax_open_kernel();
36073+ *(void **)&bin_attr_image.private = bgrt_image;
36074+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36075+ pax_close_kernel();
36076
36077 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36078 if (!bgrt_kobj)
36079diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36080index afec452..c5d8b96 100644
36081--- a/drivers/acpi/blacklist.c
36082+++ b/drivers/acpi/blacklist.c
36083@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36084 u32 is_critical_error;
36085 };
36086
36087-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36088+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36089
36090 /*
36091 * POLICY: If *anything* doesn't work, put it on the blacklist.
36092@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36093 return 0;
36094 }
36095
36096-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36097+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36098 {
36099 .callback = dmi_disable_osi_vista,
36100 .ident = "Fujitsu Siemens",
36101diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36102index c68e724..e863008 100644
36103--- a/drivers/acpi/custom_method.c
36104+++ b/drivers/acpi/custom_method.c
36105@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36106 struct acpi_table_header table;
36107 acpi_status status;
36108
36109+#ifdef CONFIG_GRKERNSEC_KMEM
36110+ return -EPERM;
36111+#endif
36112+
36113 if (!(*ppos)) {
36114 /* parse the table header to get the table length */
36115 if (count <= sizeof(struct acpi_table_header))
36116diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36117index 3dca36d..abaf070 100644
36118--- a/drivers/acpi/processor_idle.c
36119+++ b/drivers/acpi/processor_idle.c
36120@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36121 {
36122 int i, count = CPUIDLE_DRIVER_STATE_START;
36123 struct acpi_processor_cx *cx;
36124- struct cpuidle_state *state;
36125+ cpuidle_state_no_const *state;
36126 struct cpuidle_driver *drv = &acpi_idle_driver;
36127
36128 if (!pr->flags.power_setup_done)
36129diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36130index 91a32ce..d77fcaf 100644
36131--- a/drivers/acpi/sysfs.c
36132+++ b/drivers/acpi/sysfs.c
36133@@ -425,11 +425,11 @@ static u32 num_counters;
36134 static struct attribute **all_attrs;
36135 static u32 acpi_gpe_count;
36136
36137-static struct attribute_group interrupt_stats_attr_group = {
36138+static attribute_group_no_const interrupt_stats_attr_group = {
36139 .name = "interrupts",
36140 };
36141
36142-static struct kobj_attribute *counter_attrs;
36143+static kobj_attribute_no_const *counter_attrs;
36144
36145 static void delete_gpe_attr_array(void)
36146 {
36147diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36148index 36605ab..6ef6d4b 100644
36149--- a/drivers/ata/libahci.c
36150+++ b/drivers/ata/libahci.c
36151@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36152 }
36153 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36154
36155-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36156+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36157 struct ata_taskfile *tf, int is_cmd, u16 flags,
36158 unsigned long timeout_msec)
36159 {
36160diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36161index 8cb2522..a815e54 100644
36162--- a/drivers/ata/libata-core.c
36163+++ b/drivers/ata/libata-core.c
36164@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36165 static void ata_dev_xfermask(struct ata_device *dev);
36166 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36167
36168-atomic_t ata_print_id = ATOMIC_INIT(0);
36169+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36170
36171 struct ata_force_param {
36172 const char *name;
36173@@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36174 struct ata_port *ap;
36175 unsigned int tag;
36176
36177- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36178+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36179 ap = qc->ap;
36180
36181 qc->flags = 0;
36182@@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36183 struct ata_port *ap;
36184 struct ata_link *link;
36185
36186- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36187+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36188 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36189 ap = qc->ap;
36190 link = qc->dev->link;
36191@@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36192 return;
36193
36194 spin_lock(&lock);
36195+ pax_open_kernel();
36196
36197 for (cur = ops->inherits; cur; cur = cur->inherits) {
36198 void **inherit = (void **)cur;
36199@@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36200 if (IS_ERR(*pp))
36201 *pp = NULL;
36202
36203- ops->inherits = NULL;
36204+ *(struct ata_port_operations **)&ops->inherits = NULL;
36205
36206+ pax_close_kernel();
36207 spin_unlock(&lock);
36208 }
36209
36210@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36211
36212 /* give ports names and add SCSI hosts */
36213 for (i = 0; i < host->n_ports; i++) {
36214- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36215+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36216 host->ports[i]->local_port_no = i + 1;
36217 }
36218
36219diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36220index ef8567d..8bdbd03 100644
36221--- a/drivers/ata/libata-scsi.c
36222+++ b/drivers/ata/libata-scsi.c
36223@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36224
36225 if (rc)
36226 return rc;
36227- ap->print_id = atomic_inc_return(&ata_print_id);
36228+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36229 return 0;
36230 }
36231 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36232diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36233index 45b5ab3..98446b8 100644
36234--- a/drivers/ata/libata.h
36235+++ b/drivers/ata/libata.h
36236@@ -53,7 +53,7 @@ enum {
36237 ATA_DNXFER_QUIET = (1 << 31),
36238 };
36239
36240-extern atomic_t ata_print_id;
36241+extern atomic_unchecked_t ata_print_id;
36242 extern int atapi_passthru16;
36243 extern int libata_fua;
36244 extern int libata_noacpi;
36245diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36246index 73492dd..ca2bff5 100644
36247--- a/drivers/ata/pata_arasan_cf.c
36248+++ b/drivers/ata/pata_arasan_cf.c
36249@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36250 /* Handle platform specific quirks */
36251 if (quirk) {
36252 if (quirk & CF_BROKEN_PIO) {
36253- ap->ops->set_piomode = NULL;
36254+ pax_open_kernel();
36255+ *(void **)&ap->ops->set_piomode = NULL;
36256+ pax_close_kernel();
36257 ap->pio_mask = 0;
36258 }
36259 if (quirk & CF_BROKEN_MWDMA)
36260diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36261index f9b983a..887b9d8 100644
36262--- a/drivers/atm/adummy.c
36263+++ b/drivers/atm/adummy.c
36264@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36265 vcc->pop(vcc, skb);
36266 else
36267 dev_kfree_skb_any(skb);
36268- atomic_inc(&vcc->stats->tx);
36269+ atomic_inc_unchecked(&vcc->stats->tx);
36270
36271 return 0;
36272 }
36273diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36274index 62a7607..cc4be104 100644
36275--- a/drivers/atm/ambassador.c
36276+++ b/drivers/atm/ambassador.c
36277@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36278 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36279
36280 // VC layer stats
36281- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36282+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36283
36284 // free the descriptor
36285 kfree (tx_descr);
36286@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36287 dump_skb ("<<<", vc, skb);
36288
36289 // VC layer stats
36290- atomic_inc(&atm_vcc->stats->rx);
36291+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36292 __net_timestamp(skb);
36293 // end of our responsibility
36294 atm_vcc->push (atm_vcc, skb);
36295@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36296 } else {
36297 PRINTK (KERN_INFO, "dropped over-size frame");
36298 // should we count this?
36299- atomic_inc(&atm_vcc->stats->rx_drop);
36300+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36301 }
36302
36303 } else {
36304@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36305 }
36306
36307 if (check_area (skb->data, skb->len)) {
36308- atomic_inc(&atm_vcc->stats->tx_err);
36309+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36310 return -ENOMEM; // ?
36311 }
36312
36313diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36314index 0e3f8f9..765a7a5 100644
36315--- a/drivers/atm/atmtcp.c
36316+++ b/drivers/atm/atmtcp.c
36317@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36318 if (vcc->pop) vcc->pop(vcc,skb);
36319 else dev_kfree_skb(skb);
36320 if (dev_data) return 0;
36321- atomic_inc(&vcc->stats->tx_err);
36322+ atomic_inc_unchecked(&vcc->stats->tx_err);
36323 return -ENOLINK;
36324 }
36325 size = skb->len+sizeof(struct atmtcp_hdr);
36326@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36327 if (!new_skb) {
36328 if (vcc->pop) vcc->pop(vcc,skb);
36329 else dev_kfree_skb(skb);
36330- atomic_inc(&vcc->stats->tx_err);
36331+ atomic_inc_unchecked(&vcc->stats->tx_err);
36332 return -ENOBUFS;
36333 }
36334 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36335@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36336 if (vcc->pop) vcc->pop(vcc,skb);
36337 else dev_kfree_skb(skb);
36338 out_vcc->push(out_vcc,new_skb);
36339- atomic_inc(&vcc->stats->tx);
36340- atomic_inc(&out_vcc->stats->rx);
36341+ atomic_inc_unchecked(&vcc->stats->tx);
36342+ atomic_inc_unchecked(&out_vcc->stats->rx);
36343 return 0;
36344 }
36345
36346@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36347 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36348 read_unlock(&vcc_sklist_lock);
36349 if (!out_vcc) {
36350- atomic_inc(&vcc->stats->tx_err);
36351+ atomic_inc_unchecked(&vcc->stats->tx_err);
36352 goto done;
36353 }
36354 skb_pull(skb,sizeof(struct atmtcp_hdr));
36355@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36356 __net_timestamp(new_skb);
36357 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36358 out_vcc->push(out_vcc,new_skb);
36359- atomic_inc(&vcc->stats->tx);
36360- atomic_inc(&out_vcc->stats->rx);
36361+ atomic_inc_unchecked(&vcc->stats->tx);
36362+ atomic_inc_unchecked(&out_vcc->stats->rx);
36363 done:
36364 if (vcc->pop) vcc->pop(vcc,skb);
36365 else dev_kfree_skb(skb);
36366diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36367index b1955ba..b179940 100644
36368--- a/drivers/atm/eni.c
36369+++ b/drivers/atm/eni.c
36370@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36371 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36372 vcc->dev->number);
36373 length = 0;
36374- atomic_inc(&vcc->stats->rx_err);
36375+ atomic_inc_unchecked(&vcc->stats->rx_err);
36376 }
36377 else {
36378 length = ATM_CELL_SIZE-1; /* no HEC */
36379@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36380 size);
36381 }
36382 eff = length = 0;
36383- atomic_inc(&vcc->stats->rx_err);
36384+ atomic_inc_unchecked(&vcc->stats->rx_err);
36385 }
36386 else {
36387 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36388@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36389 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36390 vcc->dev->number,vcc->vci,length,size << 2,descr);
36391 length = eff = 0;
36392- atomic_inc(&vcc->stats->rx_err);
36393+ atomic_inc_unchecked(&vcc->stats->rx_err);
36394 }
36395 }
36396 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36397@@ -767,7 +767,7 @@ rx_dequeued++;
36398 vcc->push(vcc,skb);
36399 pushed++;
36400 }
36401- atomic_inc(&vcc->stats->rx);
36402+ atomic_inc_unchecked(&vcc->stats->rx);
36403 }
36404 wake_up(&eni_dev->rx_wait);
36405 }
36406@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36407 PCI_DMA_TODEVICE);
36408 if (vcc->pop) vcc->pop(vcc,skb);
36409 else dev_kfree_skb_irq(skb);
36410- atomic_inc(&vcc->stats->tx);
36411+ atomic_inc_unchecked(&vcc->stats->tx);
36412 wake_up(&eni_dev->tx_wait);
36413 dma_complete++;
36414 }
36415diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36416index b41c948..a002b17 100644
36417--- a/drivers/atm/firestream.c
36418+++ b/drivers/atm/firestream.c
36419@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36420 }
36421 }
36422
36423- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36424+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36425
36426 fs_dprintk (FS_DEBUG_TXMEM, "i");
36427 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36428@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36429 #endif
36430 skb_put (skb, qe->p1 & 0xffff);
36431 ATM_SKB(skb)->vcc = atm_vcc;
36432- atomic_inc(&atm_vcc->stats->rx);
36433+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36434 __net_timestamp(skb);
36435 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36436 atm_vcc->push (atm_vcc, skb);
36437@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36438 kfree (pe);
36439 }
36440 if (atm_vcc)
36441- atomic_inc(&atm_vcc->stats->rx_drop);
36442+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36443 break;
36444 case 0x1f: /* Reassembly abort: no buffers. */
36445 /* Silently increment error counter. */
36446 if (atm_vcc)
36447- atomic_inc(&atm_vcc->stats->rx_drop);
36448+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36449 break;
36450 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36451 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36452diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36453index 204814e..cede831 100644
36454--- a/drivers/atm/fore200e.c
36455+++ b/drivers/atm/fore200e.c
36456@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36457 #endif
36458 /* check error condition */
36459 if (*entry->status & STATUS_ERROR)
36460- atomic_inc(&vcc->stats->tx_err);
36461+ atomic_inc_unchecked(&vcc->stats->tx_err);
36462 else
36463- atomic_inc(&vcc->stats->tx);
36464+ atomic_inc_unchecked(&vcc->stats->tx);
36465 }
36466 }
36467
36468@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36469 if (skb == NULL) {
36470 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36471
36472- atomic_inc(&vcc->stats->rx_drop);
36473+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36474 return -ENOMEM;
36475 }
36476
36477@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36478
36479 dev_kfree_skb_any(skb);
36480
36481- atomic_inc(&vcc->stats->rx_drop);
36482+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36483 return -ENOMEM;
36484 }
36485
36486 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36487
36488 vcc->push(vcc, skb);
36489- atomic_inc(&vcc->stats->rx);
36490+ atomic_inc_unchecked(&vcc->stats->rx);
36491
36492 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36493
36494@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36495 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36496 fore200e->atm_dev->number,
36497 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36498- atomic_inc(&vcc->stats->rx_err);
36499+ atomic_inc_unchecked(&vcc->stats->rx_err);
36500 }
36501 }
36502
36503@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36504 goto retry_here;
36505 }
36506
36507- atomic_inc(&vcc->stats->tx_err);
36508+ atomic_inc_unchecked(&vcc->stats->tx_err);
36509
36510 fore200e->tx_sat++;
36511 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36512diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36513index aa6be26..f70a785 100644
36514--- a/drivers/atm/he.c
36515+++ b/drivers/atm/he.c
36516@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36517
36518 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36519 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36520- atomic_inc(&vcc->stats->rx_drop);
36521+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36522 goto return_host_buffers;
36523 }
36524
36525@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36526 RBRQ_LEN_ERR(he_dev->rbrq_head)
36527 ? "LEN_ERR" : "",
36528 vcc->vpi, vcc->vci);
36529- atomic_inc(&vcc->stats->rx_err);
36530+ atomic_inc_unchecked(&vcc->stats->rx_err);
36531 goto return_host_buffers;
36532 }
36533
36534@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36535 vcc->push(vcc, skb);
36536 spin_lock(&he_dev->global_lock);
36537
36538- atomic_inc(&vcc->stats->rx);
36539+ atomic_inc_unchecked(&vcc->stats->rx);
36540
36541 return_host_buffers:
36542 ++pdus_assembled;
36543@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36544 tpd->vcc->pop(tpd->vcc, tpd->skb);
36545 else
36546 dev_kfree_skb_any(tpd->skb);
36547- atomic_inc(&tpd->vcc->stats->tx_err);
36548+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36549 }
36550 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36551 return;
36552@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36553 vcc->pop(vcc, skb);
36554 else
36555 dev_kfree_skb_any(skb);
36556- atomic_inc(&vcc->stats->tx_err);
36557+ atomic_inc_unchecked(&vcc->stats->tx_err);
36558 return -EINVAL;
36559 }
36560
36561@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36562 vcc->pop(vcc, skb);
36563 else
36564 dev_kfree_skb_any(skb);
36565- atomic_inc(&vcc->stats->tx_err);
36566+ atomic_inc_unchecked(&vcc->stats->tx_err);
36567 return -EINVAL;
36568 }
36569 #endif
36570@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36571 vcc->pop(vcc, skb);
36572 else
36573 dev_kfree_skb_any(skb);
36574- atomic_inc(&vcc->stats->tx_err);
36575+ atomic_inc_unchecked(&vcc->stats->tx_err);
36576 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36577 return -ENOMEM;
36578 }
36579@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36580 vcc->pop(vcc, skb);
36581 else
36582 dev_kfree_skb_any(skb);
36583- atomic_inc(&vcc->stats->tx_err);
36584+ atomic_inc_unchecked(&vcc->stats->tx_err);
36585 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36586 return -ENOMEM;
36587 }
36588@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36589 __enqueue_tpd(he_dev, tpd, cid);
36590 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36591
36592- atomic_inc(&vcc->stats->tx);
36593+ atomic_inc_unchecked(&vcc->stats->tx);
36594
36595 return 0;
36596 }
36597diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36598index 1dc0519..1aadaf7 100644
36599--- a/drivers/atm/horizon.c
36600+++ b/drivers/atm/horizon.c
36601@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36602 {
36603 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36604 // VC layer stats
36605- atomic_inc(&vcc->stats->rx);
36606+ atomic_inc_unchecked(&vcc->stats->rx);
36607 __net_timestamp(skb);
36608 // end of our responsibility
36609 vcc->push (vcc, skb);
36610@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36611 dev->tx_iovec = NULL;
36612
36613 // VC layer stats
36614- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36615+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36616
36617 // free the skb
36618 hrz_kfree_skb (skb);
36619diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36620index 1bdf104..9dc44b1 100644
36621--- a/drivers/atm/idt77252.c
36622+++ b/drivers/atm/idt77252.c
36623@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36624 else
36625 dev_kfree_skb(skb);
36626
36627- atomic_inc(&vcc->stats->tx);
36628+ atomic_inc_unchecked(&vcc->stats->tx);
36629 }
36630
36631 atomic_dec(&scq->used);
36632@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36633 if ((sb = dev_alloc_skb(64)) == NULL) {
36634 printk("%s: Can't allocate buffers for aal0.\n",
36635 card->name);
36636- atomic_add(i, &vcc->stats->rx_drop);
36637+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36638 break;
36639 }
36640 if (!atm_charge(vcc, sb->truesize)) {
36641 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36642 card->name);
36643- atomic_add(i - 1, &vcc->stats->rx_drop);
36644+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36645 dev_kfree_skb(sb);
36646 break;
36647 }
36648@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36649 ATM_SKB(sb)->vcc = vcc;
36650 __net_timestamp(sb);
36651 vcc->push(vcc, sb);
36652- atomic_inc(&vcc->stats->rx);
36653+ atomic_inc_unchecked(&vcc->stats->rx);
36654
36655 cell += ATM_CELL_PAYLOAD;
36656 }
36657@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36658 "(CDC: %08x)\n",
36659 card->name, len, rpp->len, readl(SAR_REG_CDC));
36660 recycle_rx_pool_skb(card, rpp);
36661- atomic_inc(&vcc->stats->rx_err);
36662+ atomic_inc_unchecked(&vcc->stats->rx_err);
36663 return;
36664 }
36665 if (stat & SAR_RSQE_CRC) {
36666 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36667 recycle_rx_pool_skb(card, rpp);
36668- atomic_inc(&vcc->stats->rx_err);
36669+ atomic_inc_unchecked(&vcc->stats->rx_err);
36670 return;
36671 }
36672 if (skb_queue_len(&rpp->queue) > 1) {
36673@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36674 RXPRINTK("%s: Can't alloc RX skb.\n",
36675 card->name);
36676 recycle_rx_pool_skb(card, rpp);
36677- atomic_inc(&vcc->stats->rx_err);
36678+ atomic_inc_unchecked(&vcc->stats->rx_err);
36679 return;
36680 }
36681 if (!atm_charge(vcc, skb->truesize)) {
36682@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36683 __net_timestamp(skb);
36684
36685 vcc->push(vcc, skb);
36686- atomic_inc(&vcc->stats->rx);
36687+ atomic_inc_unchecked(&vcc->stats->rx);
36688
36689 return;
36690 }
36691@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36692 __net_timestamp(skb);
36693
36694 vcc->push(vcc, skb);
36695- atomic_inc(&vcc->stats->rx);
36696+ atomic_inc_unchecked(&vcc->stats->rx);
36697
36698 if (skb->truesize > SAR_FB_SIZE_3)
36699 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36700@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36701 if (vcc->qos.aal != ATM_AAL0) {
36702 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36703 card->name, vpi, vci);
36704- atomic_inc(&vcc->stats->rx_drop);
36705+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36706 goto drop;
36707 }
36708
36709 if ((sb = dev_alloc_skb(64)) == NULL) {
36710 printk("%s: Can't allocate buffers for AAL0.\n",
36711 card->name);
36712- atomic_inc(&vcc->stats->rx_err);
36713+ atomic_inc_unchecked(&vcc->stats->rx_err);
36714 goto drop;
36715 }
36716
36717@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36718 ATM_SKB(sb)->vcc = vcc;
36719 __net_timestamp(sb);
36720 vcc->push(vcc, sb);
36721- atomic_inc(&vcc->stats->rx);
36722+ atomic_inc_unchecked(&vcc->stats->rx);
36723
36724 drop:
36725 skb_pull(queue, 64);
36726@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36727
36728 if (vc == NULL) {
36729 printk("%s: NULL connection in send().\n", card->name);
36730- atomic_inc(&vcc->stats->tx_err);
36731+ atomic_inc_unchecked(&vcc->stats->tx_err);
36732 dev_kfree_skb(skb);
36733 return -EINVAL;
36734 }
36735 if (!test_bit(VCF_TX, &vc->flags)) {
36736 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36737- atomic_inc(&vcc->stats->tx_err);
36738+ atomic_inc_unchecked(&vcc->stats->tx_err);
36739 dev_kfree_skb(skb);
36740 return -EINVAL;
36741 }
36742@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36743 break;
36744 default:
36745 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36746- atomic_inc(&vcc->stats->tx_err);
36747+ atomic_inc_unchecked(&vcc->stats->tx_err);
36748 dev_kfree_skb(skb);
36749 return -EINVAL;
36750 }
36751
36752 if (skb_shinfo(skb)->nr_frags != 0) {
36753 printk("%s: No scatter-gather yet.\n", card->name);
36754- atomic_inc(&vcc->stats->tx_err);
36755+ atomic_inc_unchecked(&vcc->stats->tx_err);
36756 dev_kfree_skb(skb);
36757 return -EINVAL;
36758 }
36759@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36760
36761 err = queue_skb(card, vc, skb, oam);
36762 if (err) {
36763- atomic_inc(&vcc->stats->tx_err);
36764+ atomic_inc_unchecked(&vcc->stats->tx_err);
36765 dev_kfree_skb(skb);
36766 return err;
36767 }
36768@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36769 skb = dev_alloc_skb(64);
36770 if (!skb) {
36771 printk("%s: Out of memory in send_oam().\n", card->name);
36772- atomic_inc(&vcc->stats->tx_err);
36773+ atomic_inc_unchecked(&vcc->stats->tx_err);
36774 return -ENOMEM;
36775 }
36776 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36777diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36778index 4217f29..88f547a 100644
36779--- a/drivers/atm/iphase.c
36780+++ b/drivers/atm/iphase.c
36781@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36782 status = (u_short) (buf_desc_ptr->desc_mode);
36783 if (status & (RX_CER | RX_PTE | RX_OFL))
36784 {
36785- atomic_inc(&vcc->stats->rx_err);
36786+ atomic_inc_unchecked(&vcc->stats->rx_err);
36787 IF_ERR(printk("IA: bad packet, dropping it");)
36788 if (status & RX_CER) {
36789 IF_ERR(printk(" cause: packet CRC error\n");)
36790@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36791 len = dma_addr - buf_addr;
36792 if (len > iadev->rx_buf_sz) {
36793 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36794- atomic_inc(&vcc->stats->rx_err);
36795+ atomic_inc_unchecked(&vcc->stats->rx_err);
36796 goto out_free_desc;
36797 }
36798
36799@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36800 ia_vcc = INPH_IA_VCC(vcc);
36801 if (ia_vcc == NULL)
36802 {
36803- atomic_inc(&vcc->stats->rx_err);
36804+ atomic_inc_unchecked(&vcc->stats->rx_err);
36805 atm_return(vcc, skb->truesize);
36806 dev_kfree_skb_any(skb);
36807 goto INCR_DLE;
36808@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36809 if ((length > iadev->rx_buf_sz) || (length >
36810 (skb->len - sizeof(struct cpcs_trailer))))
36811 {
36812- atomic_inc(&vcc->stats->rx_err);
36813+ atomic_inc_unchecked(&vcc->stats->rx_err);
36814 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36815 length, skb->len);)
36816 atm_return(vcc, skb->truesize);
36817@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36818
36819 IF_RX(printk("rx_dle_intr: skb push");)
36820 vcc->push(vcc,skb);
36821- atomic_inc(&vcc->stats->rx);
36822+ atomic_inc_unchecked(&vcc->stats->rx);
36823 iadev->rx_pkt_cnt++;
36824 }
36825 INCR_DLE:
36826@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36827 {
36828 struct k_sonet_stats *stats;
36829 stats = &PRIV(_ia_dev[board])->sonet_stats;
36830- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36831- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36832- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36833- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36834- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36835- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36836- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36837- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36838- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36839+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36840+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36841+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36842+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36843+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36844+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36845+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36846+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36847+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36848 }
36849 ia_cmds.status = 0;
36850 break;
36851@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36852 if ((desc == 0) || (desc > iadev->num_tx_desc))
36853 {
36854 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36855- atomic_inc(&vcc->stats->tx);
36856+ atomic_inc_unchecked(&vcc->stats->tx);
36857 if (vcc->pop)
36858 vcc->pop(vcc, skb);
36859 else
36860@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36861 ATM_DESC(skb) = vcc->vci;
36862 skb_queue_tail(&iadev->tx_dma_q, skb);
36863
36864- atomic_inc(&vcc->stats->tx);
36865+ atomic_inc_unchecked(&vcc->stats->tx);
36866 iadev->tx_pkt_cnt++;
36867 /* Increment transaction counter */
36868 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36869
36870 #if 0
36871 /* add flow control logic */
36872- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36873+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36874 if (iavcc->vc_desc_cnt > 10) {
36875 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36876 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36877diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36878index fa7d701..1e404c7 100644
36879--- a/drivers/atm/lanai.c
36880+++ b/drivers/atm/lanai.c
36881@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36882 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36883 lanai_endtx(lanai, lvcc);
36884 lanai_free_skb(lvcc->tx.atmvcc, skb);
36885- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36886+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36887 }
36888
36889 /* Try to fill the buffer - don't call unless there is backlog */
36890@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36891 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36892 __net_timestamp(skb);
36893 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36894- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36895+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36896 out:
36897 lvcc->rx.buf.ptr = end;
36898 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36899@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36900 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36901 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36902 lanai->stats.service_rxnotaal5++;
36903- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36904+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36905 return 0;
36906 }
36907 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36908@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36909 int bytes;
36910 read_unlock(&vcc_sklist_lock);
36911 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36912- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36913+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36914 lvcc->stats.x.aal5.service_trash++;
36915 bytes = (SERVICE_GET_END(s) * 16) -
36916 (((unsigned long) lvcc->rx.buf.ptr) -
36917@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36918 }
36919 if (s & SERVICE_STREAM) {
36920 read_unlock(&vcc_sklist_lock);
36921- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36922+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36923 lvcc->stats.x.aal5.service_stream++;
36924 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36925 "PDU on VCI %d!\n", lanai->number, vci);
36926@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36927 return 0;
36928 }
36929 DPRINTK("got rx crc error on vci %d\n", vci);
36930- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36931+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36932 lvcc->stats.x.aal5.service_rxcrc++;
36933 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36934 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36935diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36936index 9587e95..b45c5cb 100644
36937--- a/drivers/atm/nicstar.c
36938+++ b/drivers/atm/nicstar.c
36939@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36940 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36941 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36942 card->index);
36943- atomic_inc(&vcc->stats->tx_err);
36944+ atomic_inc_unchecked(&vcc->stats->tx_err);
36945 dev_kfree_skb_any(skb);
36946 return -EINVAL;
36947 }
36948@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36949 if (!vc->tx) {
36950 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36951 card->index);
36952- atomic_inc(&vcc->stats->tx_err);
36953+ atomic_inc_unchecked(&vcc->stats->tx_err);
36954 dev_kfree_skb_any(skb);
36955 return -EINVAL;
36956 }
36957@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36958 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36959 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36960 card->index);
36961- atomic_inc(&vcc->stats->tx_err);
36962+ atomic_inc_unchecked(&vcc->stats->tx_err);
36963 dev_kfree_skb_any(skb);
36964 return -EINVAL;
36965 }
36966
36967 if (skb_shinfo(skb)->nr_frags != 0) {
36968 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36969- atomic_inc(&vcc->stats->tx_err);
36970+ atomic_inc_unchecked(&vcc->stats->tx_err);
36971 dev_kfree_skb_any(skb);
36972 return -EINVAL;
36973 }
36974@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36975 }
36976
36977 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36978- atomic_inc(&vcc->stats->tx_err);
36979+ atomic_inc_unchecked(&vcc->stats->tx_err);
36980 dev_kfree_skb_any(skb);
36981 return -EIO;
36982 }
36983- atomic_inc(&vcc->stats->tx);
36984+ atomic_inc_unchecked(&vcc->stats->tx);
36985
36986 return 0;
36987 }
36988@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36989 printk
36990 ("nicstar%d: Can't allocate buffers for aal0.\n",
36991 card->index);
36992- atomic_add(i, &vcc->stats->rx_drop);
36993+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36994 break;
36995 }
36996 if (!atm_charge(vcc, sb->truesize)) {
36997 RXPRINTK
36998 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36999 card->index);
37000- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37001+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37002 dev_kfree_skb_any(sb);
37003 break;
37004 }
37005@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37006 ATM_SKB(sb)->vcc = vcc;
37007 __net_timestamp(sb);
37008 vcc->push(vcc, sb);
37009- atomic_inc(&vcc->stats->rx);
37010+ atomic_inc_unchecked(&vcc->stats->rx);
37011 cell += ATM_CELL_PAYLOAD;
37012 }
37013
37014@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37015 if (iovb == NULL) {
37016 printk("nicstar%d: Out of iovec buffers.\n",
37017 card->index);
37018- atomic_inc(&vcc->stats->rx_drop);
37019+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37020 recycle_rx_buf(card, skb);
37021 return;
37022 }
37023@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37024 small or large buffer itself. */
37025 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37026 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37027- atomic_inc(&vcc->stats->rx_err);
37028+ atomic_inc_unchecked(&vcc->stats->rx_err);
37029 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37030 NS_MAX_IOVECS);
37031 NS_PRV_IOVCNT(iovb) = 0;
37032@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37033 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37034 card->index);
37035 which_list(card, skb);
37036- atomic_inc(&vcc->stats->rx_err);
37037+ atomic_inc_unchecked(&vcc->stats->rx_err);
37038 recycle_rx_buf(card, skb);
37039 vc->rx_iov = NULL;
37040 recycle_iov_buf(card, iovb);
37041@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37042 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37043 card->index);
37044 which_list(card, skb);
37045- atomic_inc(&vcc->stats->rx_err);
37046+ atomic_inc_unchecked(&vcc->stats->rx_err);
37047 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37048 NS_PRV_IOVCNT(iovb));
37049 vc->rx_iov = NULL;
37050@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37051 printk(" - PDU size mismatch.\n");
37052 else
37053 printk(".\n");
37054- atomic_inc(&vcc->stats->rx_err);
37055+ atomic_inc_unchecked(&vcc->stats->rx_err);
37056 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37057 NS_PRV_IOVCNT(iovb));
37058 vc->rx_iov = NULL;
37059@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37060 /* skb points to a small buffer */
37061 if (!atm_charge(vcc, skb->truesize)) {
37062 push_rxbufs(card, skb);
37063- atomic_inc(&vcc->stats->rx_drop);
37064+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37065 } else {
37066 skb_put(skb, len);
37067 dequeue_sm_buf(card, skb);
37068@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37069 ATM_SKB(skb)->vcc = vcc;
37070 __net_timestamp(skb);
37071 vcc->push(vcc, skb);
37072- atomic_inc(&vcc->stats->rx);
37073+ atomic_inc_unchecked(&vcc->stats->rx);
37074 }
37075 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37076 struct sk_buff *sb;
37077@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37078 if (len <= NS_SMBUFSIZE) {
37079 if (!atm_charge(vcc, sb->truesize)) {
37080 push_rxbufs(card, sb);
37081- atomic_inc(&vcc->stats->rx_drop);
37082+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37083 } else {
37084 skb_put(sb, len);
37085 dequeue_sm_buf(card, sb);
37086@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37087 ATM_SKB(sb)->vcc = vcc;
37088 __net_timestamp(sb);
37089 vcc->push(vcc, sb);
37090- atomic_inc(&vcc->stats->rx);
37091+ atomic_inc_unchecked(&vcc->stats->rx);
37092 }
37093
37094 push_rxbufs(card, skb);
37095@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37096
37097 if (!atm_charge(vcc, skb->truesize)) {
37098 push_rxbufs(card, skb);
37099- atomic_inc(&vcc->stats->rx_drop);
37100+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37101 } else {
37102 dequeue_lg_buf(card, skb);
37103 #ifdef NS_USE_DESTRUCTORS
37104@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37105 ATM_SKB(skb)->vcc = vcc;
37106 __net_timestamp(skb);
37107 vcc->push(vcc, skb);
37108- atomic_inc(&vcc->stats->rx);
37109+ atomic_inc_unchecked(&vcc->stats->rx);
37110 }
37111
37112 push_rxbufs(card, sb);
37113@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37114 printk
37115 ("nicstar%d: Out of huge buffers.\n",
37116 card->index);
37117- atomic_inc(&vcc->stats->rx_drop);
37118+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37119 recycle_iovec_rx_bufs(card,
37120 (struct iovec *)
37121 iovb->data,
37122@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37123 card->hbpool.count++;
37124 } else
37125 dev_kfree_skb_any(hb);
37126- atomic_inc(&vcc->stats->rx_drop);
37127+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37128 } else {
37129 /* Copy the small buffer to the huge buffer */
37130 sb = (struct sk_buff *)iov->iov_base;
37131@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37132 #endif /* NS_USE_DESTRUCTORS */
37133 __net_timestamp(hb);
37134 vcc->push(vcc, hb);
37135- atomic_inc(&vcc->stats->rx);
37136+ atomic_inc_unchecked(&vcc->stats->rx);
37137 }
37138 }
37139
37140diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37141index e3fb496..d9646bf 100644
37142--- a/drivers/atm/solos-pci.c
37143+++ b/drivers/atm/solos-pci.c
37144@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37145 }
37146 atm_charge(vcc, skb->truesize);
37147 vcc->push(vcc, skb);
37148- atomic_inc(&vcc->stats->rx);
37149+ atomic_inc_unchecked(&vcc->stats->rx);
37150 break;
37151
37152 case PKT_STATUS:
37153@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37154 vcc = SKB_CB(oldskb)->vcc;
37155
37156 if (vcc) {
37157- atomic_inc(&vcc->stats->tx);
37158+ atomic_inc_unchecked(&vcc->stats->tx);
37159 solos_pop(vcc, oldskb);
37160 } else {
37161 dev_kfree_skb_irq(oldskb);
37162diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37163index 0215934..ce9f5b1 100644
37164--- a/drivers/atm/suni.c
37165+++ b/drivers/atm/suni.c
37166@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37167
37168
37169 #define ADD_LIMITED(s,v) \
37170- atomic_add((v),&stats->s); \
37171- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37172+ atomic_add_unchecked((v),&stats->s); \
37173+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37174
37175
37176 static void suni_hz(unsigned long from_timer)
37177diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37178index 5120a96..e2572bd 100644
37179--- a/drivers/atm/uPD98402.c
37180+++ b/drivers/atm/uPD98402.c
37181@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37182 struct sonet_stats tmp;
37183 int error = 0;
37184
37185- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37186+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37187 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37188 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37189 if (zero && !error) {
37190@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37191
37192
37193 #define ADD_LIMITED(s,v) \
37194- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37195- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37196- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37197+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37198+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37199+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37200
37201
37202 static void stat_event(struct atm_dev *dev)
37203@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37204 if (reason & uPD98402_INT_PFM) stat_event(dev);
37205 if (reason & uPD98402_INT_PCO) {
37206 (void) GET(PCOCR); /* clear interrupt cause */
37207- atomic_add(GET(HECCT),
37208+ atomic_add_unchecked(GET(HECCT),
37209 &PRIV(dev)->sonet_stats.uncorr_hcs);
37210 }
37211 if ((reason & uPD98402_INT_RFO) &&
37212@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37213 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37214 uPD98402_INT_LOS),PIMR); /* enable them */
37215 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37216- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37217- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37218- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37219+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37220+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37221+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37222 return 0;
37223 }
37224
37225diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37226index 969c3c2..9b72956 100644
37227--- a/drivers/atm/zatm.c
37228+++ b/drivers/atm/zatm.c
37229@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37230 }
37231 if (!size) {
37232 dev_kfree_skb_irq(skb);
37233- if (vcc) atomic_inc(&vcc->stats->rx_err);
37234+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37235 continue;
37236 }
37237 if (!atm_charge(vcc,skb->truesize)) {
37238@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37239 skb->len = size;
37240 ATM_SKB(skb)->vcc = vcc;
37241 vcc->push(vcc,skb);
37242- atomic_inc(&vcc->stats->rx);
37243+ atomic_inc_unchecked(&vcc->stats->rx);
37244 }
37245 zout(pos & 0xffff,MTA(mbx));
37246 #if 0 /* probably a stupid idea */
37247@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37248 skb_queue_head(&zatm_vcc->backlog,skb);
37249 break;
37250 }
37251- atomic_inc(&vcc->stats->tx);
37252+ atomic_inc_unchecked(&vcc->stats->tx);
37253 wake_up(&zatm_vcc->tx_wait);
37254 }
37255
37256diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37257index 59dc808..f10c74e 100644
37258--- a/drivers/base/bus.c
37259+++ b/drivers/base/bus.c
37260@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37261 return -EINVAL;
37262
37263 mutex_lock(&subsys->p->mutex);
37264- list_add_tail(&sif->node, &subsys->p->interfaces);
37265+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37266 if (sif->add_dev) {
37267 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37268 while ((dev = subsys_dev_iter_next(&iter)))
37269@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37270 subsys = sif->subsys;
37271
37272 mutex_lock(&subsys->p->mutex);
37273- list_del_init(&sif->node);
37274+ pax_list_del_init((struct list_head *)&sif->node);
37275 if (sif->remove_dev) {
37276 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37277 while ((dev = subsys_dev_iter_next(&iter)))
37278diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37279index 25798db..15f130e 100644
37280--- a/drivers/base/devtmpfs.c
37281+++ b/drivers/base/devtmpfs.c
37282@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37283 if (!thread)
37284 return 0;
37285
37286- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37287+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37288 if (err)
37289 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37290 else
37291@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37292 *err = sys_unshare(CLONE_NEWNS);
37293 if (*err)
37294 goto out;
37295- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37296+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37297 if (*err)
37298 goto out;
37299- sys_chdir("/.."); /* will traverse into overmounted root */
37300- sys_chroot(".");
37301+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37302+ sys_chroot((char __force_user *)".");
37303 complete(&setup_done);
37304 while (1) {
37305 spin_lock(&req_lock);
37306diff --git a/drivers/base/node.c b/drivers/base/node.c
37307index bc9f43b..29703b8 100644
37308--- a/drivers/base/node.c
37309+++ b/drivers/base/node.c
37310@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37311 struct node_attr {
37312 struct device_attribute attr;
37313 enum node_states state;
37314-};
37315+} __do_const;
37316
37317 static ssize_t show_node_state(struct device *dev,
37318 struct device_attribute *attr, char *buf)
37319diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37320index bfb8955..4ebff34 100644
37321--- a/drivers/base/power/domain.c
37322+++ b/drivers/base/power/domain.c
37323@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37324
37325 if (dev->power.subsys_data->domain_data) {
37326 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37327- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37328+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37329 if (clear_td)
37330- gpd_data->td = (struct gpd_timing_data){ 0 };
37331+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37332
37333 if (--gpd_data->refcount == 0) {
37334 dev->power.subsys_data->domain_data = NULL;
37335@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37336 {
37337 struct cpuidle_driver *cpuidle_drv;
37338 struct gpd_cpu_data *cpu_data;
37339- struct cpuidle_state *idle_state;
37340+ cpuidle_state_no_const *idle_state;
37341 int ret = 0;
37342
37343 if (IS_ERR_OR_NULL(genpd) || state < 0)
37344@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37345 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37346 {
37347 struct gpd_cpu_data *cpu_data;
37348- struct cpuidle_state *idle_state;
37349+ cpuidle_state_no_const *idle_state;
37350 int ret = 0;
37351
37352 if (IS_ERR_OR_NULL(genpd))
37353diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37354index 03e089a..0e9560c 100644
37355--- a/drivers/base/power/sysfs.c
37356+++ b/drivers/base/power/sysfs.c
37357@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37358 return -EIO;
37359 }
37360 }
37361- return sprintf(buf, p);
37362+ return sprintf(buf, "%s", p);
37363 }
37364
37365 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37366diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37367index 2d56f41..8830f19 100644
37368--- a/drivers/base/power/wakeup.c
37369+++ b/drivers/base/power/wakeup.c
37370@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37371 * They need to be modified together atomically, so it's better to use one
37372 * atomic variable to hold them both.
37373 */
37374-static atomic_t combined_event_count = ATOMIC_INIT(0);
37375+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37376
37377 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37378 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37379
37380 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37381 {
37382- unsigned int comb = atomic_read(&combined_event_count);
37383+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37384
37385 *cnt = (comb >> IN_PROGRESS_BITS);
37386 *inpr = comb & MAX_IN_PROGRESS;
37387@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37388 ws->start_prevent_time = ws->last_time;
37389
37390 /* Increment the counter of events in progress. */
37391- cec = atomic_inc_return(&combined_event_count);
37392+ cec = atomic_inc_return_unchecked(&combined_event_count);
37393
37394 trace_wakeup_source_activate(ws->name, cec);
37395 }
37396@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37397 * Increment the counter of registered wakeup events and decrement the
37398 * couter of wakeup events in progress simultaneously.
37399 */
37400- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37401+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37402 trace_wakeup_source_deactivate(ws->name, cec);
37403
37404 split_counters(&cnt, &inpr);
37405diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37406index e8d11b6..7b1b36f 100644
37407--- a/drivers/base/syscore.c
37408+++ b/drivers/base/syscore.c
37409@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37410 void register_syscore_ops(struct syscore_ops *ops)
37411 {
37412 mutex_lock(&syscore_ops_lock);
37413- list_add_tail(&ops->node, &syscore_ops_list);
37414+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37415 mutex_unlock(&syscore_ops_lock);
37416 }
37417 EXPORT_SYMBOL_GPL(register_syscore_ops);
37418@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37419 void unregister_syscore_ops(struct syscore_ops *ops)
37420 {
37421 mutex_lock(&syscore_ops_lock);
37422- list_del(&ops->node);
37423+ pax_list_del((struct list_head *)&ops->node);
37424 mutex_unlock(&syscore_ops_lock);
37425 }
37426 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37427diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37428index 036e8ab..6221dec 100644
37429--- a/drivers/block/cciss.c
37430+++ b/drivers/block/cciss.c
37431@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37432 while (!list_empty(&h->reqQ)) {
37433 c = list_entry(h->reqQ.next, CommandList_struct, list);
37434 /* can't do anything if fifo is full */
37435- if ((h->access.fifo_full(h))) {
37436+ if ((h->access->fifo_full(h))) {
37437 dev_warn(&h->pdev->dev, "fifo full\n");
37438 break;
37439 }
37440@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37441 h->Qdepth--;
37442
37443 /* Tell the controller execute command */
37444- h->access.submit_command(h, c);
37445+ h->access->submit_command(h, c);
37446
37447 /* Put job onto the completed Q */
37448 addQ(&h->cmpQ, c);
37449@@ -3447,17 +3447,17 @@ startio:
37450
37451 static inline unsigned long get_next_completion(ctlr_info_t *h)
37452 {
37453- return h->access.command_completed(h);
37454+ return h->access->command_completed(h);
37455 }
37456
37457 static inline int interrupt_pending(ctlr_info_t *h)
37458 {
37459- return h->access.intr_pending(h);
37460+ return h->access->intr_pending(h);
37461 }
37462
37463 static inline long interrupt_not_for_us(ctlr_info_t *h)
37464 {
37465- return ((h->access.intr_pending(h) == 0) ||
37466+ return ((h->access->intr_pending(h) == 0) ||
37467 (h->interrupts_enabled == 0));
37468 }
37469
37470@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37471 u32 a;
37472
37473 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37474- return h->access.command_completed(h);
37475+ return h->access->command_completed(h);
37476
37477 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37478 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37479@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37480 trans_support & CFGTBL_Trans_use_short_tags);
37481
37482 /* Change the access methods to the performant access methods */
37483- h->access = SA5_performant_access;
37484+ h->access = &SA5_performant_access;
37485 h->transMethod = CFGTBL_Trans_Performant;
37486
37487 return;
37488@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37489 if (prod_index < 0)
37490 return -ENODEV;
37491 h->product_name = products[prod_index].product_name;
37492- h->access = *(products[prod_index].access);
37493+ h->access = products[prod_index].access;
37494
37495 if (cciss_board_disabled(h)) {
37496 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37497@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37498 }
37499
37500 /* make sure the board interrupts are off */
37501- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37502+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37503 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37504 if (rc)
37505 goto clean2;
37506@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37507 * fake ones to scoop up any residual completions.
37508 */
37509 spin_lock_irqsave(&h->lock, flags);
37510- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37511+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37512 spin_unlock_irqrestore(&h->lock, flags);
37513 free_irq(h->intr[h->intr_mode], h);
37514 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37515@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37516 dev_info(&h->pdev->dev, "Board READY.\n");
37517 dev_info(&h->pdev->dev,
37518 "Waiting for stale completions to drain.\n");
37519- h->access.set_intr_mask(h, CCISS_INTR_ON);
37520+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37521 msleep(10000);
37522- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37523+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37524
37525 rc = controller_reset_failed(h->cfgtable);
37526 if (rc)
37527@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37528 cciss_scsi_setup(h);
37529
37530 /* Turn the interrupts on so we can service requests */
37531- h->access.set_intr_mask(h, CCISS_INTR_ON);
37532+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37533
37534 /* Get the firmware version */
37535 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37536@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37537 kfree(flush_buf);
37538 if (return_code != IO_OK)
37539 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37540- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37541+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37542 free_irq(h->intr[h->intr_mode], h);
37543 }
37544
37545diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37546index 7fda30e..2f27946 100644
37547--- a/drivers/block/cciss.h
37548+++ b/drivers/block/cciss.h
37549@@ -101,7 +101,7 @@ struct ctlr_info
37550 /* information about each logical volume */
37551 drive_info_struct *drv[CISS_MAX_LUN];
37552
37553- struct access_method access;
37554+ struct access_method *access;
37555
37556 /* queue and queue Info */
37557 struct list_head reqQ;
37558@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37559 }
37560
37561 static struct access_method SA5_access = {
37562- SA5_submit_command,
37563- SA5_intr_mask,
37564- SA5_fifo_full,
37565- SA5_intr_pending,
37566- SA5_completed,
37567+ .submit_command = SA5_submit_command,
37568+ .set_intr_mask = SA5_intr_mask,
37569+ .fifo_full = SA5_fifo_full,
37570+ .intr_pending = SA5_intr_pending,
37571+ .command_completed = SA5_completed,
37572 };
37573
37574 static struct access_method SA5B_access = {
37575- SA5_submit_command,
37576- SA5B_intr_mask,
37577- SA5_fifo_full,
37578- SA5B_intr_pending,
37579- SA5_completed,
37580+ .submit_command = SA5_submit_command,
37581+ .set_intr_mask = SA5B_intr_mask,
37582+ .fifo_full = SA5_fifo_full,
37583+ .intr_pending = SA5B_intr_pending,
37584+ .command_completed = SA5_completed,
37585 };
37586
37587 static struct access_method SA5_performant_access = {
37588- SA5_submit_command,
37589- SA5_performant_intr_mask,
37590- SA5_fifo_full,
37591- SA5_performant_intr_pending,
37592- SA5_performant_completed,
37593+ .submit_command = SA5_submit_command,
37594+ .set_intr_mask = SA5_performant_intr_mask,
37595+ .fifo_full = SA5_fifo_full,
37596+ .intr_pending = SA5_performant_intr_pending,
37597+ .command_completed = SA5_performant_completed,
37598 };
37599
37600 struct board_type {
37601diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37602index 2b94403..fd6ad1f 100644
37603--- a/drivers/block/cpqarray.c
37604+++ b/drivers/block/cpqarray.c
37605@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37606 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37607 goto Enomem4;
37608 }
37609- hba[i]->access.set_intr_mask(hba[i], 0);
37610+ hba[i]->access->set_intr_mask(hba[i], 0);
37611 if (request_irq(hba[i]->intr, do_ida_intr,
37612 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37613 {
37614@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37615 add_timer(&hba[i]->timer);
37616
37617 /* Enable IRQ now that spinlock and rate limit timer are set up */
37618- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37619+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37620
37621 for(j=0; j<NWD; j++) {
37622 struct gendisk *disk = ida_gendisk[i][j];
37623@@ -694,7 +694,7 @@ DBGINFO(
37624 for(i=0; i<NR_PRODUCTS; i++) {
37625 if (board_id == products[i].board_id) {
37626 c->product_name = products[i].product_name;
37627- c->access = *(products[i].access);
37628+ c->access = products[i].access;
37629 break;
37630 }
37631 }
37632@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37633 hba[ctlr]->intr = intr;
37634 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37635 hba[ctlr]->product_name = products[j].product_name;
37636- hba[ctlr]->access = *(products[j].access);
37637+ hba[ctlr]->access = products[j].access;
37638 hba[ctlr]->ctlr = ctlr;
37639 hba[ctlr]->board_id = board_id;
37640 hba[ctlr]->pci_dev = NULL; /* not PCI */
37641@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37642
37643 while((c = h->reqQ) != NULL) {
37644 /* Can't do anything if we're busy */
37645- if (h->access.fifo_full(h) == 0)
37646+ if (h->access->fifo_full(h) == 0)
37647 return;
37648
37649 /* Get the first entry from the request Q */
37650@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37651 h->Qdepth--;
37652
37653 /* Tell the controller to do our bidding */
37654- h->access.submit_command(h, c);
37655+ h->access->submit_command(h, c);
37656
37657 /* Get onto the completion Q */
37658 addQ(&h->cmpQ, c);
37659@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37660 unsigned long flags;
37661 __u32 a,a1;
37662
37663- istat = h->access.intr_pending(h);
37664+ istat = h->access->intr_pending(h);
37665 /* Is this interrupt for us? */
37666 if (istat == 0)
37667 return IRQ_NONE;
37668@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37669 */
37670 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37671 if (istat & FIFO_NOT_EMPTY) {
37672- while((a = h->access.command_completed(h))) {
37673+ while((a = h->access->command_completed(h))) {
37674 a1 = a; a &= ~3;
37675 if ((c = h->cmpQ) == NULL)
37676 {
37677@@ -1448,11 +1448,11 @@ static int sendcmd(
37678 /*
37679 * Disable interrupt
37680 */
37681- info_p->access.set_intr_mask(info_p, 0);
37682+ info_p->access->set_intr_mask(info_p, 0);
37683 /* Make sure there is room in the command FIFO */
37684 /* Actually it should be completely empty at this time. */
37685 for (i = 200000; i > 0; i--) {
37686- temp = info_p->access.fifo_full(info_p);
37687+ temp = info_p->access->fifo_full(info_p);
37688 if (temp != 0) {
37689 break;
37690 }
37691@@ -1465,7 +1465,7 @@ DBG(
37692 /*
37693 * Send the cmd
37694 */
37695- info_p->access.submit_command(info_p, c);
37696+ info_p->access->submit_command(info_p, c);
37697 complete = pollcomplete(ctlr);
37698
37699 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37700@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37701 * we check the new geometry. Then turn interrupts back on when
37702 * we're done.
37703 */
37704- host->access.set_intr_mask(host, 0);
37705+ host->access->set_intr_mask(host, 0);
37706 getgeometry(ctlr);
37707- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37708+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37709
37710 for(i=0; i<NWD; i++) {
37711 struct gendisk *disk = ida_gendisk[ctlr][i];
37712@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37713 /* Wait (up to 2 seconds) for a command to complete */
37714
37715 for (i = 200000; i > 0; i--) {
37716- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37717+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37718 if (done == 0) {
37719 udelay(10); /* a short fixed delay */
37720 } else
37721diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37722index be73e9d..7fbf140 100644
37723--- a/drivers/block/cpqarray.h
37724+++ b/drivers/block/cpqarray.h
37725@@ -99,7 +99,7 @@ struct ctlr_info {
37726 drv_info_t drv[NWD];
37727 struct proc_dir_entry *proc;
37728
37729- struct access_method access;
37730+ struct access_method *access;
37731
37732 cmdlist_t *reqQ;
37733 cmdlist_t *cmpQ;
37734diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37735index 0e06f0c..c47b81d 100644
37736--- a/drivers/block/drbd/drbd_int.h
37737+++ b/drivers/block/drbd/drbd_int.h
37738@@ -582,7 +582,7 @@ struct drbd_epoch {
37739 struct drbd_tconn *tconn;
37740 struct list_head list;
37741 unsigned int barrier_nr;
37742- atomic_t epoch_size; /* increased on every request added. */
37743+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37744 atomic_t active; /* increased on every req. added, and dec on every finished. */
37745 unsigned long flags;
37746 };
37747@@ -1022,7 +1022,7 @@ struct drbd_conf {
37748 unsigned int al_tr_number;
37749 int al_tr_cycle;
37750 wait_queue_head_t seq_wait;
37751- atomic_t packet_seq;
37752+ atomic_unchecked_t packet_seq;
37753 unsigned int peer_seq;
37754 spinlock_t peer_seq_lock;
37755 unsigned int minor;
37756@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37757 char __user *uoptval;
37758 int err;
37759
37760- uoptval = (char __user __force *)optval;
37761+ uoptval = (char __force_user *)optval;
37762
37763 set_fs(KERNEL_DS);
37764 if (level == SOL_SOCKET)
37765diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37766index 89c497c..9c736ae 100644
37767--- a/drivers/block/drbd/drbd_interval.c
37768+++ b/drivers/block/drbd/drbd_interval.c
37769@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37770 }
37771
37772 static const struct rb_augment_callbacks augment_callbacks = {
37773- augment_propagate,
37774- augment_copy,
37775- augment_rotate,
37776+ .propagate = augment_propagate,
37777+ .copy = augment_copy,
37778+ .rotate = augment_rotate,
37779 };
37780
37781 /**
37782diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37783index 929468e..7d934eb 100644
37784--- a/drivers/block/drbd/drbd_main.c
37785+++ b/drivers/block/drbd/drbd_main.c
37786@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37787 p->sector = sector;
37788 p->block_id = block_id;
37789 p->blksize = blksize;
37790- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37791+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37792 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37793 }
37794
37795@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37796 return -EIO;
37797 p->sector = cpu_to_be64(req->i.sector);
37798 p->block_id = (unsigned long)req;
37799- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37800+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37801 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37802 if (mdev->state.conn >= C_SYNC_SOURCE &&
37803 mdev->state.conn <= C_PAUSED_SYNC_T)
37804@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
37805 {
37806 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37807
37808- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37809- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37810+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37811+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37812 kfree(tconn->current_epoch);
37813
37814 idr_destroy(&tconn->volumes);
37815diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37816index c706d50..5e1b472 100644
37817--- a/drivers/block/drbd/drbd_nl.c
37818+++ b/drivers/block/drbd/drbd_nl.c
37819@@ -3440,7 +3440,7 @@ out:
37820
37821 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37822 {
37823- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37824+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37825 struct sk_buff *msg;
37826 struct drbd_genlmsghdr *d_out;
37827 unsigned seq;
37828@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37829 return;
37830 }
37831
37832- seq = atomic_inc_return(&drbd_genl_seq);
37833+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37834 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37835 if (!msg)
37836 goto failed;
37837diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37838index d073305..4998fea 100644
37839--- a/drivers/block/drbd/drbd_receiver.c
37840+++ b/drivers/block/drbd/drbd_receiver.c
37841@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37842 {
37843 int err;
37844
37845- atomic_set(&mdev->packet_seq, 0);
37846+ atomic_set_unchecked(&mdev->packet_seq, 0);
37847 mdev->peer_seq = 0;
37848
37849 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37850@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37851 do {
37852 next_epoch = NULL;
37853
37854- epoch_size = atomic_read(&epoch->epoch_size);
37855+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37856
37857 switch (ev & ~EV_CLEANUP) {
37858 case EV_PUT:
37859@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37860 rv = FE_DESTROYED;
37861 } else {
37862 epoch->flags = 0;
37863- atomic_set(&epoch->epoch_size, 0);
37864+ atomic_set_unchecked(&epoch->epoch_size, 0);
37865 /* atomic_set(&epoch->active, 0); is already zero */
37866 if (rv == FE_STILL_LIVE)
37867 rv = FE_RECYCLED;
37868@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37869 conn_wait_active_ee_empty(tconn);
37870 drbd_flush(tconn);
37871
37872- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37873+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37874 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37875 if (epoch)
37876 break;
37877@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37878 }
37879
37880 epoch->flags = 0;
37881- atomic_set(&epoch->epoch_size, 0);
37882+ atomic_set_unchecked(&epoch->epoch_size, 0);
37883 atomic_set(&epoch->active, 0);
37884
37885 spin_lock(&tconn->epoch_lock);
37886- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37887+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37888 list_add(&epoch->list, &tconn->current_epoch->list);
37889 tconn->current_epoch = epoch;
37890 tconn->epochs++;
37891@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37892
37893 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37894 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37895- atomic_inc(&tconn->current_epoch->epoch_size);
37896+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37897 err2 = drbd_drain_block(mdev, pi->size);
37898 if (!err)
37899 err = err2;
37900@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37901
37902 spin_lock(&tconn->epoch_lock);
37903 peer_req->epoch = tconn->current_epoch;
37904- atomic_inc(&peer_req->epoch->epoch_size);
37905+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37906 atomic_inc(&peer_req->epoch->active);
37907 spin_unlock(&tconn->epoch_lock);
37908
37909@@ -4345,7 +4345,7 @@ struct data_cmd {
37910 int expect_payload;
37911 size_t pkt_size;
37912 int (*fn)(struct drbd_tconn *, struct packet_info *);
37913-};
37914+} __do_const;
37915
37916 static struct data_cmd drbd_cmd_handler[] = {
37917 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37918@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37919 if (!list_empty(&tconn->current_epoch->list))
37920 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37921 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37922- atomic_set(&tconn->current_epoch->epoch_size, 0);
37923+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37924 tconn->send.seen_any_write_yet = false;
37925
37926 conn_info(tconn, "Connection closed\n");
37927@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37928 struct asender_cmd {
37929 size_t pkt_size;
37930 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37931-};
37932+} __do_const;
37933
37934 static struct asender_cmd asender_tbl[] = {
37935 [P_PING] = { 0, got_Ping },
37936diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
37937index 2023043..dab515c 100644
37938--- a/drivers/block/floppy.c
37939+++ b/drivers/block/floppy.c
37940@@ -3053,7 +3053,10 @@ static int raw_cmd_copyout(int cmd, void __user *param,
37941 int ret;
37942
37943 while (ptr) {
37944- ret = copy_to_user(param, ptr, sizeof(*ptr));
37945+ struct floppy_raw_cmd cmd = *ptr;
37946+ cmd.next = NULL;
37947+ cmd.kernel_data = NULL;
37948+ ret = copy_to_user(param, &cmd, sizeof(cmd));
37949 if (ret)
37950 return -EFAULT;
37951 param += sizeof(struct floppy_raw_cmd);
37952@@ -3107,10 +3110,11 @@ loop:
37953 return -ENOMEM;
37954 *rcmd = ptr;
37955 ret = copy_from_user(ptr, param, sizeof(*ptr));
37956- if (ret)
37957- return -EFAULT;
37958 ptr->next = NULL;
37959 ptr->buffer_length = 0;
37960+ ptr->kernel_data = NULL;
37961+ if (ret)
37962+ return -EFAULT;
37963 param += sizeof(struct floppy_raw_cmd);
37964 if (ptr->cmd_count > 33)
37965 /* the command may now also take up the space
37966@@ -3126,7 +3130,6 @@ loop:
37967 for (i = 0; i < 16; i++)
37968 ptr->reply[i] = 0;
37969 ptr->resultcode = 0;
37970- ptr->kernel_data = NULL;
37971
37972 if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
37973 if (ptr->length <= 0)
37974diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37975index 66e8c3b..9b68dd9 100644
37976--- a/drivers/block/loop.c
37977+++ b/drivers/block/loop.c
37978@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37979
37980 file_start_write(file);
37981 set_fs(get_ds());
37982- bw = file->f_op->write(file, buf, len, &pos);
37983+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37984 set_fs(old_fs);
37985 file_end_write(file);
37986 if (likely(bw == len))
37987diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37988index 091b9ea..f5428f8 100644
37989--- a/drivers/block/null_blk.c
37990+++ b/drivers/block/null_blk.c
37991@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37992 return 0;
37993 }
37994
37995-static struct blk_mq_ops null_mq_ops = {
37996- .queue_rq = null_queue_rq,
37997- .map_queue = blk_mq_map_queue,
37998+static struct blk_mq_ops null_mq_single_ops = {
37999+ .queue_rq = null_queue_rq,
38000+ .map_queue = blk_mq_map_queue,
38001 .init_hctx = null_init_hctx,
38002 .complete = null_softirq_done_fn,
38003+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38004+ .free_hctx = blk_mq_free_single_hw_queue,
38005+};
38006+
38007+static struct blk_mq_ops null_mq_per_node_ops = {
38008+ .queue_rq = null_queue_rq,
38009+ .map_queue = blk_mq_map_queue,
38010+ .init_hctx = null_init_hctx,
38011+ .alloc_hctx = null_alloc_hctx,
38012+ .free_hctx = null_free_hctx,
38013 };
38014
38015 static struct blk_mq_reg null_mq_reg = {
38016- .ops = &null_mq_ops,
38017+ .ops = &null_mq_single_ops,
38018 .queue_depth = 64,
38019 .cmd_size = sizeof(struct nullb_cmd),
38020 .flags = BLK_MQ_F_SHOULD_MERGE,
38021@@ -521,13 +531,8 @@ static int null_add_dev(void)
38022 null_mq_reg.queue_depth = hw_queue_depth;
38023 null_mq_reg.nr_hw_queues = submit_queues;
38024
38025- if (use_per_node_hctx) {
38026- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38027- null_mq_reg.ops->free_hctx = null_free_hctx;
38028- } else {
38029- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38030- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38031- }
38032+ if (use_per_node_hctx)
38033+ null_mq_reg.ops = &null_mq_per_node_ops;
38034
38035 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38036 } else if (queue_mode == NULL_Q_BIO) {
38037diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38038index a2af73d..c0b8f61 100644
38039--- a/drivers/block/pktcdvd.c
38040+++ b/drivers/block/pktcdvd.c
38041@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38042
38043 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38044 {
38045- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38046+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38047 }
38048
38049 /*
38050@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38051 return -EROFS;
38052 }
38053 pd->settings.fp = ti.fp;
38054- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38055+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38056
38057 if (ti.nwa_v) {
38058 pd->nwa = be32_to_cpu(ti.next_writable);
38059diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38060index e5565fb..71be10b4 100644
38061--- a/drivers/block/smart1,2.h
38062+++ b/drivers/block/smart1,2.h
38063@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38064 }
38065
38066 static struct access_method smart4_access = {
38067- smart4_submit_command,
38068- smart4_intr_mask,
38069- smart4_fifo_full,
38070- smart4_intr_pending,
38071- smart4_completed,
38072+ .submit_command = smart4_submit_command,
38073+ .set_intr_mask = smart4_intr_mask,
38074+ .fifo_full = smart4_fifo_full,
38075+ .intr_pending = smart4_intr_pending,
38076+ .command_completed = smart4_completed,
38077 };
38078
38079 /*
38080@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38081 }
38082
38083 static struct access_method smart2_access = {
38084- smart2_submit_command,
38085- smart2_intr_mask,
38086- smart2_fifo_full,
38087- smart2_intr_pending,
38088- smart2_completed,
38089+ .submit_command = smart2_submit_command,
38090+ .set_intr_mask = smart2_intr_mask,
38091+ .fifo_full = smart2_fifo_full,
38092+ .intr_pending = smart2_intr_pending,
38093+ .command_completed = smart2_completed,
38094 };
38095
38096 /*
38097@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38098 }
38099
38100 static struct access_method smart2e_access = {
38101- smart2e_submit_command,
38102- smart2e_intr_mask,
38103- smart2e_fifo_full,
38104- smart2e_intr_pending,
38105- smart2e_completed,
38106+ .submit_command = smart2e_submit_command,
38107+ .set_intr_mask = smart2e_intr_mask,
38108+ .fifo_full = smart2e_fifo_full,
38109+ .intr_pending = smart2e_intr_pending,
38110+ .command_completed = smart2e_completed,
38111 };
38112
38113 /*
38114@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38115 }
38116
38117 static struct access_method smart1_access = {
38118- smart1_submit_command,
38119- smart1_intr_mask,
38120- smart1_fifo_full,
38121- smart1_intr_pending,
38122- smart1_completed,
38123+ .submit_command = smart1_submit_command,
38124+ .set_intr_mask = smart1_intr_mask,
38125+ .fifo_full = smart1_fifo_full,
38126+ .intr_pending = smart1_intr_pending,
38127+ .command_completed = smart1_completed,
38128 };
38129diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38130index f038dba..bb74c08 100644
38131--- a/drivers/bluetooth/btwilink.c
38132+++ b/drivers/bluetooth/btwilink.c
38133@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38134
38135 static int bt_ti_probe(struct platform_device *pdev)
38136 {
38137- static struct ti_st *hst;
38138+ struct ti_st *hst;
38139 struct hci_dev *hdev;
38140 int err;
38141
38142diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38143index 8a3aff7..d7538c2 100644
38144--- a/drivers/cdrom/cdrom.c
38145+++ b/drivers/cdrom/cdrom.c
38146@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38147 ENSURE(reset, CDC_RESET);
38148 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38149 cdi->mc_flags = 0;
38150- cdo->n_minors = 0;
38151 cdi->options = CDO_USE_FFLAGS;
38152
38153 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38154@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38155 else
38156 cdi->cdda_method = CDDA_OLD;
38157
38158- if (!cdo->generic_packet)
38159- cdo->generic_packet = cdrom_dummy_generic_packet;
38160+ if (!cdo->generic_packet) {
38161+ pax_open_kernel();
38162+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38163+ pax_close_kernel();
38164+ }
38165
38166 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38167 mutex_lock(&cdrom_mutex);
38168@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38169 if (cdi->exit)
38170 cdi->exit(cdi);
38171
38172- cdi->ops->n_minors--;
38173 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38174 }
38175
38176@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38177 */
38178 nr = nframes;
38179 do {
38180- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38181+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38182 if (cgc.buffer)
38183 break;
38184
38185@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38186 struct cdrom_device_info *cdi;
38187 int ret;
38188
38189- ret = scnprintf(info + *pos, max_size - *pos, header);
38190+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38191 if (!ret)
38192 return 1;
38193
38194diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38195index 51e75ad..39c4c76 100644
38196--- a/drivers/cdrom/gdrom.c
38197+++ b/drivers/cdrom/gdrom.c
38198@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38199 .audio_ioctl = gdrom_audio_ioctl,
38200 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38201 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38202- .n_minors = 1,
38203 };
38204
38205 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38206diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38207index 1386749..5430258 100644
38208--- a/drivers/char/Kconfig
38209+++ b/drivers/char/Kconfig
38210@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38211
38212 config DEVKMEM
38213 bool "/dev/kmem virtual device support"
38214- default y
38215+ default n
38216+ depends on !GRKERNSEC_KMEM
38217 help
38218 Say Y here if you want to support the /dev/kmem device. The
38219 /dev/kmem device is rarely used, but can be used for certain
38220@@ -577,6 +578,7 @@ config DEVPORT
38221 bool
38222 depends on !M68K
38223 depends on ISA || PCI
38224+ depends on !GRKERNSEC_KMEM
38225 default y
38226
38227 source "drivers/s390/char/Kconfig"
38228diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38229index a48e05b..6bac831 100644
38230--- a/drivers/char/agp/compat_ioctl.c
38231+++ b/drivers/char/agp/compat_ioctl.c
38232@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38233 return -ENOMEM;
38234 }
38235
38236- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38237+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38238 sizeof(*usegment) * ureserve.seg_count)) {
38239 kfree(usegment);
38240 kfree(ksegment);
38241diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38242index 1b19239..963967b 100644
38243--- a/drivers/char/agp/frontend.c
38244+++ b/drivers/char/agp/frontend.c
38245@@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38246
38247 agp_copy_info(agp_bridge, &kerninfo);
38248
38249+ memset(&userinfo, 0, sizeof(userinfo));
38250 userinfo.version.major = kerninfo.version.major;
38251 userinfo.version.minor = kerninfo.version.minor;
38252 userinfo.bridge_id = kerninfo.device->vendor |
38253@@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38254 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38255 return -EFAULT;
38256
38257- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38258+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38259 return -EFAULT;
38260
38261 client = agp_find_client_by_pid(reserve.pid);
38262@@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38263 if (segment == NULL)
38264 return -ENOMEM;
38265
38266- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38267+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38268 sizeof(struct agp_segment) * reserve.seg_count)) {
38269 kfree(segment);
38270 return -EFAULT;
38271diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38272index 4f94375..413694e 100644
38273--- a/drivers/char/genrtc.c
38274+++ b/drivers/char/genrtc.c
38275@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38276 switch (cmd) {
38277
38278 case RTC_PLL_GET:
38279+ memset(&pll, 0, sizeof(pll));
38280 if (get_rtc_pll(&pll))
38281 return -EINVAL;
38282 else
38283diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38284index d5d4cd8..22d561d 100644
38285--- a/drivers/char/hpet.c
38286+++ b/drivers/char/hpet.c
38287@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38288 }
38289
38290 static int
38291-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38292+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38293 struct hpet_info *info)
38294 {
38295 struct hpet_timer __iomem *timer;
38296diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38297index 86fe45c..c0ea948 100644
38298--- a/drivers/char/hw_random/intel-rng.c
38299+++ b/drivers/char/hw_random/intel-rng.c
38300@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38301
38302 if (no_fwh_detect)
38303 return -ENODEV;
38304- printk(warning);
38305+ printk("%s", warning);
38306 return -EBUSY;
38307 }
38308
38309diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38310index ec4e10f..f2a763b 100644
38311--- a/drivers/char/ipmi/ipmi_msghandler.c
38312+++ b/drivers/char/ipmi/ipmi_msghandler.c
38313@@ -420,7 +420,7 @@ struct ipmi_smi {
38314 struct proc_dir_entry *proc_dir;
38315 char proc_dir_name[10];
38316
38317- atomic_t stats[IPMI_NUM_STATS];
38318+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38319
38320 /*
38321 * run_to_completion duplicate of smb_info, smi_info
38322@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38323
38324
38325 #define ipmi_inc_stat(intf, stat) \
38326- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38327+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38328 #define ipmi_get_stat(intf, stat) \
38329- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38330+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38331
38332 static int is_lan_addr(struct ipmi_addr *addr)
38333 {
38334@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38335 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38336 init_waitqueue_head(&intf->waitq);
38337 for (i = 0; i < IPMI_NUM_STATS; i++)
38338- atomic_set(&intf->stats[i], 0);
38339+ atomic_set_unchecked(&intf->stats[i], 0);
38340
38341 intf->proc_dir = NULL;
38342
38343diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38344index 03f4189..e79f5e0 100644
38345--- a/drivers/char/ipmi/ipmi_si_intf.c
38346+++ b/drivers/char/ipmi/ipmi_si_intf.c
38347@@ -280,7 +280,7 @@ struct smi_info {
38348 unsigned char slave_addr;
38349
38350 /* Counters and things for the proc filesystem. */
38351- atomic_t stats[SI_NUM_STATS];
38352+ atomic_unchecked_t stats[SI_NUM_STATS];
38353
38354 struct task_struct *thread;
38355
38356@@ -289,9 +289,9 @@ struct smi_info {
38357 };
38358
38359 #define smi_inc_stat(smi, stat) \
38360- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38361+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38362 #define smi_get_stat(smi, stat) \
38363- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38364+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38365
38366 #define SI_MAX_PARMS 4
38367
38368@@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38369 atomic_set(&new_smi->req_events, 0);
38370 new_smi->run_to_completion = 0;
38371 for (i = 0; i < SI_NUM_STATS; i++)
38372- atomic_set(&new_smi->stats[i], 0);
38373+ atomic_set_unchecked(&new_smi->stats[i], 0);
38374
38375 new_smi->interrupt_disabled = 1;
38376 atomic_set(&new_smi->stop_operation, 0);
38377diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38378index 92c5937..1be4e4d 100644
38379--- a/drivers/char/mem.c
38380+++ b/drivers/char/mem.c
38381@@ -18,6 +18,7 @@
38382 #include <linux/raw.h>
38383 #include <linux/tty.h>
38384 #include <linux/capability.h>
38385+#include <linux/security.h>
38386 #include <linux/ptrace.h>
38387 #include <linux/device.h>
38388 #include <linux/highmem.h>
38389@@ -36,6 +37,10 @@
38390
38391 #define DEVPORT_MINOR 4
38392
38393+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38394+extern const struct file_operations grsec_fops;
38395+#endif
38396+
38397 static inline unsigned long size_inside_page(unsigned long start,
38398 unsigned long size)
38399 {
38400@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38401
38402 while (cursor < to) {
38403 if (!devmem_is_allowed(pfn)) {
38404+#ifdef CONFIG_GRKERNSEC_KMEM
38405+ gr_handle_mem_readwrite(from, to);
38406+#else
38407 printk(KERN_INFO
38408 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38409 current->comm, from, to);
38410+#endif
38411 return 0;
38412 }
38413 cursor += PAGE_SIZE;
38414@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38415 }
38416 return 1;
38417 }
38418+#elif defined(CONFIG_GRKERNSEC_KMEM)
38419+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38420+{
38421+ return 0;
38422+}
38423 #else
38424 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38425 {
38426@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38427
38428 while (count > 0) {
38429 unsigned long remaining;
38430+ char *temp;
38431
38432 sz = size_inside_page(p, count);
38433
38434@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38435 if (!ptr)
38436 return -EFAULT;
38437
38438- remaining = copy_to_user(buf, ptr, sz);
38439+#ifdef CONFIG_PAX_USERCOPY
38440+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38441+ if (!temp) {
38442+ unxlate_dev_mem_ptr(p, ptr);
38443+ return -ENOMEM;
38444+ }
38445+ memcpy(temp, ptr, sz);
38446+#else
38447+ temp = ptr;
38448+#endif
38449+
38450+ remaining = copy_to_user(buf, temp, sz);
38451+
38452+#ifdef CONFIG_PAX_USERCOPY
38453+ kfree(temp);
38454+#endif
38455+
38456 unxlate_dev_mem_ptr(p, ptr);
38457 if (remaining)
38458 return -EFAULT;
38459@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38460 size_t count, loff_t *ppos)
38461 {
38462 unsigned long p = *ppos;
38463- ssize_t low_count, read, sz;
38464+ ssize_t low_count, read, sz, err = 0;
38465 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38466- int err = 0;
38467
38468 read = 0;
38469 if (p < (unsigned long) high_memory) {
38470@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38471 }
38472 #endif
38473 while (low_count > 0) {
38474+ char *temp;
38475+
38476 sz = size_inside_page(p, low_count);
38477
38478 /*
38479@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38480 */
38481 kbuf = xlate_dev_kmem_ptr((char *)p);
38482
38483- if (copy_to_user(buf, kbuf, sz))
38484+#ifdef CONFIG_PAX_USERCOPY
38485+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38486+ if (!temp)
38487+ return -ENOMEM;
38488+ memcpy(temp, kbuf, sz);
38489+#else
38490+ temp = kbuf;
38491+#endif
38492+
38493+ err = copy_to_user(buf, temp, sz);
38494+
38495+#ifdef CONFIG_PAX_USERCOPY
38496+ kfree(temp);
38497+#endif
38498+
38499+ if (err)
38500 return -EFAULT;
38501 buf += sz;
38502 p += sz;
38503@@ -821,6 +868,9 @@ static const struct memdev {
38504 #ifdef CONFIG_PRINTK
38505 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38506 #endif
38507+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38508+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38509+#endif
38510 };
38511
38512 static int memory_open(struct inode *inode, struct file *filp)
38513@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38514 continue;
38515
38516 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38517- NULL, devlist[minor].name);
38518+ NULL, "%s", devlist[minor].name);
38519 }
38520
38521 return tty_init();
38522diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38523index 9df78e2..01ba9ae 100644
38524--- a/drivers/char/nvram.c
38525+++ b/drivers/char/nvram.c
38526@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38527
38528 spin_unlock_irq(&rtc_lock);
38529
38530- if (copy_to_user(buf, contents, tmp - contents))
38531+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38532 return -EFAULT;
38533
38534 *ppos = i;
38535diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38536index 8320abd..ec48108 100644
38537--- a/drivers/char/pcmcia/synclink_cs.c
38538+++ b/drivers/char/pcmcia/synclink_cs.c
38539@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38540
38541 if (debug_level >= DEBUG_LEVEL_INFO)
38542 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38543- __FILE__, __LINE__, info->device_name, port->count);
38544+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38545
38546- WARN_ON(!port->count);
38547+ WARN_ON(!atomic_read(&port->count));
38548
38549 if (tty_port_close_start(port, tty, filp) == 0)
38550 goto cleanup;
38551@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38552 cleanup:
38553 if (debug_level >= DEBUG_LEVEL_INFO)
38554 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38555- tty->driver->name, port->count);
38556+ tty->driver->name, atomic_read(&port->count));
38557 }
38558
38559 /* Wait until the transmitter is empty.
38560@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38561
38562 if (debug_level >= DEBUG_LEVEL_INFO)
38563 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38564- __FILE__, __LINE__, tty->driver->name, port->count);
38565+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38566
38567 /* If port is closing, signal caller to try again */
38568 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38569@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38570 goto cleanup;
38571 }
38572 spin_lock(&port->lock);
38573- port->count++;
38574+ atomic_inc(&port->count);
38575 spin_unlock(&port->lock);
38576 spin_unlock_irqrestore(&info->netlock, flags);
38577
38578- if (port->count == 1) {
38579+ if (atomic_read(&port->count) == 1) {
38580 /* 1st open on this device, init hardware */
38581 retval = startup(info, tty);
38582 if (retval < 0)
38583@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38584 unsigned short new_crctype;
38585
38586 /* return error if TTY interface open */
38587- if (info->port.count)
38588+ if (atomic_read(&info->port.count))
38589 return -EBUSY;
38590
38591 switch (encoding)
38592@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38593
38594 /* arbitrate between network and tty opens */
38595 spin_lock_irqsave(&info->netlock, flags);
38596- if (info->port.count != 0 || info->netcount != 0) {
38597+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38598 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38599 spin_unlock_irqrestore(&info->netlock, flags);
38600 return -EBUSY;
38601@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38602 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38603
38604 /* return error if TTY interface open */
38605- if (info->port.count)
38606+ if (atomic_read(&info->port.count))
38607 return -EBUSY;
38608
38609 if (cmd != SIOCWANDEV)
38610diff --git a/drivers/char/random.c b/drivers/char/random.c
38611index 429b75b..a7f4145 100644
38612--- a/drivers/char/random.c
38613+++ b/drivers/char/random.c
38614@@ -270,10 +270,17 @@
38615 /*
38616 * Configuration information
38617 */
38618+#ifdef CONFIG_GRKERNSEC_RANDNET
38619+#define INPUT_POOL_SHIFT 14
38620+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38621+#define OUTPUT_POOL_SHIFT 12
38622+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38623+#else
38624 #define INPUT_POOL_SHIFT 12
38625 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38626 #define OUTPUT_POOL_SHIFT 10
38627 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38628+#endif
38629 #define SEC_XFER_SIZE 512
38630 #define EXTRACT_SIZE 10
38631
38632@@ -284,9 +291,6 @@
38633 /*
38634 * To allow fractional bits to be tracked, the entropy_count field is
38635 * denominated in units of 1/8th bits.
38636- *
38637- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38638- * credit_entropy_bits() needs to be 64 bits wide.
38639 */
38640 #define ENTROPY_SHIFT 3
38641 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38642@@ -361,12 +365,19 @@ static struct poolinfo {
38643 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38644 int tap1, tap2, tap3, tap4, tap5;
38645 } poolinfo_table[] = {
38646+#ifdef CONFIG_GRKERNSEC_RANDNET
38647+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38648+ { S(512), 411, 308, 208, 104, 1 },
38649+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38650+ { S(128), 104, 76, 51, 25, 1 },
38651+#else
38652 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38653 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38654 { S(128), 104, 76, 51, 25, 1 },
38655 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38656 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38657 { S(32), 26, 19, 14, 7, 1 },
38658+#endif
38659 #if 0
38660 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38661 { S(2048), 1638, 1231, 819, 411, 1 },
38662@@ -433,9 +444,9 @@ struct entropy_store {
38663 };
38664
38665 static void push_to_pool(struct work_struct *work);
38666-static __u32 input_pool_data[INPUT_POOL_WORDS];
38667-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38668-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38669+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38670+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38671+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38672
38673 static struct entropy_store input_pool = {
38674 .poolinfo = &poolinfo_table[0],
38675@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38676 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38677 }
38678
38679- ACCESS_ONCE(r->input_rotate) = input_rotate;
38680- ACCESS_ONCE(r->add_ptr) = i;
38681+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38682+ ACCESS_ONCE_RW(r->add_ptr) = i;
38683 smp_wmb();
38684
38685 if (out)
38686@@ -632,7 +643,7 @@ retry:
38687 /* The +2 corresponds to the /4 in the denominator */
38688
38689 do {
38690- unsigned int anfrac = min(pnfrac, pool_size/2);
38691+ u64 anfrac = min(pnfrac, pool_size/2);
38692 unsigned int add =
38693 ((pool_size - entropy_count)*anfrac*3) >> s;
38694
38695@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38696
38697 extract_buf(r, tmp);
38698 i = min_t(int, nbytes, EXTRACT_SIZE);
38699- if (copy_to_user(buf, tmp, i)) {
38700+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38701 ret = -EFAULT;
38702 break;
38703 }
38704@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38705 #include <linux/sysctl.h>
38706
38707 static int min_read_thresh = 8, min_write_thresh;
38708-static int max_read_thresh = INPUT_POOL_WORDS * 32;
38709+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38710 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38711 static char sysctl_bootid[16];
38712
38713@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38714 static int proc_do_uuid(struct ctl_table *table, int write,
38715 void __user *buffer, size_t *lenp, loff_t *ppos)
38716 {
38717- struct ctl_table fake_table;
38718+ ctl_table_no_const fake_table;
38719 unsigned char buf[64], tmp_uuid[16], *uuid;
38720
38721 uuid = table->data;
38722@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38723 static int proc_do_entropy(ctl_table *table, int write,
38724 void __user *buffer, size_t *lenp, loff_t *ppos)
38725 {
38726- ctl_table fake_table;
38727+ ctl_table_no_const fake_table;
38728 int entropy_count;
38729
38730 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38731diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38732index 7cc1fe22..b602d6b 100644
38733--- a/drivers/char/sonypi.c
38734+++ b/drivers/char/sonypi.c
38735@@ -54,6 +54,7 @@
38736
38737 #include <asm/uaccess.h>
38738 #include <asm/io.h>
38739+#include <asm/local.h>
38740
38741 #include <linux/sonypi.h>
38742
38743@@ -490,7 +491,7 @@ static struct sonypi_device {
38744 spinlock_t fifo_lock;
38745 wait_queue_head_t fifo_proc_list;
38746 struct fasync_struct *fifo_async;
38747- int open_count;
38748+ local_t open_count;
38749 int model;
38750 struct input_dev *input_jog_dev;
38751 struct input_dev *input_key_dev;
38752@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38753 static int sonypi_misc_release(struct inode *inode, struct file *file)
38754 {
38755 mutex_lock(&sonypi_device.lock);
38756- sonypi_device.open_count--;
38757+ local_dec(&sonypi_device.open_count);
38758 mutex_unlock(&sonypi_device.lock);
38759 return 0;
38760 }
38761@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38762 {
38763 mutex_lock(&sonypi_device.lock);
38764 /* Flush input queue on first open */
38765- if (!sonypi_device.open_count)
38766+ if (!local_read(&sonypi_device.open_count))
38767 kfifo_reset(&sonypi_device.fifo);
38768- sonypi_device.open_count++;
38769+ local_inc(&sonypi_device.open_count);
38770 mutex_unlock(&sonypi_device.lock);
38771
38772 return 0;
38773diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38774index b9a57fa..5bb9e38 100644
38775--- a/drivers/char/tpm/tpm_acpi.c
38776+++ b/drivers/char/tpm/tpm_acpi.c
38777@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38778 virt = acpi_os_map_memory(start, len);
38779 if (!virt) {
38780 kfree(log->bios_event_log);
38781+ log->bios_event_log = NULL;
38782 printk("%s: ERROR - Unable to map memory\n", __func__);
38783 return -EIO;
38784 }
38785
38786- memcpy_fromio(log->bios_event_log, virt, len);
38787+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38788
38789 acpi_os_unmap_memory(virt, len);
38790 return 0;
38791diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38792index 59f7cb2..bac8b6d 100644
38793--- a/drivers/char/tpm/tpm_eventlog.c
38794+++ b/drivers/char/tpm/tpm_eventlog.c
38795@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38796 event = addr;
38797
38798 if ((event->event_type == 0 && event->event_size == 0) ||
38799- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38800+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38801 return NULL;
38802
38803 return addr;
38804@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38805 return NULL;
38806
38807 if ((event->event_type == 0 && event->event_size == 0) ||
38808- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38809+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38810 return NULL;
38811
38812 (*pos)++;
38813@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38814 int i;
38815
38816 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38817- seq_putc(m, data[i]);
38818+ if (!seq_putc(m, data[i]))
38819+ return -EFAULT;
38820
38821 return 0;
38822 }
38823diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38824index 6928d09..ff6abe8 100644
38825--- a/drivers/char/virtio_console.c
38826+++ b/drivers/char/virtio_console.c
38827@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38828 if (to_user) {
38829 ssize_t ret;
38830
38831- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38832+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38833 if (ret)
38834 return -EFAULT;
38835 } else {
38836@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38837 if (!port_has_data(port) && !port->host_connected)
38838 return 0;
38839
38840- return fill_readbuf(port, ubuf, count, true);
38841+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38842 }
38843
38844 static int wait_port_writable(struct port *port, bool nonblock)
38845diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38846index 57a078e..c17cde8 100644
38847--- a/drivers/clk/clk-composite.c
38848+++ b/drivers/clk/clk-composite.c
38849@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38850 struct clk *clk;
38851 struct clk_init_data init;
38852 struct clk_composite *composite;
38853- struct clk_ops *clk_composite_ops;
38854+ clk_ops_no_const *clk_composite_ops;
38855
38856 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38857 if (!composite) {
38858diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38859index 5983a26..65d5f46 100644
38860--- a/drivers/clk/socfpga/clk.c
38861+++ b/drivers/clk/socfpga/clk.c
38862@@ -22,6 +22,7 @@
38863 #include <linux/clk-provider.h>
38864 #include <linux/io.h>
38865 #include <linux/of.h>
38866+#include <asm/pgtable.h>
38867
38868 /* Clock Manager offsets */
38869 #define CLKMGR_CTRL 0x0
38870@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38871 streq(clk_name, "periph_pll") ||
38872 streq(clk_name, "sdram_pll")) {
38873 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38874- clk_pll_ops.enable = clk_gate_ops.enable;
38875- clk_pll_ops.disable = clk_gate_ops.disable;
38876+ pax_open_kernel();
38877+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38878+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38879+ pax_close_kernel();
38880 }
38881
38882 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38883@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38884 return parent_rate / div;
38885 }
38886
38887-static struct clk_ops gateclk_ops = {
38888+static clk_ops_no_const gateclk_ops __read_only = {
38889 .recalc_rate = socfpga_clk_recalc_rate,
38890 .get_parent = socfpga_clk_get_parent,
38891 .set_parent = socfpga_clk_set_parent,
38892diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38893index 18448a7..d5fad43 100644
38894--- a/drivers/cpufreq/acpi-cpufreq.c
38895+++ b/drivers/cpufreq/acpi-cpufreq.c
38896@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38897 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38898 per_cpu(acfreq_data, cpu) = data;
38899
38900- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38901- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38902+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38903+ pax_open_kernel();
38904+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38905+ pax_close_kernel();
38906+ }
38907
38908 result = acpi_processor_register_performance(data->acpi_data, cpu);
38909 if (result)
38910@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38911 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38912 break;
38913 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38914- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38915+ pax_open_kernel();
38916+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38917+ pax_close_kernel();
38918 break;
38919 default:
38920 break;
38921@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
38922 if (!msrs)
38923 return;
38924
38925- acpi_cpufreq_driver.boost_supported = true;
38926- acpi_cpufreq_driver.boost_enabled = boost_state(0);
38927+ pax_open_kernel();
38928+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
38929+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
38930+ pax_close_kernel();
38931 get_online_cpus();
38932
38933 /* Force all MSRs to the same value */
38934diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38935index 199b52b..e3503bb 100644
38936--- a/drivers/cpufreq/cpufreq.c
38937+++ b/drivers/cpufreq/cpufreq.c
38938@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38939 #endif
38940
38941 mutex_lock(&cpufreq_governor_mutex);
38942- list_del(&governor->governor_list);
38943+ pax_list_del(&governor->governor_list);
38944 mutex_unlock(&cpufreq_governor_mutex);
38945 return;
38946 }
38947@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38948 return NOTIFY_OK;
38949 }
38950
38951-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38952+static struct notifier_block cpufreq_cpu_notifier = {
38953 .notifier_call = cpufreq_cpu_callback,
38954 };
38955
38956@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
38957 return 0;
38958
38959 write_lock_irqsave(&cpufreq_driver_lock, flags);
38960- cpufreq_driver->boost_enabled = state;
38961+ pax_open_kernel();
38962+ *(bool *)&cpufreq_driver->boost_enabled = state;
38963+ pax_close_kernel();
38964 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38965
38966 ret = cpufreq_driver->set_boost(state);
38967 if (ret) {
38968 write_lock_irqsave(&cpufreq_driver_lock, flags);
38969- cpufreq_driver->boost_enabled = !state;
38970+ pax_open_kernel();
38971+ *(bool *)&cpufreq_driver->boost_enabled = !state;
38972+ pax_close_kernel();
38973 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38974
38975 pr_err("%s: Cannot %s BOOST\n", __func__,
38976@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38977
38978 pr_debug("trying to register driver %s\n", driver_data->name);
38979
38980- if (driver_data->setpolicy)
38981- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38982+ if (driver_data->setpolicy) {
38983+ pax_open_kernel();
38984+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38985+ pax_close_kernel();
38986+ }
38987
38988 write_lock_irqsave(&cpufreq_driver_lock, flags);
38989 if (cpufreq_driver) {
38990@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38991 * Check if driver provides function to enable boost -
38992 * if not, use cpufreq_boost_set_sw as default
38993 */
38994- if (!cpufreq_driver->set_boost)
38995- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38996+ if (!cpufreq_driver->set_boost) {
38997+ pax_open_kernel();
38998+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38999+ pax_close_kernel();
39000+ }
39001
39002 ret = cpufreq_sysfs_create_file(&boost.attr);
39003 if (ret) {
39004diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39005index ba43991..23858ffb 100644
39006--- a/drivers/cpufreq/cpufreq_governor.c
39007+++ b/drivers/cpufreq/cpufreq_governor.c
39008@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39009 struct dbs_data *dbs_data;
39010 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39011 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39012- struct od_ops *od_ops = NULL;
39013+ const struct od_ops *od_ops = NULL;
39014 struct od_dbs_tuners *od_tuners = NULL;
39015 struct cs_dbs_tuners *cs_tuners = NULL;
39016 struct cpu_dbs_common_info *cpu_cdbs;
39017@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39018
39019 if ((cdata->governor == GOV_CONSERVATIVE) &&
39020 (!policy->governor->initialized)) {
39021- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39022+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39023
39024 cpufreq_register_notifier(cs_ops->notifier_block,
39025 CPUFREQ_TRANSITION_NOTIFIER);
39026@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39027
39028 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39029 (policy->governor->initialized == 1)) {
39030- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39031+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39032
39033 cpufreq_unregister_notifier(cs_ops->notifier_block,
39034 CPUFREQ_TRANSITION_NOTIFIER);
39035diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39036index bfb9ae1..e1d3a7e 100644
39037--- a/drivers/cpufreq/cpufreq_governor.h
39038+++ b/drivers/cpufreq/cpufreq_governor.h
39039@@ -205,7 +205,7 @@ struct common_dbs_data {
39040 void (*exit)(struct dbs_data *dbs_data);
39041
39042 /* Governor specific ops, see below */
39043- void *gov_ops;
39044+ const void *gov_ops;
39045 };
39046
39047 /* Governor Per policy data */
39048@@ -225,7 +225,7 @@ struct od_ops {
39049 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39050 unsigned int freq_next, unsigned int relation);
39051 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39052-};
39053+} __no_const;
39054
39055 struct cs_ops {
39056 struct notifier_block *notifier_block;
39057diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39058index 18d4091..434be15 100644
39059--- a/drivers/cpufreq/cpufreq_ondemand.c
39060+++ b/drivers/cpufreq/cpufreq_ondemand.c
39061@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39062
39063 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39064
39065-static struct od_ops od_ops = {
39066+static struct od_ops od_ops __read_only = {
39067 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39068 .powersave_bias_target = generic_powersave_bias_target,
39069 .freq_increase = dbs_freq_increase,
39070@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39071 (struct cpufreq_policy *, unsigned int, unsigned int),
39072 unsigned int powersave_bias)
39073 {
39074- od_ops.powersave_bias_target = f;
39075+ pax_open_kernel();
39076+ *(void **)&od_ops.powersave_bias_target = f;
39077+ pax_close_kernel();
39078 od_set_powersave_bias(powersave_bias);
39079 }
39080 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39081
39082 void od_unregister_powersave_bias_handler(void)
39083 {
39084- od_ops.powersave_bias_target = generic_powersave_bias_target;
39085+ pax_open_kernel();
39086+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39087+ pax_close_kernel();
39088 od_set_powersave_bias(0);
39089 }
39090 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39091diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39092index 2cd36b9..8f07fae 100644
39093--- a/drivers/cpufreq/intel_pstate.c
39094+++ b/drivers/cpufreq/intel_pstate.c
39095@@ -124,10 +124,10 @@ struct pstate_funcs {
39096 struct cpu_defaults {
39097 struct pstate_adjust_policy pid_policy;
39098 struct pstate_funcs funcs;
39099-};
39100+} __do_const;
39101
39102 static struct pstate_adjust_policy pid_params;
39103-static struct pstate_funcs pstate_funcs;
39104+static struct pstate_funcs *pstate_funcs;
39105
39106 struct perf_limits {
39107 int no_turbo;
39108@@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39109
39110 cpu->pstate.current_pstate = pstate;
39111
39112- pstate_funcs.set(cpu, pstate);
39113+ pstate_funcs->set(cpu, pstate);
39114 }
39115
39116 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39117@@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39118 {
39119 sprintf(cpu->name, "Intel 2nd generation core");
39120
39121- cpu->pstate.min_pstate = pstate_funcs.get_min();
39122- cpu->pstate.max_pstate = pstate_funcs.get_max();
39123- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39124+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39125+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39126+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39127
39128- if (pstate_funcs.get_vid)
39129- pstate_funcs.get_vid(cpu);
39130+ if (pstate_funcs->get_vid)
39131+ pstate_funcs->get_vid(cpu);
39132
39133 /*
39134 * goto max pstate so we don't slow up boot if we are built-in if we are
39135@@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39136 rdmsrl(MSR_IA32_APERF, aperf);
39137 rdmsrl(MSR_IA32_MPERF, mperf);
39138
39139- if (!pstate_funcs.get_max() ||
39140- !pstate_funcs.get_min() ||
39141- !pstate_funcs.get_turbo())
39142+ if (!pstate_funcs->get_max() ||
39143+ !pstate_funcs->get_min() ||
39144+ !pstate_funcs->get_turbo())
39145 return -ENODEV;
39146
39147 rdmsrl(MSR_IA32_APERF, tmp);
39148@@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39149 return 0;
39150 }
39151
39152-static void copy_pid_params(struct pstate_adjust_policy *policy)
39153+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39154 {
39155 pid_params.sample_rate_ms = policy->sample_rate_ms;
39156 pid_params.p_gain_pct = policy->p_gain_pct;
39157@@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39158
39159 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39160 {
39161- pstate_funcs.get_max = funcs->get_max;
39162- pstate_funcs.get_min = funcs->get_min;
39163- pstate_funcs.get_turbo = funcs->get_turbo;
39164- pstate_funcs.set = funcs->set;
39165- pstate_funcs.get_vid = funcs->get_vid;
39166+ pstate_funcs = funcs;
39167 }
39168
39169 #if IS_ENABLED(CONFIG_ACPI)
39170diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39171index 3d1cba9..0ab21d2 100644
39172--- a/drivers/cpufreq/p4-clockmod.c
39173+++ b/drivers/cpufreq/p4-clockmod.c
39174@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39175 case 0x0F: /* Core Duo */
39176 case 0x16: /* Celeron Core */
39177 case 0x1C: /* Atom */
39178- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39179+ pax_open_kernel();
39180+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39181+ pax_close_kernel();
39182 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39183 case 0x0D: /* Pentium M (Dothan) */
39184- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39185+ pax_open_kernel();
39186+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39187+ pax_close_kernel();
39188 /* fall through */
39189 case 0x09: /* Pentium M (Banias) */
39190 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39191@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39192
39193 /* on P-4s, the TSC runs with constant frequency independent whether
39194 * throttling is active or not. */
39195- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39196+ pax_open_kernel();
39197+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39198+ pax_close_kernel();
39199
39200 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39201 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39202diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39203index 724ffbd..ad83692 100644
39204--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39205+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39206@@ -18,14 +18,12 @@
39207 #include <asm/head.h>
39208 #include <asm/timer.h>
39209
39210-static struct cpufreq_driver *cpufreq_us3_driver;
39211-
39212 struct us3_freq_percpu_info {
39213 struct cpufreq_frequency_table table[4];
39214 };
39215
39216 /* Indexed by cpu number. */
39217-static struct us3_freq_percpu_info *us3_freq_table;
39218+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39219
39220 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39221 * in the Safari config register.
39222@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39223
39224 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39225 {
39226- if (cpufreq_us3_driver) {
39227- cpufreq_frequency_table_put_attr(policy->cpu);
39228- us3_freq_target(policy, 0);
39229- }
39230+ cpufreq_frequency_table_put_attr(policy->cpu);
39231+ us3_freq_target(policy, 0);
39232
39233 return 0;
39234 }
39235
39236+static int __init us3_freq_init(void);
39237+static void __exit us3_freq_exit(void);
39238+
39239+static struct cpufreq_driver cpufreq_us3_driver = {
39240+ .init = us3_freq_cpu_init,
39241+ .verify = cpufreq_generic_frequency_table_verify,
39242+ .target_index = us3_freq_target,
39243+ .get = us3_freq_get,
39244+ .exit = us3_freq_cpu_exit,
39245+ .owner = THIS_MODULE,
39246+ .name = "UltraSPARC-III",
39247+
39248+};
39249+
39250 static int __init us3_freq_init(void)
39251 {
39252 unsigned long manuf, impl, ver;
39253@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39254 (impl == CHEETAH_IMPL ||
39255 impl == CHEETAH_PLUS_IMPL ||
39256 impl == JAGUAR_IMPL ||
39257- impl == PANTHER_IMPL)) {
39258- struct cpufreq_driver *driver;
39259-
39260- ret = -ENOMEM;
39261- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39262- if (!driver)
39263- goto err_out;
39264-
39265- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39266- GFP_KERNEL);
39267- if (!us3_freq_table)
39268- goto err_out;
39269-
39270- driver->init = us3_freq_cpu_init;
39271- driver->verify = cpufreq_generic_frequency_table_verify;
39272- driver->target_index = us3_freq_target;
39273- driver->get = us3_freq_get;
39274- driver->exit = us3_freq_cpu_exit;
39275- strcpy(driver->name, "UltraSPARC-III");
39276-
39277- cpufreq_us3_driver = driver;
39278- ret = cpufreq_register_driver(driver);
39279- if (ret)
39280- goto err_out;
39281-
39282- return 0;
39283-
39284-err_out:
39285- if (driver) {
39286- kfree(driver);
39287- cpufreq_us3_driver = NULL;
39288- }
39289- kfree(us3_freq_table);
39290- us3_freq_table = NULL;
39291- return ret;
39292- }
39293+ impl == PANTHER_IMPL))
39294+ return cpufreq_register_driver(&cpufreq_us3_driver);
39295
39296 return -ENODEV;
39297 }
39298
39299 static void __exit us3_freq_exit(void)
39300 {
39301- if (cpufreq_us3_driver) {
39302- cpufreq_unregister_driver(cpufreq_us3_driver);
39303- kfree(cpufreq_us3_driver);
39304- cpufreq_us3_driver = NULL;
39305- kfree(us3_freq_table);
39306- us3_freq_table = NULL;
39307- }
39308+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39309 }
39310
39311 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39312diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39313index 4e1daca..e707b61 100644
39314--- a/drivers/cpufreq/speedstep-centrino.c
39315+++ b/drivers/cpufreq/speedstep-centrino.c
39316@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39317 !cpu_has(cpu, X86_FEATURE_EST))
39318 return -ENODEV;
39319
39320- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39321- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39322+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39323+ pax_open_kernel();
39324+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39325+ pax_close_kernel();
39326+ }
39327
39328 if (policy->cpu != 0)
39329 return -ENODEV;
39330diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39331index 06dbe7c..c2c8671 100644
39332--- a/drivers/cpuidle/driver.c
39333+++ b/drivers/cpuidle/driver.c
39334@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39335
39336 static void poll_idle_init(struct cpuidle_driver *drv)
39337 {
39338- struct cpuidle_state *state = &drv->states[0];
39339+ cpuidle_state_no_const *state = &drv->states[0];
39340
39341 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39342 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39343diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39344index ca89412..a7b9c49 100644
39345--- a/drivers/cpuidle/governor.c
39346+++ b/drivers/cpuidle/governor.c
39347@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39348 mutex_lock(&cpuidle_lock);
39349 if (__cpuidle_find_governor(gov->name) == NULL) {
39350 ret = 0;
39351- list_add_tail(&gov->governor_list, &cpuidle_governors);
39352+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39353 if (!cpuidle_curr_governor ||
39354 cpuidle_curr_governor->rating < gov->rating)
39355 cpuidle_switch_governor(gov);
39356diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39357index e918b6d..f87ea80 100644
39358--- a/drivers/cpuidle/sysfs.c
39359+++ b/drivers/cpuidle/sysfs.c
39360@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39361 NULL
39362 };
39363
39364-static struct attribute_group cpuidle_attr_group = {
39365+static attribute_group_no_const cpuidle_attr_group = {
39366 .attrs = cpuidle_default_attrs,
39367 .name = "cpuidle",
39368 };
39369diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39370index 12fea3e..1e28f47 100644
39371--- a/drivers/crypto/hifn_795x.c
39372+++ b/drivers/crypto/hifn_795x.c
39373@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39374 MODULE_PARM_DESC(hifn_pll_ref,
39375 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39376
39377-static atomic_t hifn_dev_number;
39378+static atomic_unchecked_t hifn_dev_number;
39379
39380 #define ACRYPTO_OP_DECRYPT 0
39381 #define ACRYPTO_OP_ENCRYPT 1
39382@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39383 goto err_out_disable_pci_device;
39384
39385 snprintf(name, sizeof(name), "hifn%d",
39386- atomic_inc_return(&hifn_dev_number)-1);
39387+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39388
39389 err = pci_request_regions(pdev, name);
39390 if (err)
39391diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39392index a0b2f7e..1b6f028 100644
39393--- a/drivers/devfreq/devfreq.c
39394+++ b/drivers/devfreq/devfreq.c
39395@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39396 goto err_out;
39397 }
39398
39399- list_add(&governor->node, &devfreq_governor_list);
39400+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39401
39402 list_for_each_entry(devfreq, &devfreq_list, node) {
39403 int ret = 0;
39404@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39405 }
39406 }
39407
39408- list_del(&governor->node);
39409+ pax_list_del((struct list_head *)&governor->node);
39410 err_out:
39411 mutex_unlock(&devfreq_list_lock);
39412
39413diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39414index 2e7b394..1371a64 100644
39415--- a/drivers/dma/sh/shdma-base.c
39416+++ b/drivers/dma/sh/shdma-base.c
39417@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39418 schan->slave_id = -EINVAL;
39419 }
39420
39421- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39422- sdev->desc_size, GFP_KERNEL);
39423+ schan->desc = kcalloc(sdev->desc_size,
39424+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39425 if (!schan->desc) {
39426 ret = -ENOMEM;
39427 goto edescalloc;
39428diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39429index 0d765c0..60b7480 100644
39430--- a/drivers/dma/sh/shdmac.c
39431+++ b/drivers/dma/sh/shdmac.c
39432@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39433 return ret;
39434 }
39435
39436-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39437+static struct notifier_block sh_dmae_nmi_notifier = {
39438 .notifier_call = sh_dmae_nmi_handler,
39439
39440 /* Run before NMI debug handler and KGDB */
39441diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39442index 592af5f..bb1d583 100644
39443--- a/drivers/edac/edac_device.c
39444+++ b/drivers/edac/edac_device.c
39445@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39446 */
39447 int edac_device_alloc_index(void)
39448 {
39449- static atomic_t device_indexes = ATOMIC_INIT(0);
39450+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39451
39452- return atomic_inc_return(&device_indexes) - 1;
39453+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39454 }
39455 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39456
39457diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39458index b335c6a..db65b44 100644
39459--- a/drivers/edac/edac_mc_sysfs.c
39460+++ b/drivers/edac/edac_mc_sysfs.c
39461@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39462 struct dev_ch_attribute {
39463 struct device_attribute attr;
39464 int channel;
39465-};
39466+} __do_const;
39467
39468 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39469 struct dev_ch_attribute dev_attr_legacy_##_name = \
39470@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39471 }
39472
39473 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39474+ pax_open_kernel();
39475 if (mci->get_sdram_scrub_rate) {
39476- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39477- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39478+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39479+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39480 }
39481 if (mci->set_sdram_scrub_rate) {
39482- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39483- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39484+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39485+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39486 }
39487+ pax_close_kernel();
39488 err = device_create_file(&mci->dev,
39489 &dev_attr_sdram_scrub_rate);
39490 if (err) {
39491diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39492index 2cf44b4d..6dd2dc7 100644
39493--- a/drivers/edac/edac_pci.c
39494+++ b/drivers/edac/edac_pci.c
39495@@ -29,7 +29,7 @@
39496
39497 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39498 static LIST_HEAD(edac_pci_list);
39499-static atomic_t pci_indexes = ATOMIC_INIT(0);
39500+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39501
39502 /*
39503 * edac_pci_alloc_ctl_info
39504@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39505 */
39506 int edac_pci_alloc_index(void)
39507 {
39508- return atomic_inc_return(&pci_indexes) - 1;
39509+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39510 }
39511 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39512
39513diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39514index e8658e4..22746d6 100644
39515--- a/drivers/edac/edac_pci_sysfs.c
39516+++ b/drivers/edac/edac_pci_sysfs.c
39517@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39518 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39519 static int edac_pci_poll_msec = 1000; /* one second workq period */
39520
39521-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39522-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39523+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39524+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39525
39526 static struct kobject *edac_pci_top_main_kobj;
39527 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39528@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39529 void *value;
39530 ssize_t(*show) (void *, char *);
39531 ssize_t(*store) (void *, const char *, size_t);
39532-};
39533+} __do_const;
39534
39535 /* Set of show/store abstract level functions for PCI Parity object */
39536 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39537@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39538 edac_printk(KERN_CRIT, EDAC_PCI,
39539 "Signaled System Error on %s\n",
39540 pci_name(dev));
39541- atomic_inc(&pci_nonparity_count);
39542+ atomic_inc_unchecked(&pci_nonparity_count);
39543 }
39544
39545 if (status & (PCI_STATUS_PARITY)) {
39546@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39547 "Master Data Parity Error on %s\n",
39548 pci_name(dev));
39549
39550- atomic_inc(&pci_parity_count);
39551+ atomic_inc_unchecked(&pci_parity_count);
39552 }
39553
39554 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39555@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39556 "Detected Parity Error on %s\n",
39557 pci_name(dev));
39558
39559- atomic_inc(&pci_parity_count);
39560+ atomic_inc_unchecked(&pci_parity_count);
39561 }
39562 }
39563
39564@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39565 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39566 "Signaled System Error on %s\n",
39567 pci_name(dev));
39568- atomic_inc(&pci_nonparity_count);
39569+ atomic_inc_unchecked(&pci_nonparity_count);
39570 }
39571
39572 if (status & (PCI_STATUS_PARITY)) {
39573@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39574 "Master Data Parity Error on "
39575 "%s\n", pci_name(dev));
39576
39577- atomic_inc(&pci_parity_count);
39578+ atomic_inc_unchecked(&pci_parity_count);
39579 }
39580
39581 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39582@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39583 "Detected Parity Error on %s\n",
39584 pci_name(dev));
39585
39586- atomic_inc(&pci_parity_count);
39587+ atomic_inc_unchecked(&pci_parity_count);
39588 }
39589 }
39590 }
39591@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39592 if (!check_pci_errors)
39593 return;
39594
39595- before_count = atomic_read(&pci_parity_count);
39596+ before_count = atomic_read_unchecked(&pci_parity_count);
39597
39598 /* scan all PCI devices looking for a Parity Error on devices and
39599 * bridges.
39600@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39601 /* Only if operator has selected panic on PCI Error */
39602 if (edac_pci_get_panic_on_pe()) {
39603 /* If the count is different 'after' from 'before' */
39604- if (before_count != atomic_read(&pci_parity_count))
39605+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39606 panic("EDAC: PCI Parity Error");
39607 }
39608 }
39609diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39610index 51b7e3a..aa8a3e8 100644
39611--- a/drivers/edac/mce_amd.h
39612+++ b/drivers/edac/mce_amd.h
39613@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39614 bool (*mc0_mce)(u16, u8);
39615 bool (*mc1_mce)(u16, u8);
39616 bool (*mc2_mce)(u16, u8);
39617-};
39618+} __no_const;
39619
39620 void amd_report_gart_errors(bool);
39621 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39622diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39623index 57ea7f4..af06b76 100644
39624--- a/drivers/firewire/core-card.c
39625+++ b/drivers/firewire/core-card.c
39626@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39627 const struct fw_card_driver *driver,
39628 struct device *device)
39629 {
39630- static atomic_t index = ATOMIC_INIT(-1);
39631+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39632
39633- card->index = atomic_inc_return(&index);
39634+ card->index = atomic_inc_return_unchecked(&index);
39635 card->driver = driver;
39636 card->device = device;
39637 card->current_tlabel = 0;
39638@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39639
39640 void fw_core_remove_card(struct fw_card *card)
39641 {
39642- struct fw_card_driver dummy_driver = dummy_driver_template;
39643+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39644
39645 card->driver->update_phy_reg(card, 4,
39646 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39647diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39648index 2c6d5e1..a2cca6b 100644
39649--- a/drivers/firewire/core-device.c
39650+++ b/drivers/firewire/core-device.c
39651@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39652 struct config_rom_attribute {
39653 struct device_attribute attr;
39654 u32 key;
39655-};
39656+} __do_const;
39657
39658 static ssize_t show_immediate(struct device *dev,
39659 struct device_attribute *dattr, char *buf)
39660diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39661index eb6935c..3cc2bfa 100644
39662--- a/drivers/firewire/core-transaction.c
39663+++ b/drivers/firewire/core-transaction.c
39664@@ -38,6 +38,7 @@
39665 #include <linux/timer.h>
39666 #include <linux/types.h>
39667 #include <linux/workqueue.h>
39668+#include <linux/sched.h>
39669
39670 #include <asm/byteorder.h>
39671
39672diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39673index c98764a..551b520 100644
39674--- a/drivers/firewire/core.h
39675+++ b/drivers/firewire/core.h
39676@@ -111,6 +111,7 @@ struct fw_card_driver {
39677
39678 int (*stop_iso)(struct fw_iso_context *ctx);
39679 };
39680+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39681
39682 void fw_card_initialize(struct fw_card *card,
39683 const struct fw_card_driver *driver, struct device *device);
39684diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39685index 8db6632..9bbc8ca 100644
39686--- a/drivers/firewire/ohci.c
39687+++ b/drivers/firewire/ohci.c
39688@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39689 be32_to_cpu(ohci->next_header));
39690 }
39691
39692+#ifndef CONFIG_GRKERNSEC
39693 if (param_remote_dma) {
39694 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39695 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39696 }
39697+#endif
39698
39699 spin_unlock_irq(&ohci->lock);
39700
39701@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39702 unsigned long flags;
39703 int n, ret = 0;
39704
39705+#ifndef CONFIG_GRKERNSEC
39706 if (param_remote_dma)
39707 return 0;
39708+#endif
39709
39710 /*
39711 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39712diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39713index 94a58a0..f5eba42 100644
39714--- a/drivers/firmware/dmi-id.c
39715+++ b/drivers/firmware/dmi-id.c
39716@@ -16,7 +16,7 @@
39717 struct dmi_device_attribute{
39718 struct device_attribute dev_attr;
39719 int field;
39720-};
39721+} __do_const;
39722 #define to_dmi_dev_attr(_dev_attr) \
39723 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39724
39725diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39726index 17afc51..0ef90cd 100644
39727--- a/drivers/firmware/dmi_scan.c
39728+++ b/drivers/firmware/dmi_scan.c
39729@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39730 if (buf == NULL)
39731 return -1;
39732
39733- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39734+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39735
39736 dmi_unmap(buf);
39737 return 0;
39738diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39739index 1491dd4..aa910db 100644
39740--- a/drivers/firmware/efi/cper.c
39741+++ b/drivers/firmware/efi/cper.c
39742@@ -41,12 +41,12 @@
39743 */
39744 u64 cper_next_record_id(void)
39745 {
39746- static atomic64_t seq;
39747+ static atomic64_unchecked_t seq;
39748
39749- if (!atomic64_read(&seq))
39750- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39751+ if (!atomic64_read_unchecked(&seq))
39752+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39753
39754- return atomic64_inc_return(&seq);
39755+ return atomic64_inc_return_unchecked(&seq);
39756 }
39757 EXPORT_SYMBOL_GPL(cper_next_record_id);
39758
39759diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39760index 4753bac..02861a2 100644
39761--- a/drivers/firmware/efi/efi.c
39762+++ b/drivers/firmware/efi/efi.c
39763@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39764 };
39765
39766 static struct efivars generic_efivars;
39767-static struct efivar_operations generic_ops;
39768+static efivar_operations_no_const generic_ops __read_only;
39769
39770 static int generic_ops_register(void)
39771 {
39772- generic_ops.get_variable = efi.get_variable;
39773- generic_ops.set_variable = efi.set_variable;
39774- generic_ops.get_next_variable = efi.get_next_variable;
39775- generic_ops.query_variable_store = efi_query_variable_store;
39776+ pax_open_kernel();
39777+ *(void **)&generic_ops.get_variable = efi.get_variable;
39778+ *(void **)&generic_ops.set_variable = efi.set_variable;
39779+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39780+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39781+ pax_close_kernel();
39782
39783 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39784 }
39785diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39786index 3dc2482..7bd2f61 100644
39787--- a/drivers/firmware/efi/efivars.c
39788+++ b/drivers/firmware/efi/efivars.c
39789@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39790 static int
39791 create_efivars_bin_attributes(void)
39792 {
39793- struct bin_attribute *attr;
39794+ bin_attribute_no_const *attr;
39795 int error;
39796
39797 /* new_var */
39798diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39799index 2a90ba6..07f3733 100644
39800--- a/drivers/firmware/google/memconsole.c
39801+++ b/drivers/firmware/google/memconsole.c
39802@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39803 if (!found_memconsole())
39804 return -ENODEV;
39805
39806- memconsole_bin_attr.size = memconsole_length;
39807+ pax_open_kernel();
39808+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39809+ pax_close_kernel();
39810
39811 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39812
39813diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39814index 1e98a98..b444372 100644
39815--- a/drivers/gpio/gpio-em.c
39816+++ b/drivers/gpio/gpio-em.c
39817@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39818 struct em_gio_priv *p;
39819 struct resource *io[2], *irq[2];
39820 struct gpio_chip *gpio_chip;
39821- struct irq_chip *irq_chip;
39822+ irq_chip_no_const *irq_chip;
39823 const char *name = dev_name(&pdev->dev);
39824 int ret;
39825
39826diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39827index f5bf3c3..7baaa59 100644
39828--- a/drivers/gpio/gpio-ich.c
39829+++ b/drivers/gpio/gpio-ich.c
39830@@ -71,7 +71,7 @@ struct ichx_desc {
39831 /* Some chipsets have quirks, let these use their own request/get */
39832 int (*request)(struct gpio_chip *chip, unsigned offset);
39833 int (*get)(struct gpio_chip *chip, unsigned offset);
39834-};
39835+} __do_const;
39836
39837 static struct {
39838 spinlock_t lock;
39839diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39840index ca76ce7..68b384b 100644
39841--- a/drivers/gpio/gpio-rcar.c
39842+++ b/drivers/gpio/gpio-rcar.c
39843@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39844 struct gpio_rcar_priv *p;
39845 struct resource *io, *irq;
39846 struct gpio_chip *gpio_chip;
39847- struct irq_chip *irq_chip;
39848+ irq_chip_no_const *irq_chip;
39849 const char *name = dev_name(&pdev->dev);
39850 int ret;
39851
39852diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39853index 9902732..64b62dd 100644
39854--- a/drivers/gpio/gpio-vr41xx.c
39855+++ b/drivers/gpio/gpio-vr41xx.c
39856@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39857 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39858 maskl, pendl, maskh, pendh);
39859
39860- atomic_inc(&irq_err_count);
39861+ atomic_inc_unchecked(&irq_err_count);
39862
39863 return -EINVAL;
39864 }
39865diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39866index 3b7d32d..05c2f74 100644
39867--- a/drivers/gpu/drm/drm_crtc.c
39868+++ b/drivers/gpu/drm/drm_crtc.c
39869@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39870 goto done;
39871 }
39872
39873- if (copy_to_user(&enum_ptr[copied].name,
39874+ if (copy_to_user(enum_ptr[copied].name,
39875 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39876 ret = -EFAULT;
39877 goto done;
39878diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39879index 345be03..158368d 100644
39880--- a/drivers/gpu/drm/drm_drv.c
39881+++ b/drivers/gpu/drm/drm_drv.c
39882@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39883 /**
39884 * Copy and IOCTL return string to user space
39885 */
39886-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39887+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39888 {
39889 int len;
39890
39891@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39892 struct drm_file *file_priv = filp->private_data;
39893 struct drm_device *dev;
39894 const struct drm_ioctl_desc *ioctl = NULL;
39895- drm_ioctl_t *func;
39896+ drm_ioctl_no_const_t func;
39897 unsigned int nr = DRM_IOCTL_NR(cmd);
39898 int retcode = -EINVAL;
39899 char stack_kdata[128];
39900diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39901index 7f2af9a..1561914 100644
39902--- a/drivers/gpu/drm/drm_fops.c
39903+++ b/drivers/gpu/drm/drm_fops.c
39904@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39905 if (drm_device_is_unplugged(dev))
39906 return -ENODEV;
39907
39908- if (!dev->open_count++)
39909+ if (local_inc_return(&dev->open_count) == 1)
39910 need_setup = 1;
39911 mutex_lock(&dev->struct_mutex);
39912 old_imapping = inode->i_mapping;
39913@@ -127,7 +127,7 @@ err_undo:
39914 iput(container_of(dev->dev_mapping, struct inode, i_data));
39915 dev->dev_mapping = old_mapping;
39916 mutex_unlock(&dev->struct_mutex);
39917- dev->open_count--;
39918+ local_dec(&dev->open_count);
39919 return retcode;
39920 }
39921 EXPORT_SYMBOL(drm_open);
39922@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
39923
39924 mutex_lock(&drm_global_mutex);
39925
39926- DRM_DEBUG("open_count = %d\n", dev->open_count);
39927+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39928
39929 if (dev->driver->preclose)
39930 dev->driver->preclose(dev, file_priv);
39931@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
39932 * Begin inline drm_release
39933 */
39934
39935- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39936+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39937 task_pid_nr(current),
39938 (long)old_encode_dev(file_priv->minor->device),
39939- dev->open_count);
39940+ local_read(&dev->open_count));
39941
39942 /* Release any auth tokens that might point to this file_priv,
39943 (do that under the drm_global_mutex) */
39944@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
39945 * End inline drm_release
39946 */
39947
39948- if (!--dev->open_count) {
39949+ if (local_dec_and_test(&dev->open_count)) {
39950 retcode = drm_lastclose(dev);
39951 if (drm_device_is_unplugged(dev))
39952 drm_put_dev(dev);
39953diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39954index 3d2e91c..d31c4c9 100644
39955--- a/drivers/gpu/drm/drm_global.c
39956+++ b/drivers/gpu/drm/drm_global.c
39957@@ -36,7 +36,7 @@
39958 struct drm_global_item {
39959 struct mutex mutex;
39960 void *object;
39961- int refcount;
39962+ atomic_t refcount;
39963 };
39964
39965 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39966@@ -49,7 +49,7 @@ void drm_global_init(void)
39967 struct drm_global_item *item = &glob[i];
39968 mutex_init(&item->mutex);
39969 item->object = NULL;
39970- item->refcount = 0;
39971+ atomic_set(&item->refcount, 0);
39972 }
39973 }
39974
39975@@ -59,7 +59,7 @@ void drm_global_release(void)
39976 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39977 struct drm_global_item *item = &glob[i];
39978 BUG_ON(item->object != NULL);
39979- BUG_ON(item->refcount != 0);
39980+ BUG_ON(atomic_read(&item->refcount) != 0);
39981 }
39982 }
39983
39984@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39985 struct drm_global_item *item = &glob[ref->global_type];
39986
39987 mutex_lock(&item->mutex);
39988- if (item->refcount == 0) {
39989+ if (atomic_read(&item->refcount) == 0) {
39990 item->object = kzalloc(ref->size, GFP_KERNEL);
39991 if (unlikely(item->object == NULL)) {
39992 ret = -ENOMEM;
39993@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39994 goto out_err;
39995
39996 }
39997- ++item->refcount;
39998+ atomic_inc(&item->refcount);
39999 ref->object = item->object;
40000 mutex_unlock(&item->mutex);
40001 return 0;
40002@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40003 struct drm_global_item *item = &glob[ref->global_type];
40004
40005 mutex_lock(&item->mutex);
40006- BUG_ON(item->refcount == 0);
40007+ BUG_ON(atomic_read(&item->refcount) == 0);
40008 BUG_ON(ref->object != item->object);
40009- if (--item->refcount == 0) {
40010+ if (atomic_dec_and_test(&item->refcount)) {
40011 ref->release(ref);
40012 item->object = NULL;
40013 }
40014diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40015index 7473035..a48b9c5 100644
40016--- a/drivers/gpu/drm/drm_info.c
40017+++ b/drivers/gpu/drm/drm_info.c
40018@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40019 struct drm_local_map *map;
40020 struct drm_map_list *r_list;
40021
40022- /* Hardcoded from _DRM_FRAME_BUFFER,
40023- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40024- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40025- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40026+ static const char * const types[] = {
40027+ [_DRM_FRAME_BUFFER] = "FB",
40028+ [_DRM_REGISTERS] = "REG",
40029+ [_DRM_SHM] = "SHM",
40030+ [_DRM_AGP] = "AGP",
40031+ [_DRM_SCATTER_GATHER] = "SG",
40032+ [_DRM_CONSISTENT] = "PCI"};
40033 const char *type;
40034 int i;
40035
40036@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40037 map = r_list->map;
40038 if (!map)
40039 continue;
40040- if (map->type < 0 || map->type > 5)
40041+ if (map->type >= ARRAY_SIZE(types))
40042 type = "??";
40043 else
40044 type = types[map->type];
40045@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40046 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40047 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40048 vma->vm_flags & VM_IO ? 'i' : '-',
40049+#ifdef CONFIG_GRKERNSEC_HIDESYM
40050+ 0);
40051+#else
40052 vma->vm_pgoff);
40053+#endif
40054
40055 #if defined(__i386__)
40056 pgprot = pgprot_val(vma->vm_page_prot);
40057diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40058index 2f4c4343..dd12cd2 100644
40059--- a/drivers/gpu/drm/drm_ioc32.c
40060+++ b/drivers/gpu/drm/drm_ioc32.c
40061@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40062 request = compat_alloc_user_space(nbytes);
40063 if (!access_ok(VERIFY_WRITE, request, nbytes))
40064 return -EFAULT;
40065- list = (struct drm_buf_desc *) (request + 1);
40066+ list = (struct drm_buf_desc __user *) (request + 1);
40067
40068 if (__put_user(count, &request->count)
40069 || __put_user(list, &request->list))
40070@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40071 request = compat_alloc_user_space(nbytes);
40072 if (!access_ok(VERIFY_WRITE, request, nbytes))
40073 return -EFAULT;
40074- list = (struct drm_buf_pub *) (request + 1);
40075+ list = (struct drm_buf_pub __user *) (request + 1);
40076
40077 if (__put_user(count, &request->count)
40078 || __put_user(list, &request->list))
40079@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40080 return 0;
40081 }
40082
40083-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40084+drm_ioctl_compat_t drm_compat_ioctls[] = {
40085 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40086 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40087 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40088@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40089 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40090 {
40091 unsigned int nr = DRM_IOCTL_NR(cmd);
40092- drm_ioctl_compat_t *fn;
40093 int ret;
40094
40095 /* Assume that ioctls without an explicit compat routine will just
40096@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40097 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40098 return drm_ioctl(filp, cmd, arg);
40099
40100- fn = drm_compat_ioctls[nr];
40101-
40102- if (fn != NULL)
40103- ret = (*fn) (filp, cmd, arg);
40104+ if (drm_compat_ioctls[nr] != NULL)
40105+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40106 else
40107 ret = drm_ioctl(filp, cmd, arg);
40108
40109diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40110index 98a33c580..8fd1c2b 100644
40111--- a/drivers/gpu/drm/drm_stub.c
40112+++ b/drivers/gpu/drm/drm_stub.c
40113@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40114
40115 drm_device_set_unplugged(dev);
40116
40117- if (dev->open_count == 0) {
40118+ if (local_read(&dev->open_count) == 0) {
40119 drm_put_dev(dev);
40120 }
40121 mutex_unlock(&drm_global_mutex);
40122diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40123index c22c309..ae758c3 100644
40124--- a/drivers/gpu/drm/drm_sysfs.c
40125+++ b/drivers/gpu/drm/drm_sysfs.c
40126@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40127 */
40128 int drm_sysfs_device_add(struct drm_minor *minor)
40129 {
40130- char *minor_str;
40131+ const char *minor_str;
40132 int r;
40133
40134 if (minor->type == DRM_MINOR_CONTROL)
40135diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40136index d4d16ed..8fb0b51 100644
40137--- a/drivers/gpu/drm/i810/i810_drv.h
40138+++ b/drivers/gpu/drm/i810/i810_drv.h
40139@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40140 int page_flipping;
40141
40142 wait_queue_head_t irq_queue;
40143- atomic_t irq_received;
40144- atomic_t irq_emitted;
40145+ atomic_unchecked_t irq_received;
40146+ atomic_unchecked_t irq_emitted;
40147
40148 int front_offset;
40149 } drm_i810_private_t;
40150diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40151index b2b46c5..feb9fe7 100644
40152--- a/drivers/gpu/drm/i915/i915_debugfs.c
40153+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40154@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40155 I915_READ(GTIMR));
40156 }
40157 seq_printf(m, "Interrupts received: %d\n",
40158- atomic_read(&dev_priv->irq_received));
40159+ atomic_read_unchecked(&dev_priv->irq_received));
40160 for_each_ring(ring, dev_priv, i) {
40161 if (INTEL_INFO(dev)->gen >= 6) {
40162 seq_printf(m,
40163diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40164index 15a74f9..4278889 100644
40165--- a/drivers/gpu/drm/i915/i915_dma.c
40166+++ b/drivers/gpu/drm/i915/i915_dma.c
40167@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40168 bool can_switch;
40169
40170 spin_lock(&dev->count_lock);
40171- can_switch = (dev->open_count == 0);
40172+ can_switch = (local_read(&dev->open_count) == 0);
40173 spin_unlock(&dev->count_lock);
40174 return can_switch;
40175 }
40176diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40177index df77e20..d3fda9f 100644
40178--- a/drivers/gpu/drm/i915/i915_drv.h
40179+++ b/drivers/gpu/drm/i915/i915_drv.h
40180@@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40181 drm_dma_handle_t *status_page_dmah;
40182 struct resource mch_res;
40183
40184- atomic_t irq_received;
40185+ atomic_unchecked_t irq_received;
40186
40187 /* protects the irq masks */
40188 spinlock_t irq_lock;
40189diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40190index d269ecf..6d857bc 100644
40191--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40192+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40193@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40194
40195 static int
40196 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40197- int count)
40198+ unsigned int count)
40199 {
40200- int i;
40201+ unsigned int i;
40202 unsigned relocs_total = 0;
40203 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40204
40205diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40206index 3c59584..500f2e9 100644
40207--- a/drivers/gpu/drm/i915/i915_ioc32.c
40208+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40209@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40210 (unsigned long)request);
40211 }
40212
40213-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40214+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40215 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40216 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40217 [DRM_I915_GETPARAM] = compat_i915_getparam,
40218@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40219 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40220 {
40221 unsigned int nr = DRM_IOCTL_NR(cmd);
40222- drm_ioctl_compat_t *fn = NULL;
40223 int ret;
40224
40225 if (nr < DRM_COMMAND_BASE)
40226 return drm_compat_ioctl(filp, cmd, arg);
40227
40228- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40229- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40230-
40231- if (fn != NULL)
40232+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40233+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40234 ret = (*fn) (filp, cmd, arg);
40235- else
40236+ } else
40237 ret = drm_ioctl(filp, cmd, arg);
40238
40239 return ret;
40240diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40241index d554169..f4426bb 100644
40242--- a/drivers/gpu/drm/i915/i915_irq.c
40243+++ b/drivers/gpu/drm/i915/i915_irq.c
40244@@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40245 int pipe;
40246 u32 pipe_stats[I915_MAX_PIPES];
40247
40248- atomic_inc(&dev_priv->irq_received);
40249+ atomic_inc_unchecked(&dev_priv->irq_received);
40250
40251 while (true) {
40252 iir = I915_READ(VLV_IIR);
40253@@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40254 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40255 irqreturn_t ret = IRQ_NONE;
40256
40257- atomic_inc(&dev_priv->irq_received);
40258+ atomic_inc_unchecked(&dev_priv->irq_received);
40259
40260 /* We get interrupts on unclaimed registers, so check for this before we
40261 * do any I915_{READ,WRITE}. */
40262@@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40263 uint32_t tmp = 0;
40264 enum pipe pipe;
40265
40266- atomic_inc(&dev_priv->irq_received);
40267+ atomic_inc_unchecked(&dev_priv->irq_received);
40268
40269 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40270 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40271@@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40272 {
40273 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40274
40275- atomic_set(&dev_priv->irq_received, 0);
40276+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40277
40278 I915_WRITE(HWSTAM, 0xeffe);
40279
40280@@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40281 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40282 int pipe;
40283
40284- atomic_set(&dev_priv->irq_received, 0);
40285+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40286
40287 /* VLV magic */
40288 I915_WRITE(VLV_IMR, 0);
40289@@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40290 struct drm_i915_private *dev_priv = dev->dev_private;
40291 int pipe;
40292
40293- atomic_set(&dev_priv->irq_received, 0);
40294+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40295
40296 I915_WRITE(GEN8_MASTER_IRQ, 0);
40297 POSTING_READ(GEN8_MASTER_IRQ);
40298@@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40299 if (!dev_priv)
40300 return;
40301
40302- atomic_set(&dev_priv->irq_received, 0);
40303+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40304
40305 I915_WRITE(GEN8_MASTER_IRQ, 0);
40306
40307@@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40308 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40309 int pipe;
40310
40311- atomic_set(&dev_priv->irq_received, 0);
40312+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40313
40314 for_each_pipe(pipe)
40315 I915_WRITE(PIPESTAT(pipe), 0);
40316@@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40317 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40318 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40319
40320- atomic_inc(&dev_priv->irq_received);
40321+ atomic_inc_unchecked(&dev_priv->irq_received);
40322
40323 iir = I915_READ16(IIR);
40324 if (iir == 0)
40325@@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40326 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40327 int pipe;
40328
40329- atomic_set(&dev_priv->irq_received, 0);
40330+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40331
40332 if (I915_HAS_HOTPLUG(dev)) {
40333 I915_WRITE(PORT_HOTPLUG_EN, 0);
40334@@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40335 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40336 int pipe, ret = IRQ_NONE;
40337
40338- atomic_inc(&dev_priv->irq_received);
40339+ atomic_inc_unchecked(&dev_priv->irq_received);
40340
40341 iir = I915_READ(IIR);
40342 do {
40343@@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40344 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40345 int pipe;
40346
40347- atomic_set(&dev_priv->irq_received, 0);
40348+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40349
40350 I915_WRITE(PORT_HOTPLUG_EN, 0);
40351 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40352@@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40353 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40354 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40355
40356- atomic_inc(&dev_priv->irq_received);
40357+ atomic_inc_unchecked(&dev_priv->irq_received);
40358
40359 iir = I915_READ(IIR);
40360
40361diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40362index 9b8a7c7..60f6003 100644
40363--- a/drivers/gpu/drm/i915/intel_display.c
40364+++ b/drivers/gpu/drm/i915/intel_display.c
40365@@ -10776,13 +10776,13 @@ struct intel_quirk {
40366 int subsystem_vendor;
40367 int subsystem_device;
40368 void (*hook)(struct drm_device *dev);
40369-};
40370+} __do_const;
40371
40372 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40373 struct intel_dmi_quirk {
40374 void (*hook)(struct drm_device *dev);
40375 const struct dmi_system_id (*dmi_id_list)[];
40376-};
40377+} __do_const;
40378
40379 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40380 {
40381@@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40382 return 1;
40383 }
40384
40385-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40386+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40387 {
40388- .dmi_id_list = &(const struct dmi_system_id[]) {
40389- {
40390- .callback = intel_dmi_reverse_brightness,
40391- .ident = "NCR Corporation",
40392- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40393- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40394- },
40395- },
40396- { } /* terminating entry */
40397+ .callback = intel_dmi_reverse_brightness,
40398+ .ident = "NCR Corporation",
40399+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40400+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40401 },
40402+ },
40403+ { } /* terminating entry */
40404+};
40405+
40406+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40407+ {
40408+ .dmi_id_list = &intel_dmi_quirks_table,
40409 .hook = quirk_invert_brightness,
40410 },
40411 };
40412diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40413index fe45321..836fdca 100644
40414--- a/drivers/gpu/drm/mga/mga_drv.h
40415+++ b/drivers/gpu/drm/mga/mga_drv.h
40416@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40417 u32 clear_cmd;
40418 u32 maccess;
40419
40420- atomic_t vbl_received; /**< Number of vblanks received. */
40421+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40422 wait_queue_head_t fence_queue;
40423- atomic_t last_fence_retired;
40424+ atomic_unchecked_t last_fence_retired;
40425 u32 next_fence_to_post;
40426
40427 unsigned int fb_cpp;
40428diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40429index 86b4bb8..ae237ad 100644
40430--- a/drivers/gpu/drm/mga/mga_ioc32.c
40431+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40432@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40433 return 0;
40434 }
40435
40436-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40437+drm_ioctl_compat_t mga_compat_ioctls[] = {
40438 [DRM_MGA_INIT] = compat_mga_init,
40439 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40440 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40441@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40442 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40443 {
40444 unsigned int nr = DRM_IOCTL_NR(cmd);
40445- drm_ioctl_compat_t *fn = NULL;
40446 int ret;
40447
40448 if (nr < DRM_COMMAND_BASE)
40449 return drm_compat_ioctl(filp, cmd, arg);
40450
40451- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40452- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40453-
40454- if (fn != NULL)
40455+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40456+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40457 ret = (*fn) (filp, cmd, arg);
40458- else
40459+ } else
40460 ret = drm_ioctl(filp, cmd, arg);
40461
40462 return ret;
40463diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40464index 1b071b8..de8601a 100644
40465--- a/drivers/gpu/drm/mga/mga_irq.c
40466+++ b/drivers/gpu/drm/mga/mga_irq.c
40467@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40468 if (crtc != 0)
40469 return 0;
40470
40471- return atomic_read(&dev_priv->vbl_received);
40472+ return atomic_read_unchecked(&dev_priv->vbl_received);
40473 }
40474
40475
40476@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40477 /* VBLANK interrupt */
40478 if (status & MGA_VLINEPEN) {
40479 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40480- atomic_inc(&dev_priv->vbl_received);
40481+ atomic_inc_unchecked(&dev_priv->vbl_received);
40482 drm_handle_vblank(dev, 0);
40483 handled = 1;
40484 }
40485@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40486 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40487 MGA_WRITE(MGA_PRIMEND, prim_end);
40488
40489- atomic_inc(&dev_priv->last_fence_retired);
40490+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40491 wake_up(&dev_priv->fence_queue);
40492 handled = 1;
40493 }
40494@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40495 * using fences.
40496 */
40497 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40498- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40499+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40500 - *sequence) <= (1 << 23)));
40501
40502 *sequence = cur_fence;
40503diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40504index 4c3feaa..26391ce 100644
40505--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40506+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40507@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40508 struct bit_table {
40509 const char id;
40510 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40511-};
40512+} __no_const;
40513
40514 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40515
40516diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40517index 23ca7a5..b6c955d 100644
40518--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40519+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40520@@ -97,7 +97,6 @@ struct nouveau_drm {
40521 struct drm_global_reference mem_global_ref;
40522 struct ttm_bo_global_ref bo_global_ref;
40523 struct ttm_bo_device bdev;
40524- atomic_t validate_sequence;
40525 int (*move)(struct nouveau_channel *,
40526 struct ttm_buffer_object *,
40527 struct ttm_mem_reg *, struct ttm_mem_reg *);
40528diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40529index c1a7e5a..38b8539 100644
40530--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40531+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40532@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40533 unsigned long arg)
40534 {
40535 unsigned int nr = DRM_IOCTL_NR(cmd);
40536- drm_ioctl_compat_t *fn = NULL;
40537+ drm_ioctl_compat_t fn = NULL;
40538 int ret;
40539
40540 if (nr < DRM_COMMAND_BASE)
40541diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40542index d45d50d..72a5dd2 100644
40543--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40544+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40545@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40546 }
40547
40548 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40549- nouveau_vram_manager_init,
40550- nouveau_vram_manager_fini,
40551- nouveau_vram_manager_new,
40552- nouveau_vram_manager_del,
40553- nouveau_vram_manager_debug
40554+ .init = nouveau_vram_manager_init,
40555+ .takedown = nouveau_vram_manager_fini,
40556+ .get_node = nouveau_vram_manager_new,
40557+ .put_node = nouveau_vram_manager_del,
40558+ .debug = nouveau_vram_manager_debug
40559 };
40560
40561 static int
40562@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40563 }
40564
40565 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40566- nouveau_gart_manager_init,
40567- nouveau_gart_manager_fini,
40568- nouveau_gart_manager_new,
40569- nouveau_gart_manager_del,
40570- nouveau_gart_manager_debug
40571+ .init = nouveau_gart_manager_init,
40572+ .takedown = nouveau_gart_manager_fini,
40573+ .get_node = nouveau_gart_manager_new,
40574+ .put_node = nouveau_gart_manager_del,
40575+ .debug = nouveau_gart_manager_debug
40576 };
40577
40578 #include <core/subdev/vm/nv04.h>
40579@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40580 }
40581
40582 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40583- nv04_gart_manager_init,
40584- nv04_gart_manager_fini,
40585- nv04_gart_manager_new,
40586- nv04_gart_manager_del,
40587- nv04_gart_manager_debug
40588+ .init = nv04_gart_manager_init,
40589+ .takedown = nv04_gart_manager_fini,
40590+ .get_node = nv04_gart_manager_new,
40591+ .put_node = nv04_gart_manager_del,
40592+ .debug = nv04_gart_manager_debug
40593 };
40594
40595 int
40596diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40597index 471347e..5adc6b9 100644
40598--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40599+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40600@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40601 bool can_switch;
40602
40603 spin_lock(&dev->count_lock);
40604- can_switch = (dev->open_count == 0);
40605+ can_switch = (local_read(&dev->open_count) == 0);
40606 spin_unlock(&dev->count_lock);
40607 return can_switch;
40608 }
40609diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40610index eb89653..613cf71 100644
40611--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40612+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40613@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40614 int ret;
40615
40616 mutex_lock(&qdev->async_io_mutex);
40617- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40618+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40619 if (qdev->last_sent_io_cmd > irq_num) {
40620 if (intr)
40621 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40622- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40623+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40624 else
40625 ret = wait_event_timeout(qdev->io_cmd_event,
40626- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40627+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40628 /* 0 is timeout, just bail the "hw" has gone away */
40629 if (ret <= 0)
40630 goto out;
40631- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40632+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40633 }
40634 outb(val, addr);
40635 qdev->last_sent_io_cmd = irq_num + 1;
40636 if (intr)
40637 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40638- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40639+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40640 else
40641 ret = wait_event_timeout(qdev->io_cmd_event,
40642- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40643+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40644 out:
40645 if (ret > 0)
40646 ret = 0;
40647diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40648index c3c2bbd..bc3c0fb 100644
40649--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40650+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40651@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40652 struct drm_info_node *node = (struct drm_info_node *) m->private;
40653 struct qxl_device *qdev = node->minor->dev->dev_private;
40654
40655- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40656- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40657- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40658- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40659+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40660+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40661+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40662+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40663 seq_printf(m, "%d\n", qdev->irq_received_error);
40664 return 0;
40665 }
40666diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40667index 36ed40b..0397633 100644
40668--- a/drivers/gpu/drm/qxl/qxl_drv.h
40669+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40670@@ -290,10 +290,10 @@ struct qxl_device {
40671 unsigned int last_sent_io_cmd;
40672
40673 /* interrupt handling */
40674- atomic_t irq_received;
40675- atomic_t irq_received_display;
40676- atomic_t irq_received_cursor;
40677- atomic_t irq_received_io_cmd;
40678+ atomic_unchecked_t irq_received;
40679+ atomic_unchecked_t irq_received_display;
40680+ atomic_unchecked_t irq_received_cursor;
40681+ atomic_unchecked_t irq_received_io_cmd;
40682 unsigned irq_received_error;
40683 wait_queue_head_t display_event;
40684 wait_queue_head_t cursor_event;
40685diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40686index 0bb86e6..d41416d 100644
40687--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40688+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40689@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40690
40691 /* TODO copy slow path code from i915 */
40692 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40693- unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)cmd->command, cmd->command_size);
40694+ unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void __force_user *)(unsigned long)cmd->command, cmd->command_size);
40695
40696 {
40697 struct qxl_drawable *draw = fb_cmd;
40698@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40699 struct drm_qxl_reloc reloc;
40700
40701 if (copy_from_user(&reloc,
40702- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40703+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40704 sizeof(reloc))) {
40705 ret = -EFAULT;
40706 goto out_free_bos;
40707@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40708
40709 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40710
40711- struct drm_qxl_command *commands =
40712- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40713+ struct drm_qxl_command __user *commands =
40714+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40715
40716- if (copy_from_user(&user_cmd, &commands[cmd_num],
40717+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40718 sizeof(user_cmd)))
40719 return -EFAULT;
40720
40721diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40722index 28f84b4..fb3e224 100644
40723--- a/drivers/gpu/drm/qxl/qxl_irq.c
40724+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40725@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40726
40727 pending = xchg(&qdev->ram_header->int_pending, 0);
40728
40729- atomic_inc(&qdev->irq_received);
40730+ atomic_inc_unchecked(&qdev->irq_received);
40731
40732 if (pending & QXL_INTERRUPT_DISPLAY) {
40733- atomic_inc(&qdev->irq_received_display);
40734+ atomic_inc_unchecked(&qdev->irq_received_display);
40735 wake_up_all(&qdev->display_event);
40736 qxl_queue_garbage_collect(qdev, false);
40737 }
40738 if (pending & QXL_INTERRUPT_CURSOR) {
40739- atomic_inc(&qdev->irq_received_cursor);
40740+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40741 wake_up_all(&qdev->cursor_event);
40742 }
40743 if (pending & QXL_INTERRUPT_IO_CMD) {
40744- atomic_inc(&qdev->irq_received_io_cmd);
40745+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40746 wake_up_all(&qdev->io_cmd_event);
40747 }
40748 if (pending & QXL_INTERRUPT_ERROR) {
40749@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40750 init_waitqueue_head(&qdev->io_cmd_event);
40751 INIT_WORK(&qdev->client_monitors_config_work,
40752 qxl_client_monitors_config_work_func);
40753- atomic_set(&qdev->irq_received, 0);
40754- atomic_set(&qdev->irq_received_display, 0);
40755- atomic_set(&qdev->irq_received_cursor, 0);
40756- atomic_set(&qdev->irq_received_io_cmd, 0);
40757+ atomic_set_unchecked(&qdev->irq_received, 0);
40758+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40759+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40760+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40761 qdev->irq_received_error = 0;
40762 ret = drm_irq_install(qdev->ddev);
40763 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40764diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40765index c7e7e65..7dddd4d 100644
40766--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40767+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40768@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40769 }
40770 }
40771
40772-static struct vm_operations_struct qxl_ttm_vm_ops;
40773+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40774 static const struct vm_operations_struct *ttm_vm_ops;
40775
40776 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40777@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40778 return r;
40779 if (unlikely(ttm_vm_ops == NULL)) {
40780 ttm_vm_ops = vma->vm_ops;
40781+ pax_open_kernel();
40782 qxl_ttm_vm_ops = *ttm_vm_ops;
40783 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40784+ pax_close_kernel();
40785 }
40786 vma->vm_ops = &qxl_ttm_vm_ops;
40787 return 0;
40788@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40789 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40790 {
40791 #if defined(CONFIG_DEBUG_FS)
40792- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40793- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40794- unsigned i;
40795+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40796+ {
40797+ .name = "qxl_mem_mm",
40798+ .show = &qxl_mm_dump_table,
40799+ },
40800+ {
40801+ .name = "qxl_surf_mm",
40802+ .show = &qxl_mm_dump_table,
40803+ }
40804+ };
40805
40806- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40807- if (i == 0)
40808- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40809- else
40810- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40811- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40812- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40813- qxl_mem_types_list[i].driver_features = 0;
40814- if (i == 0)
40815- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40816- else
40817- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40818+ pax_open_kernel();
40819+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40820+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40821+ pax_close_kernel();
40822
40823- }
40824- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40825+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40826 #else
40827 return 0;
40828 #endif
40829diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40830index 59459fe..be26b31 100644
40831--- a/drivers/gpu/drm/r128/r128_cce.c
40832+++ b/drivers/gpu/drm/r128/r128_cce.c
40833@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40834
40835 /* GH: Simple idle check.
40836 */
40837- atomic_set(&dev_priv->idle_count, 0);
40838+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40839
40840 /* We don't support anything other than bus-mastering ring mode,
40841 * but the ring can be in either AGP or PCI space for the ring
40842diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40843index 5bf3f5f..7000661 100644
40844--- a/drivers/gpu/drm/r128/r128_drv.h
40845+++ b/drivers/gpu/drm/r128/r128_drv.h
40846@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40847 int is_pci;
40848 unsigned long cce_buffers_offset;
40849
40850- atomic_t idle_count;
40851+ atomic_unchecked_t idle_count;
40852
40853 int page_flipping;
40854 int current_page;
40855 u32 crtc_offset;
40856 u32 crtc_offset_cntl;
40857
40858- atomic_t vbl_received;
40859+ atomic_unchecked_t vbl_received;
40860
40861 u32 color_fmt;
40862 unsigned int front_offset;
40863diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40864index b0d0fd3..a6fbbe4 100644
40865--- a/drivers/gpu/drm/r128/r128_ioc32.c
40866+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40867@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40868 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40869 }
40870
40871-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40872+drm_ioctl_compat_t r128_compat_ioctls[] = {
40873 [DRM_R128_INIT] = compat_r128_init,
40874 [DRM_R128_DEPTH] = compat_r128_depth,
40875 [DRM_R128_STIPPLE] = compat_r128_stipple,
40876@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40877 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40878 {
40879 unsigned int nr = DRM_IOCTL_NR(cmd);
40880- drm_ioctl_compat_t *fn = NULL;
40881 int ret;
40882
40883 if (nr < DRM_COMMAND_BASE)
40884 return drm_compat_ioctl(filp, cmd, arg);
40885
40886- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40887- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40888-
40889- if (fn != NULL)
40890+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40891+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40892 ret = (*fn) (filp, cmd, arg);
40893- else
40894+ } else
40895 ret = drm_ioctl(filp, cmd, arg);
40896
40897 return ret;
40898diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40899index c2ae496..30b5993 100644
40900--- a/drivers/gpu/drm/r128/r128_irq.c
40901+++ b/drivers/gpu/drm/r128/r128_irq.c
40902@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40903 if (crtc != 0)
40904 return 0;
40905
40906- return atomic_read(&dev_priv->vbl_received);
40907+ return atomic_read_unchecked(&dev_priv->vbl_received);
40908 }
40909
40910 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40911@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40912 /* VBLANK interrupt */
40913 if (status & R128_CRTC_VBLANK_INT) {
40914 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40915- atomic_inc(&dev_priv->vbl_received);
40916+ atomic_inc_unchecked(&dev_priv->vbl_received);
40917 drm_handle_vblank(dev, 0);
40918 return IRQ_HANDLED;
40919 }
40920diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40921index e806dac..f81d32f 100644
40922--- a/drivers/gpu/drm/r128/r128_state.c
40923+++ b/drivers/gpu/drm/r128/r128_state.c
40924@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40925
40926 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40927 {
40928- if (atomic_read(&dev_priv->idle_count) == 0)
40929+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40930 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40931 else
40932- atomic_set(&dev_priv->idle_count, 0);
40933+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40934 }
40935
40936 #endif
40937diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40938index 4a85bb6..aaea819 100644
40939--- a/drivers/gpu/drm/radeon/mkregtable.c
40940+++ b/drivers/gpu/drm/radeon/mkregtable.c
40941@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40942 regex_t mask_rex;
40943 regmatch_t match[4];
40944 char buf[1024];
40945- size_t end;
40946+ long end;
40947 int len;
40948 int done = 0;
40949 int r;
40950 unsigned o;
40951 struct offset *offset;
40952 char last_reg_s[10];
40953- int last_reg;
40954+ unsigned long last_reg;
40955
40956 if (regcomp
40957 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40958diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40959index 044bc98..50ced9b 100644
40960--- a/drivers/gpu/drm/radeon/radeon_device.c
40961+++ b/drivers/gpu/drm/radeon/radeon_device.c
40962@@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40963 bool can_switch;
40964
40965 spin_lock(&dev->count_lock);
40966- can_switch = (dev->open_count == 0);
40967+ can_switch = (local_read(&dev->open_count) == 0);
40968 spin_unlock(&dev->count_lock);
40969 return can_switch;
40970 }
40971diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40972index dafd812..1bf20c7 100644
40973--- a/drivers/gpu/drm/radeon/radeon_drv.h
40974+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40975@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40976
40977 /* SW interrupt */
40978 wait_queue_head_t swi_queue;
40979- atomic_t swi_emitted;
40980+ atomic_unchecked_t swi_emitted;
40981 int vblank_crtc;
40982 uint32_t irq_enable_reg;
40983 uint32_t r500_disp_irq_reg;
40984diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40985index bdb0f93..5ff558f 100644
40986--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40987+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40988@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40989 request = compat_alloc_user_space(sizeof(*request));
40990 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40991 || __put_user(req32.param, &request->param)
40992- || __put_user((void __user *)(unsigned long)req32.value,
40993+ || __put_user((unsigned long)req32.value,
40994 &request->value))
40995 return -EFAULT;
40996
40997@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40998 #define compat_radeon_cp_setparam NULL
40999 #endif /* X86_64 || IA64 */
41000
41001-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41002+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41003 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41004 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41005 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41006@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41007 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41008 {
41009 unsigned int nr = DRM_IOCTL_NR(cmd);
41010- drm_ioctl_compat_t *fn = NULL;
41011 int ret;
41012
41013 if (nr < DRM_COMMAND_BASE)
41014 return drm_compat_ioctl(filp, cmd, arg);
41015
41016- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41017- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41018-
41019- if (fn != NULL)
41020+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41021+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41022 ret = (*fn) (filp, cmd, arg);
41023- else
41024+ } else
41025 ret = drm_ioctl(filp, cmd, arg);
41026
41027 return ret;
41028diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41029index 244b19b..c19226d 100644
41030--- a/drivers/gpu/drm/radeon/radeon_irq.c
41031+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41032@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41033 unsigned int ret;
41034 RING_LOCALS;
41035
41036- atomic_inc(&dev_priv->swi_emitted);
41037- ret = atomic_read(&dev_priv->swi_emitted);
41038+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41039+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41040
41041 BEGIN_RING(4);
41042 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41043@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41044 drm_radeon_private_t *dev_priv =
41045 (drm_radeon_private_t *) dev->dev_private;
41046
41047- atomic_set(&dev_priv->swi_emitted, 0);
41048+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41049 init_waitqueue_head(&dev_priv->swi_queue);
41050
41051 dev->max_vblank_count = 0x001fffff;
41052diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41053index 956ab7f..fbd36d8 100644
41054--- a/drivers/gpu/drm/radeon/radeon_state.c
41055+++ b/drivers/gpu/drm/radeon/radeon_state.c
41056@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41057 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41058 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41059
41060- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41061+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41062 sarea_priv->nbox * sizeof(depth_boxes[0])))
41063 return -EFAULT;
41064
41065@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41066 {
41067 drm_radeon_private_t *dev_priv = dev->dev_private;
41068 drm_radeon_getparam_t *param = data;
41069- int value;
41070+ int value = 0;
41071
41072 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41073
41074diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41075index 040a2a1..eae4e54 100644
41076--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41077+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41078@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41079 man->size = size >> PAGE_SHIFT;
41080 }
41081
41082-static struct vm_operations_struct radeon_ttm_vm_ops;
41083+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41084 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41085
41086 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41087@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41088 }
41089 if (unlikely(ttm_vm_ops == NULL)) {
41090 ttm_vm_ops = vma->vm_ops;
41091+ pax_open_kernel();
41092 radeon_ttm_vm_ops = *ttm_vm_ops;
41093 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41094+ pax_close_kernel();
41095 }
41096 vma->vm_ops = &radeon_ttm_vm_ops;
41097 return 0;
41098diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41099index 9336006..ce78aa7 100644
41100--- a/drivers/gpu/drm/tegra/dc.c
41101+++ b/drivers/gpu/drm/tegra/dc.c
41102@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41103 }
41104
41105 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41106- dc->debugfs_files[i].data = dc;
41107+ *(void **)&dc->debugfs_files[i].data = dc;
41108
41109 err = drm_debugfs_create_files(dc->debugfs_files,
41110 ARRAY_SIZE(debugfs_files),
41111diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41112index d452faab..f8cbc6a 100644
41113--- a/drivers/gpu/drm/tegra/dsi.c
41114+++ b/drivers/gpu/drm/tegra/dsi.c
41115@@ -53,7 +53,7 @@ struct tegra_dsi {
41116 struct clk *clk_lp;
41117 struct clk *clk;
41118
41119- struct drm_info_list *debugfs_files;
41120+ drm_info_list_no_const *debugfs_files;
41121 struct drm_minor *minor;
41122 struct dentry *debugfs;
41123
41124diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41125index 6928015..c9853e7 100644
41126--- a/drivers/gpu/drm/tegra/hdmi.c
41127+++ b/drivers/gpu/drm/tegra/hdmi.c
41128@@ -59,7 +59,7 @@ struct tegra_hdmi {
41129 bool stereo;
41130 bool dvi;
41131
41132- struct drm_info_list *debugfs_files;
41133+ drm_info_list_no_const *debugfs_files;
41134 struct drm_minor *minor;
41135 struct dentry *debugfs;
41136 };
41137diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41138index c58eba33..83c2728 100644
41139--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41140+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41141@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41142 }
41143
41144 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41145- ttm_bo_man_init,
41146- ttm_bo_man_takedown,
41147- ttm_bo_man_get_node,
41148- ttm_bo_man_put_node,
41149- ttm_bo_man_debug
41150+ .init = ttm_bo_man_init,
41151+ .takedown = ttm_bo_man_takedown,
41152+ .get_node = ttm_bo_man_get_node,
41153+ .put_node = ttm_bo_man_put_node,
41154+ .debug = ttm_bo_man_debug
41155 };
41156 EXPORT_SYMBOL(ttm_bo_manager_func);
41157diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41158index dbc2def..0a9f710 100644
41159--- a/drivers/gpu/drm/ttm/ttm_memory.c
41160+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41161@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41162 zone->glob = glob;
41163 glob->zone_kernel = zone;
41164 ret = kobject_init_and_add(
41165- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41166+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41167 if (unlikely(ret != 0)) {
41168 kobject_put(&zone->kobj);
41169 return ret;
41170@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41171 zone->glob = glob;
41172 glob->zone_dma32 = zone;
41173 ret = kobject_init_and_add(
41174- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41175+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41176 if (unlikely(ret != 0)) {
41177 kobject_put(&zone->kobj);
41178 return ret;
41179diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41180index 863bef9..cba15cf 100644
41181--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41182+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41183@@ -391,9 +391,9 @@ out:
41184 static unsigned long
41185 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41186 {
41187- static atomic_t start_pool = ATOMIC_INIT(0);
41188+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41189 unsigned i;
41190- unsigned pool_offset = atomic_add_return(1, &start_pool);
41191+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41192 struct ttm_page_pool *pool;
41193 int shrink_pages = sc->nr_to_scan;
41194 unsigned long freed = 0;
41195diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41196index dbadd49..1b7457b 100644
41197--- a/drivers/gpu/drm/udl/udl_fb.c
41198+++ b/drivers/gpu/drm/udl/udl_fb.c
41199@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41200 fb_deferred_io_cleanup(info);
41201 kfree(info->fbdefio);
41202 info->fbdefio = NULL;
41203- info->fbops->fb_mmap = udl_fb_mmap;
41204 }
41205
41206 pr_warn("released /dev/fb%d user=%d count=%d\n",
41207diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41208index ad02732..144f5ed 100644
41209--- a/drivers/gpu/drm/via/via_drv.h
41210+++ b/drivers/gpu/drm/via/via_drv.h
41211@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41212 typedef uint32_t maskarray_t[5];
41213
41214 typedef struct drm_via_irq {
41215- atomic_t irq_received;
41216+ atomic_unchecked_t irq_received;
41217 uint32_t pending_mask;
41218 uint32_t enable_mask;
41219 wait_queue_head_t irq_queue;
41220@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41221 struct timeval last_vblank;
41222 int last_vblank_valid;
41223 unsigned usec_per_vblank;
41224- atomic_t vbl_received;
41225+ atomic_unchecked_t vbl_received;
41226 drm_via_state_t hc_state;
41227 char pci_buf[VIA_PCI_BUF_SIZE];
41228 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41229diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41230index 1319433..a993b0c 100644
41231--- a/drivers/gpu/drm/via/via_irq.c
41232+++ b/drivers/gpu/drm/via/via_irq.c
41233@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41234 if (crtc != 0)
41235 return 0;
41236
41237- return atomic_read(&dev_priv->vbl_received);
41238+ return atomic_read_unchecked(&dev_priv->vbl_received);
41239 }
41240
41241 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41242@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41243
41244 status = VIA_READ(VIA_REG_INTERRUPT);
41245 if (status & VIA_IRQ_VBLANK_PENDING) {
41246- atomic_inc(&dev_priv->vbl_received);
41247- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41248+ atomic_inc_unchecked(&dev_priv->vbl_received);
41249+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41250 do_gettimeofday(&cur_vblank);
41251 if (dev_priv->last_vblank_valid) {
41252 dev_priv->usec_per_vblank =
41253@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41254 dev_priv->last_vblank = cur_vblank;
41255 dev_priv->last_vblank_valid = 1;
41256 }
41257- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41258+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41259 DRM_DEBUG("US per vblank is: %u\n",
41260 dev_priv->usec_per_vblank);
41261 }
41262@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41263
41264 for (i = 0; i < dev_priv->num_irqs; ++i) {
41265 if (status & cur_irq->pending_mask) {
41266- atomic_inc(&cur_irq->irq_received);
41267+ atomic_inc_unchecked(&cur_irq->irq_received);
41268 wake_up(&cur_irq->irq_queue);
41269 handled = 1;
41270 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41271@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41272 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41273 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41274 masks[irq][4]));
41275- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41276+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41277 } else {
41278 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41279 (((cur_irq_sequence =
41280- atomic_read(&cur_irq->irq_received)) -
41281+ atomic_read_unchecked(&cur_irq->irq_received)) -
41282 *sequence) <= (1 << 23)));
41283 }
41284 *sequence = cur_irq_sequence;
41285@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41286 }
41287
41288 for (i = 0; i < dev_priv->num_irqs; ++i) {
41289- atomic_set(&cur_irq->irq_received, 0);
41290+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41291 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41292 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41293 init_waitqueue_head(&cur_irq->irq_queue);
41294@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41295 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41296 case VIA_IRQ_RELATIVE:
41297 irqwait->request.sequence +=
41298- atomic_read(&cur_irq->irq_received);
41299+ atomic_read_unchecked(&cur_irq->irq_received);
41300 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41301 case VIA_IRQ_ABSOLUTE:
41302 break;
41303diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41304index 0783155..b29e18e 100644
41305--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41306+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41307@@ -437,7 +437,7 @@ struct vmw_private {
41308 * Fencing and IRQs.
41309 */
41310
41311- atomic_t marker_seq;
41312+ atomic_unchecked_t marker_seq;
41313 wait_queue_head_t fence_queue;
41314 wait_queue_head_t fifo_queue;
41315 int fence_queue_waiters; /* Protected by hw_mutex */
41316diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41317index 6ccd993..618d592 100644
41318--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41319+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41320@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41321 (unsigned int) min,
41322 (unsigned int) fifo->capabilities);
41323
41324- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41325+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41326 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41327 vmw_marker_queue_init(&fifo->marker_queue);
41328 return vmw_fifo_send_fence(dev_priv, &dummy);
41329@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41330 if (reserveable)
41331 iowrite32(bytes, fifo_mem +
41332 SVGA_FIFO_RESERVED);
41333- return fifo_mem + (next_cmd >> 2);
41334+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41335 } else {
41336 need_bounce = true;
41337 }
41338@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41339
41340 fm = vmw_fifo_reserve(dev_priv, bytes);
41341 if (unlikely(fm == NULL)) {
41342- *seqno = atomic_read(&dev_priv->marker_seq);
41343+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41344 ret = -ENOMEM;
41345 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41346 false, 3*HZ);
41347@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41348 }
41349
41350 do {
41351- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41352+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41353 } while (*seqno == 0);
41354
41355 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41356diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41357index b1273e8..9c274fd 100644
41358--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41359+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41360@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41361 }
41362
41363 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41364- vmw_gmrid_man_init,
41365- vmw_gmrid_man_takedown,
41366- vmw_gmrid_man_get_node,
41367- vmw_gmrid_man_put_node,
41368- vmw_gmrid_man_debug
41369+ .init = vmw_gmrid_man_init,
41370+ .takedown = vmw_gmrid_man_takedown,
41371+ .get_node = vmw_gmrid_man_get_node,
41372+ .put_node = vmw_gmrid_man_put_node,
41373+ .debug = vmw_gmrid_man_debug
41374 };
41375diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41376index 47b7094..698ba09 100644
41377--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41378+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41379@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41380 int ret;
41381
41382 num_clips = arg->num_clips;
41383- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41384+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41385
41386 if (unlikely(num_clips == 0))
41387 return 0;
41388@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41389 int ret;
41390
41391 num_clips = arg->num_clips;
41392- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41393+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41394
41395 if (unlikely(num_clips == 0))
41396 return 0;
41397diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41398index 0c42376..6febe77 100644
41399--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41400+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41401@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41402 * emitted. Then the fence is stale and signaled.
41403 */
41404
41405- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41406+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41407 > VMW_FENCE_WRAP);
41408
41409 return ret;
41410@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41411
41412 if (fifo_idle)
41413 down_read(&fifo_state->rwsem);
41414- signal_seq = atomic_read(&dev_priv->marker_seq);
41415+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41416 ret = 0;
41417
41418 for (;;) {
41419diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41420index 8a8725c2..afed796 100644
41421--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41422+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41423@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41424 while (!vmw_lag_lt(queue, us)) {
41425 spin_lock(&queue->lock);
41426 if (list_empty(&queue->head))
41427- seqno = atomic_read(&dev_priv->marker_seq);
41428+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41429 else {
41430 marker = list_first_entry(&queue->head,
41431 struct vmw_marker, head);
41432diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41433index ec0ae2d..dc0780b 100644
41434--- a/drivers/gpu/vga/vga_switcheroo.c
41435+++ b/drivers/gpu/vga/vga_switcheroo.c
41436@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41437
41438 /* this version is for the case where the power switch is separate
41439 to the device being powered down. */
41440-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41441+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41442 {
41443 /* copy over all the bus versions */
41444 if (dev->bus && dev->bus->pm) {
41445@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41446 return ret;
41447 }
41448
41449-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41450+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41451 {
41452 /* copy over all the bus versions */
41453 if (dev->bus && dev->bus->pm) {
41454diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41455index cc32a6f..02a4b1c 100644
41456--- a/drivers/hid/hid-core.c
41457+++ b/drivers/hid/hid-core.c
41458@@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41459
41460 int hid_add_device(struct hid_device *hdev)
41461 {
41462- static atomic_t id = ATOMIC_INIT(0);
41463+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41464 int ret;
41465
41466 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41467@@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41468 /* XXX hack, any other cleaner solution after the driver core
41469 * is converted to allow more than 20 bytes as the device name? */
41470 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41471- hdev->vendor, hdev->product, atomic_inc_return(&id));
41472+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41473
41474 hid_debug_register(hdev, dev_name(&hdev->dev));
41475 ret = device_add(&hdev->dev);
41476diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41477index c13fb5b..55a3802 100644
41478--- a/drivers/hid/hid-wiimote-debug.c
41479+++ b/drivers/hid/hid-wiimote-debug.c
41480@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41481 else if (size == 0)
41482 return -EIO;
41483
41484- if (copy_to_user(u, buf, size))
41485+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41486 return -EFAULT;
41487
41488 *off += size;
41489diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41490index cedc6da..2c3da2a 100644
41491--- a/drivers/hid/uhid.c
41492+++ b/drivers/hid/uhid.c
41493@@ -47,7 +47,7 @@ struct uhid_device {
41494 struct mutex report_lock;
41495 wait_queue_head_t report_wait;
41496 atomic_t report_done;
41497- atomic_t report_id;
41498+ atomic_unchecked_t report_id;
41499 struct uhid_event report_buf;
41500 };
41501
41502@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41503
41504 spin_lock_irqsave(&uhid->qlock, flags);
41505 ev->type = UHID_FEATURE;
41506- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41507+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41508 ev->u.feature.rnum = rnum;
41509 ev->u.feature.rtype = report_type;
41510
41511@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41512 spin_lock_irqsave(&uhid->qlock, flags);
41513
41514 /* id for old report; drop it silently */
41515- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41516+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41517 goto unlock;
41518 if (atomic_read(&uhid->report_done))
41519 goto unlock;
41520diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41521index 69ea36f..8dbf4bb 100644
41522--- a/drivers/hv/channel.c
41523+++ b/drivers/hv/channel.c
41524@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41525 int ret = 0;
41526 int t;
41527
41528- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41529- atomic_inc(&vmbus_connection.next_gpadl_handle);
41530+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41531+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41532
41533 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41534 if (ret)
41535diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41536index bcb4950..61dba6c 100644
41537--- a/drivers/hv/hv.c
41538+++ b/drivers/hv/hv.c
41539@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41540 u64 output_address = (output) ? virt_to_phys(output) : 0;
41541 u32 output_address_hi = output_address >> 32;
41542 u32 output_address_lo = output_address & 0xFFFFFFFF;
41543- void *hypercall_page = hv_context.hypercall_page;
41544+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41545
41546 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41547 "=a"(hv_status_lo) : "d" (control_hi),
41548@@ -154,7 +154,7 @@ int hv_init(void)
41549 /* See if the hypercall page is already set */
41550 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41551
41552- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41553+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41554
41555 if (!virtaddr)
41556 goto cleanup;
41557diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41558index 7e17a54..a50a33d 100644
41559--- a/drivers/hv/hv_balloon.c
41560+++ b/drivers/hv/hv_balloon.c
41561@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41562
41563 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41564 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41565-static atomic_t trans_id = ATOMIC_INIT(0);
41566+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41567
41568 static int dm_ring_size = (5 * PAGE_SIZE);
41569
41570@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41571 pr_info("Memory hot add failed\n");
41572
41573 dm->state = DM_INITIALIZED;
41574- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41575+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41576 vmbus_sendpacket(dm->dev->channel, &resp,
41577 sizeof(struct dm_hot_add_response),
41578 (unsigned long)NULL,
41579@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41580 memset(&status, 0, sizeof(struct dm_status));
41581 status.hdr.type = DM_STATUS_REPORT;
41582 status.hdr.size = sizeof(struct dm_status);
41583- status.hdr.trans_id = atomic_inc_return(&trans_id);
41584+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41585
41586 /*
41587 * The host expects the guest to report free memory.
41588@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41589 * send the status. This can happen if we were interrupted
41590 * after we picked our transaction ID.
41591 */
41592- if (status.hdr.trans_id != atomic_read(&trans_id))
41593+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41594 return;
41595
41596 vmbus_sendpacket(dm->dev->channel, &status,
41597@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41598 */
41599
41600 do {
41601- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41602+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41603 ret = vmbus_sendpacket(dm_device.dev->channel,
41604 bl_resp,
41605 bl_resp->hdr.size,
41606@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41607
41608 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41609 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41610- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41611+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41612 resp.hdr.size = sizeof(struct dm_unballoon_response);
41613
41614 vmbus_sendpacket(dm_device.dev->channel, &resp,
41615@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41616 memset(&version_req, 0, sizeof(struct dm_version_request));
41617 version_req.hdr.type = DM_VERSION_REQUEST;
41618 version_req.hdr.size = sizeof(struct dm_version_request);
41619- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41620+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41621 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41622 version_req.is_last_attempt = 1;
41623
41624@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41625 memset(&version_req, 0, sizeof(struct dm_version_request));
41626 version_req.hdr.type = DM_VERSION_REQUEST;
41627 version_req.hdr.size = sizeof(struct dm_version_request);
41628- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41629+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41630 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41631 version_req.is_last_attempt = 0;
41632
41633@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41634 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41635 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41636 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41637- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41638+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41639
41640 cap_msg.caps.cap_bits.balloon = 1;
41641 cap_msg.caps.cap_bits.hot_add = 1;
41642diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41643index e055176..c22ff1f 100644
41644--- a/drivers/hv/hyperv_vmbus.h
41645+++ b/drivers/hv/hyperv_vmbus.h
41646@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41647 struct vmbus_connection {
41648 enum vmbus_connect_state conn_state;
41649
41650- atomic_t next_gpadl_handle;
41651+ atomic_unchecked_t next_gpadl_handle;
41652
41653 /*
41654 * Represents channel interrupts. Each bit position represents a
41655diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41656index 077bb1b..d433d74 100644
41657--- a/drivers/hv/vmbus_drv.c
41658+++ b/drivers/hv/vmbus_drv.c
41659@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41660 {
41661 int ret = 0;
41662
41663- static atomic_t device_num = ATOMIC_INIT(0);
41664+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41665
41666 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41667- atomic_inc_return(&device_num));
41668+ atomic_inc_return_unchecked(&device_num));
41669
41670 child_device_obj->device.bus = &hv_bus;
41671 child_device_obj->device.parent = &hv_acpi_dev->dev;
41672diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41673index 579bdf9..75118b5 100644
41674--- a/drivers/hwmon/acpi_power_meter.c
41675+++ b/drivers/hwmon/acpi_power_meter.c
41676@@ -116,7 +116,7 @@ struct sensor_template {
41677 struct device_attribute *devattr,
41678 const char *buf, size_t count);
41679 int index;
41680-};
41681+} __do_const;
41682
41683 /* Averaging interval */
41684 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41685@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41686 struct sensor_template *attrs)
41687 {
41688 struct device *dev = &resource->acpi_dev->dev;
41689- struct sensor_device_attribute *sensors =
41690+ sensor_device_attribute_no_const *sensors =
41691 &resource->sensors[resource->num_sensors];
41692 int res = 0;
41693
41694diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41695index 3288f13..71cfb4e 100644
41696--- a/drivers/hwmon/applesmc.c
41697+++ b/drivers/hwmon/applesmc.c
41698@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41699 {
41700 struct applesmc_node_group *grp;
41701 struct applesmc_dev_attr *node;
41702- struct attribute *attr;
41703+ attribute_no_const *attr;
41704 int ret, i;
41705
41706 for (grp = groups; grp->format; grp++) {
41707diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41708index ae208f6..48b6c5b 100644
41709--- a/drivers/hwmon/asus_atk0110.c
41710+++ b/drivers/hwmon/asus_atk0110.c
41711@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41712 struct atk_sensor_data {
41713 struct list_head list;
41714 struct atk_data *data;
41715- struct device_attribute label_attr;
41716- struct device_attribute input_attr;
41717- struct device_attribute limit1_attr;
41718- struct device_attribute limit2_attr;
41719+ device_attribute_no_const label_attr;
41720+ device_attribute_no_const input_attr;
41721+ device_attribute_no_const limit1_attr;
41722+ device_attribute_no_const limit2_attr;
41723 char label_attr_name[ATTR_NAME_SIZE];
41724 char input_attr_name[ATTR_NAME_SIZE];
41725 char limit1_attr_name[ATTR_NAME_SIZE];
41726@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41727 static struct device_attribute atk_name_attr =
41728 __ATTR(name, 0444, atk_name_show, NULL);
41729
41730-static void atk_init_attribute(struct device_attribute *attr, char *name,
41731+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41732 sysfs_show_func show)
41733 {
41734 sysfs_attr_init(&attr->attr);
41735diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41736index bbb0b0d..9fe1332 100644
41737--- a/drivers/hwmon/coretemp.c
41738+++ b/drivers/hwmon/coretemp.c
41739@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41740 return NOTIFY_OK;
41741 }
41742
41743-static struct notifier_block coretemp_cpu_notifier __refdata = {
41744+static struct notifier_block coretemp_cpu_notifier = {
41745 .notifier_call = coretemp_cpu_callback,
41746 };
41747
41748diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41749index 632f1dc..57e6a58 100644
41750--- a/drivers/hwmon/ibmaem.c
41751+++ b/drivers/hwmon/ibmaem.c
41752@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41753 struct aem_rw_sensor_template *rw)
41754 {
41755 struct device *dev = &data->pdev->dev;
41756- struct sensor_device_attribute *sensors = data->sensors;
41757+ sensor_device_attribute_no_const *sensors = data->sensors;
41758 int err;
41759
41760 /* Set up read-only sensors */
41761diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41762index 708081b..fe2d4ab 100644
41763--- a/drivers/hwmon/iio_hwmon.c
41764+++ b/drivers/hwmon/iio_hwmon.c
41765@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41766 {
41767 struct device *dev = &pdev->dev;
41768 struct iio_hwmon_state *st;
41769- struct sensor_device_attribute *a;
41770+ sensor_device_attribute_no_const *a;
41771 int ret, i;
41772 int in_i = 1, temp_i = 1, curr_i = 1;
41773 enum iio_chan_type type;
41774diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41775index 38d5a63..cf2c2ea 100644
41776--- a/drivers/hwmon/nct6775.c
41777+++ b/drivers/hwmon/nct6775.c
41778@@ -944,10 +944,10 @@ static struct attribute_group *
41779 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41780 int repeat)
41781 {
41782- struct attribute_group *group;
41783+ attribute_group_no_const *group;
41784 struct sensor_device_attr_u *su;
41785- struct sensor_device_attribute *a;
41786- struct sensor_device_attribute_2 *a2;
41787+ sensor_device_attribute_no_const *a;
41788+ sensor_device_attribute_2_no_const *a2;
41789 struct attribute **attrs;
41790 struct sensor_device_template **t;
41791 int i, count;
41792diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41793index 291d11f..3f0dbbd 100644
41794--- a/drivers/hwmon/pmbus/pmbus_core.c
41795+++ b/drivers/hwmon/pmbus/pmbus_core.c
41796@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41797 return 0;
41798 }
41799
41800-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41801+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41802 const char *name,
41803 umode_t mode,
41804 ssize_t (*show)(struct device *dev,
41805@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41806 dev_attr->store = store;
41807 }
41808
41809-static void pmbus_attr_init(struct sensor_device_attribute *a,
41810+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41811 const char *name,
41812 umode_t mode,
41813 ssize_t (*show)(struct device *dev,
41814@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41815 u16 reg, u8 mask)
41816 {
41817 struct pmbus_boolean *boolean;
41818- struct sensor_device_attribute *a;
41819+ sensor_device_attribute_no_const *a;
41820
41821 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41822 if (!boolean)
41823@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41824 bool update, bool readonly)
41825 {
41826 struct pmbus_sensor *sensor;
41827- struct device_attribute *a;
41828+ device_attribute_no_const *a;
41829
41830 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41831 if (!sensor)
41832@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41833 const char *lstring, int index)
41834 {
41835 struct pmbus_label *label;
41836- struct device_attribute *a;
41837+ device_attribute_no_const *a;
41838
41839 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41840 if (!label)
41841diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41842index 97cd45a..ac54d8b 100644
41843--- a/drivers/hwmon/sht15.c
41844+++ b/drivers/hwmon/sht15.c
41845@@ -169,7 +169,7 @@ struct sht15_data {
41846 int supply_uv;
41847 bool supply_uv_valid;
41848 struct work_struct update_supply_work;
41849- atomic_t interrupt_handled;
41850+ atomic_unchecked_t interrupt_handled;
41851 };
41852
41853 /**
41854@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41855 ret = gpio_direction_input(data->pdata->gpio_data);
41856 if (ret)
41857 return ret;
41858- atomic_set(&data->interrupt_handled, 0);
41859+ atomic_set_unchecked(&data->interrupt_handled, 0);
41860
41861 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41862 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41863 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41864 /* Only relevant if the interrupt hasn't occurred. */
41865- if (!atomic_read(&data->interrupt_handled))
41866+ if (!atomic_read_unchecked(&data->interrupt_handled))
41867 schedule_work(&data->read_work);
41868 }
41869 ret = wait_event_timeout(data->wait_queue,
41870@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41871
41872 /* First disable the interrupt */
41873 disable_irq_nosync(irq);
41874- atomic_inc(&data->interrupt_handled);
41875+ atomic_inc_unchecked(&data->interrupt_handled);
41876 /* Then schedule a reading work struct */
41877 if (data->state != SHT15_READING_NOTHING)
41878 schedule_work(&data->read_work);
41879@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41880 * If not, then start the interrupt again - care here as could
41881 * have gone low in meantime so verify it hasn't!
41882 */
41883- atomic_set(&data->interrupt_handled, 0);
41884+ atomic_set_unchecked(&data->interrupt_handled, 0);
41885 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41886 /* If still not occurred or another handler was scheduled */
41887 if (gpio_get_value(data->pdata->gpio_data)
41888- || atomic_read(&data->interrupt_handled))
41889+ || atomic_read_unchecked(&data->interrupt_handled))
41890 return;
41891 }
41892
41893diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41894index 38944e9..ae9e5ed 100644
41895--- a/drivers/hwmon/via-cputemp.c
41896+++ b/drivers/hwmon/via-cputemp.c
41897@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41898 return NOTIFY_OK;
41899 }
41900
41901-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41902+static struct notifier_block via_cputemp_cpu_notifier = {
41903 .notifier_call = via_cputemp_cpu_callback,
41904 };
41905
41906diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41907index 41fc683..a39cfea 100644
41908--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41909+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41910@@ -43,7 +43,7 @@
41911 extern struct i2c_adapter amd756_smbus;
41912
41913 static struct i2c_adapter *s4882_adapter;
41914-static struct i2c_algorithm *s4882_algo;
41915+static i2c_algorithm_no_const *s4882_algo;
41916
41917 /* Wrapper access functions for multiplexed SMBus */
41918 static DEFINE_MUTEX(amd756_lock);
41919diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41920index 721f7eb..0fd2a09 100644
41921--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41922+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41923@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41924 /* usb layer */
41925
41926 /* Send command to device, and get response. */
41927-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41928+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41929 {
41930 int ret = 0;
41931 int actual;
41932diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41933index b170bdf..3c76427 100644
41934--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41935+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41936@@ -41,7 +41,7 @@
41937 extern struct i2c_adapter *nforce2_smbus;
41938
41939 static struct i2c_adapter *s4985_adapter;
41940-static struct i2c_algorithm *s4985_algo;
41941+static i2c_algorithm_no_const *s4985_algo;
41942
41943 /* Wrapper access functions for multiplexed SMBus */
41944 static DEFINE_MUTEX(nforce2_lock);
41945diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41946index 80b47e8..1a6040d9 100644
41947--- a/drivers/i2c/i2c-dev.c
41948+++ b/drivers/i2c/i2c-dev.c
41949@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41950 break;
41951 }
41952
41953- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41954+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41955 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41956 if (IS_ERR(rdwr_pa[i].buf)) {
41957 res = PTR_ERR(rdwr_pa[i].buf);
41958diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41959index 0b510ba..4fbb5085 100644
41960--- a/drivers/ide/ide-cd.c
41961+++ b/drivers/ide/ide-cd.c
41962@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41963 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41964 if ((unsigned long)buf & alignment
41965 || blk_rq_bytes(rq) & q->dma_pad_mask
41966- || object_is_on_stack(buf))
41967+ || object_starts_on_stack(buf))
41968 drive->dma = 0;
41969 }
41970 }
41971diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41972index acc911a..8700c3c 100644
41973--- a/drivers/iio/industrialio-core.c
41974+++ b/drivers/iio/industrialio-core.c
41975@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41976 }
41977
41978 static
41979-int __iio_device_attr_init(struct device_attribute *dev_attr,
41980+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41981 const char *postfix,
41982 struct iio_chan_spec const *chan,
41983 ssize_t (*readfunc)(struct device *dev,
41984diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41985index c323917..6ddea8b 100644
41986--- a/drivers/infiniband/core/cm.c
41987+++ b/drivers/infiniband/core/cm.c
41988@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41989
41990 struct cm_counter_group {
41991 struct kobject obj;
41992- atomic_long_t counter[CM_ATTR_COUNT];
41993+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41994 };
41995
41996 struct cm_counter_attribute {
41997@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41998 struct ib_mad_send_buf *msg = NULL;
41999 int ret;
42000
42001- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42002+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42003 counter[CM_REQ_COUNTER]);
42004
42005 /* Quick state check to discard duplicate REQs. */
42006@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42007 if (!cm_id_priv)
42008 return;
42009
42010- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42011+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42012 counter[CM_REP_COUNTER]);
42013 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42014 if (ret)
42015@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42016 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42017 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42018 spin_unlock_irq(&cm_id_priv->lock);
42019- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42020+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42021 counter[CM_RTU_COUNTER]);
42022 goto out;
42023 }
42024@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42025 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42026 dreq_msg->local_comm_id);
42027 if (!cm_id_priv) {
42028- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42029+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42030 counter[CM_DREQ_COUNTER]);
42031 cm_issue_drep(work->port, work->mad_recv_wc);
42032 return -EINVAL;
42033@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42034 case IB_CM_MRA_REP_RCVD:
42035 break;
42036 case IB_CM_TIMEWAIT:
42037- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42038+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42039 counter[CM_DREQ_COUNTER]);
42040 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42041 goto unlock;
42042@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42043 cm_free_msg(msg);
42044 goto deref;
42045 case IB_CM_DREQ_RCVD:
42046- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42047+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42048 counter[CM_DREQ_COUNTER]);
42049 goto unlock;
42050 default:
42051@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42052 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42053 cm_id_priv->msg, timeout)) {
42054 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42055- atomic_long_inc(&work->port->
42056+ atomic_long_inc_unchecked(&work->port->
42057 counter_group[CM_RECV_DUPLICATES].
42058 counter[CM_MRA_COUNTER]);
42059 goto out;
42060@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42061 break;
42062 case IB_CM_MRA_REQ_RCVD:
42063 case IB_CM_MRA_REP_RCVD:
42064- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42065+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42066 counter[CM_MRA_COUNTER]);
42067 /* fall through */
42068 default:
42069@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42070 case IB_CM_LAP_IDLE:
42071 break;
42072 case IB_CM_MRA_LAP_SENT:
42073- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42074+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42075 counter[CM_LAP_COUNTER]);
42076 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42077 goto unlock;
42078@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42079 cm_free_msg(msg);
42080 goto deref;
42081 case IB_CM_LAP_RCVD:
42082- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42083+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42084 counter[CM_LAP_COUNTER]);
42085 goto unlock;
42086 default:
42087@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42088 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42089 if (cur_cm_id_priv) {
42090 spin_unlock_irq(&cm.lock);
42091- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42092+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42093 counter[CM_SIDR_REQ_COUNTER]);
42094 goto out; /* Duplicate message. */
42095 }
42096@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42097 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42098 msg->retries = 1;
42099
42100- atomic_long_add(1 + msg->retries,
42101+ atomic_long_add_unchecked(1 + msg->retries,
42102 &port->counter_group[CM_XMIT].counter[attr_index]);
42103 if (msg->retries)
42104- atomic_long_add(msg->retries,
42105+ atomic_long_add_unchecked(msg->retries,
42106 &port->counter_group[CM_XMIT_RETRIES].
42107 counter[attr_index]);
42108
42109@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42110 }
42111
42112 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42113- atomic_long_inc(&port->counter_group[CM_RECV].
42114+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42115 counter[attr_id - CM_ATTR_ID_OFFSET]);
42116
42117 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42118@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42119 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42120
42121 return sprintf(buf, "%ld\n",
42122- atomic_long_read(&group->counter[cm_attr->index]));
42123+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42124 }
42125
42126 static const struct sysfs_ops cm_counter_ops = {
42127diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42128index 9f5ad7c..588cd84 100644
42129--- a/drivers/infiniband/core/fmr_pool.c
42130+++ b/drivers/infiniband/core/fmr_pool.c
42131@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42132
42133 struct task_struct *thread;
42134
42135- atomic_t req_ser;
42136- atomic_t flush_ser;
42137+ atomic_unchecked_t req_ser;
42138+ atomic_unchecked_t flush_ser;
42139
42140 wait_queue_head_t force_wait;
42141 };
42142@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42143 struct ib_fmr_pool *pool = pool_ptr;
42144
42145 do {
42146- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42147+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42148 ib_fmr_batch_release(pool);
42149
42150- atomic_inc(&pool->flush_ser);
42151+ atomic_inc_unchecked(&pool->flush_ser);
42152 wake_up_interruptible(&pool->force_wait);
42153
42154 if (pool->flush_function)
42155@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42156 }
42157
42158 set_current_state(TASK_INTERRUPTIBLE);
42159- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42160+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42161 !kthread_should_stop())
42162 schedule();
42163 __set_current_state(TASK_RUNNING);
42164@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42165 pool->dirty_watermark = params->dirty_watermark;
42166 pool->dirty_len = 0;
42167 spin_lock_init(&pool->pool_lock);
42168- atomic_set(&pool->req_ser, 0);
42169- atomic_set(&pool->flush_ser, 0);
42170+ atomic_set_unchecked(&pool->req_ser, 0);
42171+ atomic_set_unchecked(&pool->flush_ser, 0);
42172 init_waitqueue_head(&pool->force_wait);
42173
42174 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42175@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42176 }
42177 spin_unlock_irq(&pool->pool_lock);
42178
42179- serial = atomic_inc_return(&pool->req_ser);
42180+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42181 wake_up_process(pool->thread);
42182
42183 if (wait_event_interruptible(pool->force_wait,
42184- atomic_read(&pool->flush_ser) - serial >= 0))
42185+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42186 return -EINTR;
42187
42188 return 0;
42189@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42190 } else {
42191 list_add_tail(&fmr->list, &pool->dirty_list);
42192 if (++pool->dirty_len >= pool->dirty_watermark) {
42193- atomic_inc(&pool->req_ser);
42194+ atomic_inc_unchecked(&pool->req_ser);
42195 wake_up_process(pool->thread);
42196 }
42197 }
42198diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42199index 41b1195..27971a0 100644
42200--- a/drivers/infiniband/hw/cxgb4/mem.c
42201+++ b/drivers/infiniband/hw/cxgb4/mem.c
42202@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42203 int err;
42204 struct fw_ri_tpte tpt;
42205 u32 stag_idx;
42206- static atomic_t key;
42207+ static atomic_unchecked_t key;
42208
42209 if (c4iw_fatal_error(rdev))
42210 return -EIO;
42211@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42212 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42213 rdev->stats.stag.max = rdev->stats.stag.cur;
42214 mutex_unlock(&rdev->stats.lock);
42215- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42216+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42217 }
42218 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42219 __func__, stag_state, type, pdid, stag_idx);
42220diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42221index 644c2c7..ecf0879 100644
42222--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42223+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42224@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42225 }
42226
42227 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42228- ipath_mapping_error,
42229- ipath_dma_map_single,
42230- ipath_dma_unmap_single,
42231- ipath_dma_map_page,
42232- ipath_dma_unmap_page,
42233- ipath_map_sg,
42234- ipath_unmap_sg,
42235- ipath_sg_dma_address,
42236- ipath_sg_dma_len,
42237- ipath_sync_single_for_cpu,
42238- ipath_sync_single_for_device,
42239- ipath_dma_alloc_coherent,
42240- ipath_dma_free_coherent
42241+ .mapping_error = ipath_mapping_error,
42242+ .map_single = ipath_dma_map_single,
42243+ .unmap_single = ipath_dma_unmap_single,
42244+ .map_page = ipath_dma_map_page,
42245+ .unmap_page = ipath_dma_unmap_page,
42246+ .map_sg = ipath_map_sg,
42247+ .unmap_sg = ipath_unmap_sg,
42248+ .dma_address = ipath_sg_dma_address,
42249+ .dma_len = ipath_sg_dma_len,
42250+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42251+ .sync_single_for_device = ipath_sync_single_for_device,
42252+ .alloc_coherent = ipath_dma_alloc_coherent,
42253+ .free_coherent = ipath_dma_free_coherent
42254 };
42255diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42256index 79b3dbc..96e5fcc 100644
42257--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42258+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42259@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42260 struct ib_atomic_eth *ateth;
42261 struct ipath_ack_entry *e;
42262 u64 vaddr;
42263- atomic64_t *maddr;
42264+ atomic64_unchecked_t *maddr;
42265 u64 sdata;
42266 u32 rkey;
42267 u8 next;
42268@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42269 IB_ACCESS_REMOTE_ATOMIC)))
42270 goto nack_acc_unlck;
42271 /* Perform atomic OP and save result. */
42272- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42273+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42274 sdata = be64_to_cpu(ateth->swap_data);
42275 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42276 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42277- (u64) atomic64_add_return(sdata, maddr) - sdata :
42278+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42279 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42280 be64_to_cpu(ateth->compare_data),
42281 sdata);
42282diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42283index 1f95bba..9530f87 100644
42284--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42285+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42286@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42287 unsigned long flags;
42288 struct ib_wc wc;
42289 u64 sdata;
42290- atomic64_t *maddr;
42291+ atomic64_unchecked_t *maddr;
42292 enum ib_wc_status send_status;
42293
42294 /*
42295@@ -382,11 +382,11 @@ again:
42296 IB_ACCESS_REMOTE_ATOMIC)))
42297 goto acc_err;
42298 /* Perform atomic OP and save result. */
42299- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42300+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42301 sdata = wqe->wr.wr.atomic.compare_add;
42302 *(u64 *) sqp->s_sge.sge.vaddr =
42303 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42304- (u64) atomic64_add_return(sdata, maddr) - sdata :
42305+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42306 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42307 sdata, wqe->wr.wr.atomic.swap);
42308 goto send_comp;
42309diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42310index f2a3f48..673ec79 100644
42311--- a/drivers/infiniband/hw/mlx4/mad.c
42312+++ b/drivers/infiniband/hw/mlx4/mad.c
42313@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42314
42315 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42316 {
42317- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42318+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42319 cpu_to_be64(0xff00000000000000LL);
42320 }
42321
42322diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42323index 25b2cdf..099ff97 100644
42324--- a/drivers/infiniband/hw/mlx4/mcg.c
42325+++ b/drivers/infiniband/hw/mlx4/mcg.c
42326@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42327 {
42328 char name[20];
42329
42330- atomic_set(&ctx->tid, 0);
42331+ atomic_set_unchecked(&ctx->tid, 0);
42332 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42333 ctx->mcg_wq = create_singlethread_workqueue(name);
42334 if (!ctx->mcg_wq)
42335diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42336index a230683..3723f2d 100644
42337--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42338+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42339@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42340 struct list_head mcg_mgid0_list;
42341 struct workqueue_struct *mcg_wq;
42342 struct mlx4_ib_demux_pv_ctx **tun;
42343- atomic_t tid;
42344+ atomic_unchecked_t tid;
42345 int flushing; /* flushing the work queue */
42346 };
42347
42348diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42349index 9d3e5c1..6f166df 100644
42350--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42351+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42352@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42353 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42354 }
42355
42356-int mthca_QUERY_FW(struct mthca_dev *dev)
42357+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42358 {
42359 struct mthca_mailbox *mailbox;
42360 u32 *outbox;
42361@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42362 CMD_TIME_CLASS_B);
42363 }
42364
42365-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42366+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42367 int num_mtt)
42368 {
42369 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42370@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42371 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42372 }
42373
42374-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42375+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42376 int eq_num)
42377 {
42378 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42379@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42380 CMD_TIME_CLASS_B);
42381 }
42382
42383-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42384+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42385 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42386 void *in_mad, void *response_mad)
42387 {
42388diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42389index 87897b9..7e79542 100644
42390--- a/drivers/infiniband/hw/mthca/mthca_main.c
42391+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42392@@ -692,7 +692,7 @@ err_close:
42393 return err;
42394 }
42395
42396-static int mthca_setup_hca(struct mthca_dev *dev)
42397+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42398 {
42399 int err;
42400
42401diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42402index ed9a989..6aa5dc2 100644
42403--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42404+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42405@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42406 * through the bitmaps)
42407 */
42408
42409-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42410+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42411 {
42412 int o;
42413 int m;
42414@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42415 return key;
42416 }
42417
42418-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42419+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42420 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42421 {
42422 struct mthca_mailbox *mailbox;
42423@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42424 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42425 }
42426
42427-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42428+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42429 u64 *buffer_list, int buffer_size_shift,
42430 int list_len, u64 iova, u64 total_size,
42431 u32 access, struct mthca_mr *mr)
42432diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42433index 42dde06..1257310 100644
42434--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42435+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42436@@ -764,7 +764,7 @@ unlock:
42437 return 0;
42438 }
42439
42440-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42441+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42442 {
42443 struct mthca_dev *dev = to_mdev(ibcq->device);
42444 struct mthca_cq *cq = to_mcq(ibcq);
42445diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42446index 353c7b0..c6ce921 100644
42447--- a/drivers/infiniband/hw/nes/nes.c
42448+++ b/drivers/infiniband/hw/nes/nes.c
42449@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42450 LIST_HEAD(nes_adapter_list);
42451 static LIST_HEAD(nes_dev_list);
42452
42453-atomic_t qps_destroyed;
42454+atomic_unchecked_t qps_destroyed;
42455
42456 static unsigned int ee_flsh_adapter;
42457 static unsigned int sysfs_nonidx_addr;
42458@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42459 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42460 struct nes_adapter *nesadapter = nesdev->nesadapter;
42461
42462- atomic_inc(&qps_destroyed);
42463+ atomic_inc_unchecked(&qps_destroyed);
42464
42465 /* Free the control structures */
42466
42467diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42468index 33cc589..3bd6538 100644
42469--- a/drivers/infiniband/hw/nes/nes.h
42470+++ b/drivers/infiniband/hw/nes/nes.h
42471@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42472 extern unsigned int wqm_quanta;
42473 extern struct list_head nes_adapter_list;
42474
42475-extern atomic_t cm_connects;
42476-extern atomic_t cm_accepts;
42477-extern atomic_t cm_disconnects;
42478-extern atomic_t cm_closes;
42479-extern atomic_t cm_connecteds;
42480-extern atomic_t cm_connect_reqs;
42481-extern atomic_t cm_rejects;
42482-extern atomic_t mod_qp_timouts;
42483-extern atomic_t qps_created;
42484-extern atomic_t qps_destroyed;
42485-extern atomic_t sw_qps_destroyed;
42486+extern atomic_unchecked_t cm_connects;
42487+extern atomic_unchecked_t cm_accepts;
42488+extern atomic_unchecked_t cm_disconnects;
42489+extern atomic_unchecked_t cm_closes;
42490+extern atomic_unchecked_t cm_connecteds;
42491+extern atomic_unchecked_t cm_connect_reqs;
42492+extern atomic_unchecked_t cm_rejects;
42493+extern atomic_unchecked_t mod_qp_timouts;
42494+extern atomic_unchecked_t qps_created;
42495+extern atomic_unchecked_t qps_destroyed;
42496+extern atomic_unchecked_t sw_qps_destroyed;
42497 extern u32 mh_detected;
42498 extern u32 mh_pauses_sent;
42499 extern u32 cm_packets_sent;
42500@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42501 extern u32 cm_packets_received;
42502 extern u32 cm_packets_dropped;
42503 extern u32 cm_packets_retrans;
42504-extern atomic_t cm_listens_created;
42505-extern atomic_t cm_listens_destroyed;
42506+extern atomic_unchecked_t cm_listens_created;
42507+extern atomic_unchecked_t cm_listens_destroyed;
42508 extern u32 cm_backlog_drops;
42509-extern atomic_t cm_loopbacks;
42510-extern atomic_t cm_nodes_created;
42511-extern atomic_t cm_nodes_destroyed;
42512-extern atomic_t cm_accel_dropped_pkts;
42513-extern atomic_t cm_resets_recvd;
42514-extern atomic_t pau_qps_created;
42515-extern atomic_t pau_qps_destroyed;
42516+extern atomic_unchecked_t cm_loopbacks;
42517+extern atomic_unchecked_t cm_nodes_created;
42518+extern atomic_unchecked_t cm_nodes_destroyed;
42519+extern atomic_unchecked_t cm_accel_dropped_pkts;
42520+extern atomic_unchecked_t cm_resets_recvd;
42521+extern atomic_unchecked_t pau_qps_created;
42522+extern atomic_unchecked_t pau_qps_destroyed;
42523
42524 extern u32 int_mod_timer_init;
42525 extern u32 int_mod_cq_depth_256;
42526diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42527index 9c9f2f5..2559190 100644
42528--- a/drivers/infiniband/hw/nes/nes_cm.c
42529+++ b/drivers/infiniband/hw/nes/nes_cm.c
42530@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42531 u32 cm_packets_retrans;
42532 u32 cm_packets_created;
42533 u32 cm_packets_received;
42534-atomic_t cm_listens_created;
42535-atomic_t cm_listens_destroyed;
42536+atomic_unchecked_t cm_listens_created;
42537+atomic_unchecked_t cm_listens_destroyed;
42538 u32 cm_backlog_drops;
42539-atomic_t cm_loopbacks;
42540-atomic_t cm_nodes_created;
42541-atomic_t cm_nodes_destroyed;
42542-atomic_t cm_accel_dropped_pkts;
42543-atomic_t cm_resets_recvd;
42544+atomic_unchecked_t cm_loopbacks;
42545+atomic_unchecked_t cm_nodes_created;
42546+atomic_unchecked_t cm_nodes_destroyed;
42547+atomic_unchecked_t cm_accel_dropped_pkts;
42548+atomic_unchecked_t cm_resets_recvd;
42549
42550 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42551 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42552@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42553 /* instance of function pointers for client API */
42554 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42555 static struct nes_cm_ops nes_cm_api = {
42556- mini_cm_accelerated,
42557- mini_cm_listen,
42558- mini_cm_del_listen,
42559- mini_cm_connect,
42560- mini_cm_close,
42561- mini_cm_accept,
42562- mini_cm_reject,
42563- mini_cm_recv_pkt,
42564- mini_cm_dealloc_core,
42565- mini_cm_get,
42566- mini_cm_set
42567+ .accelerated = mini_cm_accelerated,
42568+ .listen = mini_cm_listen,
42569+ .stop_listener = mini_cm_del_listen,
42570+ .connect = mini_cm_connect,
42571+ .close = mini_cm_close,
42572+ .accept = mini_cm_accept,
42573+ .reject = mini_cm_reject,
42574+ .recv_pkt = mini_cm_recv_pkt,
42575+ .destroy_cm_core = mini_cm_dealloc_core,
42576+ .get = mini_cm_get,
42577+ .set = mini_cm_set
42578 };
42579
42580 static struct nes_cm_core *g_cm_core;
42581
42582-atomic_t cm_connects;
42583-atomic_t cm_accepts;
42584-atomic_t cm_disconnects;
42585-atomic_t cm_closes;
42586-atomic_t cm_connecteds;
42587-atomic_t cm_connect_reqs;
42588-atomic_t cm_rejects;
42589+atomic_unchecked_t cm_connects;
42590+atomic_unchecked_t cm_accepts;
42591+atomic_unchecked_t cm_disconnects;
42592+atomic_unchecked_t cm_closes;
42593+atomic_unchecked_t cm_connecteds;
42594+atomic_unchecked_t cm_connect_reqs;
42595+atomic_unchecked_t cm_rejects;
42596
42597 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42598 {
42599@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42600 kfree(listener);
42601 listener = NULL;
42602 ret = 0;
42603- atomic_inc(&cm_listens_destroyed);
42604+ atomic_inc_unchecked(&cm_listens_destroyed);
42605 } else {
42606 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42607 }
42608@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42609 cm_node->rem_mac);
42610
42611 add_hte_node(cm_core, cm_node);
42612- atomic_inc(&cm_nodes_created);
42613+ atomic_inc_unchecked(&cm_nodes_created);
42614
42615 return cm_node;
42616 }
42617@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42618 }
42619
42620 atomic_dec(&cm_core->node_cnt);
42621- atomic_inc(&cm_nodes_destroyed);
42622+ atomic_inc_unchecked(&cm_nodes_destroyed);
42623 nesqp = cm_node->nesqp;
42624 if (nesqp) {
42625 nesqp->cm_node = NULL;
42626@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42627
42628 static void drop_packet(struct sk_buff *skb)
42629 {
42630- atomic_inc(&cm_accel_dropped_pkts);
42631+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42632 dev_kfree_skb_any(skb);
42633 }
42634
42635@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42636 {
42637
42638 int reset = 0; /* whether to send reset in case of err.. */
42639- atomic_inc(&cm_resets_recvd);
42640+ atomic_inc_unchecked(&cm_resets_recvd);
42641 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42642 " refcnt=%d\n", cm_node, cm_node->state,
42643 atomic_read(&cm_node->ref_count));
42644@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42645 rem_ref_cm_node(cm_node->cm_core, cm_node);
42646 return NULL;
42647 }
42648- atomic_inc(&cm_loopbacks);
42649+ atomic_inc_unchecked(&cm_loopbacks);
42650 loopbackremotenode->loopbackpartner = cm_node;
42651 loopbackremotenode->tcp_cntxt.rcv_wscale =
42652 NES_CM_DEFAULT_RCV_WND_SCALE;
42653@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42654 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42655 else {
42656 rem_ref_cm_node(cm_core, cm_node);
42657- atomic_inc(&cm_accel_dropped_pkts);
42658+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42659 dev_kfree_skb_any(skb);
42660 }
42661 break;
42662@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42663
42664 if ((cm_id) && (cm_id->event_handler)) {
42665 if (issue_disconn) {
42666- atomic_inc(&cm_disconnects);
42667+ atomic_inc_unchecked(&cm_disconnects);
42668 cm_event.event = IW_CM_EVENT_DISCONNECT;
42669 cm_event.status = disconn_status;
42670 cm_event.local_addr = cm_id->local_addr;
42671@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42672 }
42673
42674 if (issue_close) {
42675- atomic_inc(&cm_closes);
42676+ atomic_inc_unchecked(&cm_closes);
42677 nes_disconnect(nesqp, 1);
42678
42679 cm_id->provider_data = nesqp;
42680@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42681
42682 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42683 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42684- atomic_inc(&cm_accepts);
42685+ atomic_inc_unchecked(&cm_accepts);
42686
42687 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42688 netdev_refcnt_read(nesvnic->netdev));
42689@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42690 struct nes_cm_core *cm_core;
42691 u8 *start_buff;
42692
42693- atomic_inc(&cm_rejects);
42694+ atomic_inc_unchecked(&cm_rejects);
42695 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42696 loopback = cm_node->loopbackpartner;
42697 cm_core = cm_node->cm_core;
42698@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42699 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42700 ntohs(laddr->sin_port));
42701
42702- atomic_inc(&cm_connects);
42703+ atomic_inc_unchecked(&cm_connects);
42704 nesqp->active_conn = 1;
42705
42706 /* cache the cm_id in the qp */
42707@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42708 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42709 return err;
42710 }
42711- atomic_inc(&cm_listens_created);
42712+ atomic_inc_unchecked(&cm_listens_created);
42713 }
42714
42715 cm_id->add_ref(cm_id);
42716@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42717
42718 if (nesqp->destroyed)
42719 return;
42720- atomic_inc(&cm_connecteds);
42721+ atomic_inc_unchecked(&cm_connecteds);
42722 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42723 " local port 0x%04X. jiffies = %lu.\n",
42724 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42725@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42726
42727 cm_id->add_ref(cm_id);
42728 ret = cm_id->event_handler(cm_id, &cm_event);
42729- atomic_inc(&cm_closes);
42730+ atomic_inc_unchecked(&cm_closes);
42731 cm_event.event = IW_CM_EVENT_CLOSE;
42732 cm_event.status = 0;
42733 cm_event.provider_data = cm_id->provider_data;
42734@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42735 return;
42736 cm_id = cm_node->cm_id;
42737
42738- atomic_inc(&cm_connect_reqs);
42739+ atomic_inc_unchecked(&cm_connect_reqs);
42740 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42741 cm_node, cm_id, jiffies);
42742
42743@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42744 return;
42745 cm_id = cm_node->cm_id;
42746
42747- atomic_inc(&cm_connect_reqs);
42748+ atomic_inc_unchecked(&cm_connect_reqs);
42749 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42750 cm_node, cm_id, jiffies);
42751
42752diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42753index 4166452..fc952c3 100644
42754--- a/drivers/infiniband/hw/nes/nes_mgt.c
42755+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42756@@ -40,8 +40,8 @@
42757 #include "nes.h"
42758 #include "nes_mgt.h"
42759
42760-atomic_t pau_qps_created;
42761-atomic_t pau_qps_destroyed;
42762+atomic_unchecked_t pau_qps_created;
42763+atomic_unchecked_t pau_qps_destroyed;
42764
42765 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42766 {
42767@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42768 {
42769 struct sk_buff *skb;
42770 unsigned long flags;
42771- atomic_inc(&pau_qps_destroyed);
42772+ atomic_inc_unchecked(&pau_qps_destroyed);
42773
42774 /* Free packets that have not yet been forwarded */
42775 /* Lock is acquired by skb_dequeue when removing the skb */
42776@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42777 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42778 skb_queue_head_init(&nesqp->pau_list);
42779 spin_lock_init(&nesqp->pau_lock);
42780- atomic_inc(&pau_qps_created);
42781+ atomic_inc_unchecked(&pau_qps_created);
42782 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42783 }
42784
42785diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42786index 49eb511..a774366 100644
42787--- a/drivers/infiniband/hw/nes/nes_nic.c
42788+++ b/drivers/infiniband/hw/nes/nes_nic.c
42789@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42790 target_stat_values[++index] = mh_detected;
42791 target_stat_values[++index] = mh_pauses_sent;
42792 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42793- target_stat_values[++index] = atomic_read(&cm_connects);
42794- target_stat_values[++index] = atomic_read(&cm_accepts);
42795- target_stat_values[++index] = atomic_read(&cm_disconnects);
42796- target_stat_values[++index] = atomic_read(&cm_connecteds);
42797- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42798- target_stat_values[++index] = atomic_read(&cm_rejects);
42799- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42800- target_stat_values[++index] = atomic_read(&qps_created);
42801- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42802- target_stat_values[++index] = atomic_read(&qps_destroyed);
42803- target_stat_values[++index] = atomic_read(&cm_closes);
42804+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42805+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42806+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42807+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42808+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42809+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42810+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42811+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42812+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42813+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42814+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42815 target_stat_values[++index] = cm_packets_sent;
42816 target_stat_values[++index] = cm_packets_bounced;
42817 target_stat_values[++index] = cm_packets_created;
42818 target_stat_values[++index] = cm_packets_received;
42819 target_stat_values[++index] = cm_packets_dropped;
42820 target_stat_values[++index] = cm_packets_retrans;
42821- target_stat_values[++index] = atomic_read(&cm_listens_created);
42822- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42823+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42824+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42825 target_stat_values[++index] = cm_backlog_drops;
42826- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42827- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42828- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42829- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42830- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42831+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42832+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42833+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42834+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42835+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42836 target_stat_values[++index] = nesadapter->free_4kpbl;
42837 target_stat_values[++index] = nesadapter->free_256pbl;
42838 target_stat_values[++index] = int_mod_timer_init;
42839 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42840 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42841 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42842- target_stat_values[++index] = atomic_read(&pau_qps_created);
42843- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42844+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42845+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42846 }
42847
42848 /**
42849diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42850index eb62461..2b7fc71 100644
42851--- a/drivers/infiniband/hw/nes/nes_verbs.c
42852+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42853@@ -46,9 +46,9 @@
42854
42855 #include <rdma/ib_umem.h>
42856
42857-atomic_t mod_qp_timouts;
42858-atomic_t qps_created;
42859-atomic_t sw_qps_destroyed;
42860+atomic_unchecked_t mod_qp_timouts;
42861+atomic_unchecked_t qps_created;
42862+atomic_unchecked_t sw_qps_destroyed;
42863
42864 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42865
42866@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42867 if (init_attr->create_flags)
42868 return ERR_PTR(-EINVAL);
42869
42870- atomic_inc(&qps_created);
42871+ atomic_inc_unchecked(&qps_created);
42872 switch (init_attr->qp_type) {
42873 case IB_QPT_RC:
42874 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42875@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42876 struct iw_cm_event cm_event;
42877 int ret = 0;
42878
42879- atomic_inc(&sw_qps_destroyed);
42880+ atomic_inc_unchecked(&sw_qps_destroyed);
42881 nesqp->destroyed = 1;
42882
42883 /* Blow away the connection if it exists. */
42884diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42885index 1946101..09766d2 100644
42886--- a/drivers/infiniband/hw/qib/qib.h
42887+++ b/drivers/infiniband/hw/qib/qib.h
42888@@ -52,6 +52,7 @@
42889 #include <linux/kref.h>
42890 #include <linux/sched.h>
42891 #include <linux/kthread.h>
42892+#include <linux/slab.h>
42893
42894 #include "qib_common.h"
42895 #include "qib_verbs.h"
42896diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42897index 24c41ba..102d71f 100644
42898--- a/drivers/input/gameport/gameport.c
42899+++ b/drivers/input/gameport/gameport.c
42900@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42901 */
42902 static void gameport_init_port(struct gameport *gameport)
42903 {
42904- static atomic_t gameport_no = ATOMIC_INIT(0);
42905+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42906
42907 __module_get(THIS_MODULE);
42908
42909 mutex_init(&gameport->drv_mutex);
42910 device_initialize(&gameport->dev);
42911 dev_set_name(&gameport->dev, "gameport%lu",
42912- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42913+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42914 gameport->dev.bus = &gameport_bus;
42915 gameport->dev.release = gameport_release_port;
42916 if (gameport->parent)
42917diff --git a/drivers/input/input.c b/drivers/input/input.c
42918index 1c4c0db..6f7abe3 100644
42919--- a/drivers/input/input.c
42920+++ b/drivers/input/input.c
42921@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42922 */
42923 struct input_dev *input_allocate_device(void)
42924 {
42925- static atomic_t input_no = ATOMIC_INIT(0);
42926+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42927 struct input_dev *dev;
42928
42929 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42930@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42931 INIT_LIST_HEAD(&dev->node);
42932
42933 dev_set_name(&dev->dev, "input%ld",
42934- (unsigned long) atomic_inc_return(&input_no) - 1);
42935+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42936
42937 __module_get(THIS_MODULE);
42938 }
42939diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42940index 4a95b22..874c182 100644
42941--- a/drivers/input/joystick/sidewinder.c
42942+++ b/drivers/input/joystick/sidewinder.c
42943@@ -30,6 +30,7 @@
42944 #include <linux/kernel.h>
42945 #include <linux/module.h>
42946 #include <linux/slab.h>
42947+#include <linux/sched.h>
42948 #include <linux/input.h>
42949 #include <linux/gameport.h>
42950 #include <linux/jiffies.h>
42951diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42952index 603fe0d..f63decc 100644
42953--- a/drivers/input/joystick/xpad.c
42954+++ b/drivers/input/joystick/xpad.c
42955@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42956
42957 static int xpad_led_probe(struct usb_xpad *xpad)
42958 {
42959- static atomic_t led_seq = ATOMIC_INIT(0);
42960+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42961 long led_no;
42962 struct xpad_led *led;
42963 struct led_classdev *led_cdev;
42964@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42965 if (!led)
42966 return -ENOMEM;
42967
42968- led_no = (long)atomic_inc_return(&led_seq) - 1;
42969+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42970
42971 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42972 led->xpad = xpad;
42973diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42974index e204f26..8459f15 100644
42975--- a/drivers/input/misc/ims-pcu.c
42976+++ b/drivers/input/misc/ims-pcu.c
42977@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42978
42979 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42980 {
42981- static atomic_t device_no = ATOMIC_INIT(0);
42982+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42983
42984 const struct ims_pcu_device_info *info;
42985 u8 device_id;
42986@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42987 }
42988
42989 /* Device appears to be operable, complete initialization */
42990- pcu->device_no = atomic_inc_return(&device_no) - 1;
42991+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42992
42993 error = ims_pcu_setup_backlight(pcu);
42994 if (error)
42995diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42996index 2f0b39d..7370f13 100644
42997--- a/drivers/input/mouse/psmouse.h
42998+++ b/drivers/input/mouse/psmouse.h
42999@@ -116,7 +116,7 @@ struct psmouse_attribute {
43000 ssize_t (*set)(struct psmouse *psmouse, void *data,
43001 const char *buf, size_t count);
43002 bool protect;
43003-};
43004+} __do_const;
43005 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43006
43007 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43008diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43009index b604564..3f14ae4 100644
43010--- a/drivers/input/mousedev.c
43011+++ b/drivers/input/mousedev.c
43012@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43013
43014 spin_unlock_irq(&client->packet_lock);
43015
43016- if (copy_to_user(buffer, data, count))
43017+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43018 return -EFAULT;
43019
43020 return count;
43021diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43022index 8f4c4ab..5fc8a45 100644
43023--- a/drivers/input/serio/serio.c
43024+++ b/drivers/input/serio/serio.c
43025@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
43026 */
43027 static void serio_init_port(struct serio *serio)
43028 {
43029- static atomic_t serio_no = ATOMIC_INIT(0);
43030+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43031
43032 __module_get(THIS_MODULE);
43033
43034@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
43035 mutex_init(&serio->drv_mutex);
43036 device_initialize(&serio->dev);
43037 dev_set_name(&serio->dev, "serio%ld",
43038- (long)atomic_inc_return(&serio_no) - 1);
43039+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43040 serio->dev.bus = &serio_bus;
43041 serio->dev.release = serio_release_port;
43042 serio->dev.groups = serio_device_attr_groups;
43043diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43044index c9a02fe..0debc75 100644
43045--- a/drivers/input/serio/serio_raw.c
43046+++ b/drivers/input/serio/serio_raw.c
43047@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43048
43049 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43050 {
43051- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43052+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43053 struct serio_raw *serio_raw;
43054 int err;
43055
43056@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43057 }
43058
43059 snprintf(serio_raw->name, sizeof(serio_raw->name),
43060- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43061+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43062 kref_init(&serio_raw->kref);
43063 INIT_LIST_HEAD(&serio_raw->client_list);
43064 init_waitqueue_head(&serio_raw->wait);
43065diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43066index e5555fc..937986d 100644
43067--- a/drivers/iommu/iommu.c
43068+++ b/drivers/iommu/iommu.c
43069@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43070 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43071 {
43072 bus_register_notifier(bus, &iommu_bus_nb);
43073- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43074+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43075 }
43076
43077 /**
43078diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43079index 228632c9..edfe331 100644
43080--- a/drivers/iommu/irq_remapping.c
43081+++ b/drivers/iommu/irq_remapping.c
43082@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43083 void panic_if_irq_remap(const char *msg)
43084 {
43085 if (irq_remapping_enabled)
43086- panic(msg);
43087+ panic("%s", msg);
43088 }
43089
43090 static void ir_ack_apic_edge(struct irq_data *data)
43091@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43092
43093 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43094 {
43095- chip->irq_print_chip = ir_print_prefix;
43096- chip->irq_ack = ir_ack_apic_edge;
43097- chip->irq_eoi = ir_ack_apic_level;
43098- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43099+ pax_open_kernel();
43100+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43101+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43102+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43103+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43104+ pax_close_kernel();
43105 }
43106
43107 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43108diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43109index 341c601..e5f407e 100644
43110--- a/drivers/irqchip/irq-gic.c
43111+++ b/drivers/irqchip/irq-gic.c
43112@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43113 * Supported arch specific GIC irq extension.
43114 * Default make them NULL.
43115 */
43116-struct irq_chip gic_arch_extn = {
43117+irq_chip_no_const gic_arch_extn = {
43118 .irq_eoi = NULL,
43119 .irq_mask = NULL,
43120 .irq_unmask = NULL,
43121@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43122 chained_irq_exit(chip, desc);
43123 }
43124
43125-static struct irq_chip gic_chip = {
43126+static irq_chip_no_const gic_chip __read_only = {
43127 .name = "GIC",
43128 .irq_mask = gic_mask_irq,
43129 .irq_unmask = gic_unmask_irq,
43130diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43131index 8777065..a4a9967 100644
43132--- a/drivers/irqchip/irq-renesas-irqc.c
43133+++ b/drivers/irqchip/irq-renesas-irqc.c
43134@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43135 struct irqc_priv *p;
43136 struct resource *io;
43137 struct resource *irq;
43138- struct irq_chip *irq_chip;
43139+ irq_chip_no_const *irq_chip;
43140 const char *name = dev_name(&pdev->dev);
43141 int ret;
43142 int k;
43143diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43144index ac6f72b..81150f2 100644
43145--- a/drivers/isdn/capi/capi.c
43146+++ b/drivers/isdn/capi/capi.c
43147@@ -81,8 +81,8 @@ struct capiminor {
43148
43149 struct capi20_appl *ap;
43150 u32 ncci;
43151- atomic_t datahandle;
43152- atomic_t msgid;
43153+ atomic_unchecked_t datahandle;
43154+ atomic_unchecked_t msgid;
43155
43156 struct tty_port port;
43157 int ttyinstop;
43158@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43159 capimsg_setu16(s, 2, mp->ap->applid);
43160 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43161 capimsg_setu8 (s, 5, CAPI_RESP);
43162- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43163+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43164 capimsg_setu32(s, 8, mp->ncci);
43165 capimsg_setu16(s, 12, datahandle);
43166 }
43167@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43168 mp->outbytes -= len;
43169 spin_unlock_bh(&mp->outlock);
43170
43171- datahandle = atomic_inc_return(&mp->datahandle);
43172+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43173 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43174 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43175 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43176 capimsg_setu16(skb->data, 2, mp->ap->applid);
43177 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43178 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43179- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43180+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43181 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43182 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43183 capimsg_setu16(skb->data, 16, len); /* Data length */
43184diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43185index c44950d..10ac276 100644
43186--- a/drivers/isdn/gigaset/bas-gigaset.c
43187+++ b/drivers/isdn/gigaset/bas-gigaset.c
43188@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43189
43190
43191 static const struct gigaset_ops gigops = {
43192- gigaset_write_cmd,
43193- gigaset_write_room,
43194- gigaset_chars_in_buffer,
43195- gigaset_brkchars,
43196- gigaset_init_bchannel,
43197- gigaset_close_bchannel,
43198- gigaset_initbcshw,
43199- gigaset_freebcshw,
43200- gigaset_reinitbcshw,
43201- gigaset_initcshw,
43202- gigaset_freecshw,
43203- gigaset_set_modem_ctrl,
43204- gigaset_baud_rate,
43205- gigaset_set_line_ctrl,
43206- gigaset_isoc_send_skb,
43207- gigaset_isoc_input,
43208+ .write_cmd = gigaset_write_cmd,
43209+ .write_room = gigaset_write_room,
43210+ .chars_in_buffer = gigaset_chars_in_buffer,
43211+ .brkchars = gigaset_brkchars,
43212+ .init_bchannel = gigaset_init_bchannel,
43213+ .close_bchannel = gigaset_close_bchannel,
43214+ .initbcshw = gigaset_initbcshw,
43215+ .freebcshw = gigaset_freebcshw,
43216+ .reinitbcshw = gigaset_reinitbcshw,
43217+ .initcshw = gigaset_initcshw,
43218+ .freecshw = gigaset_freecshw,
43219+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43220+ .baud_rate = gigaset_baud_rate,
43221+ .set_line_ctrl = gigaset_set_line_ctrl,
43222+ .send_skb = gigaset_isoc_send_skb,
43223+ .handle_input = gigaset_isoc_input,
43224 };
43225
43226 /* bas_gigaset_init
43227diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43228index 600c79b..3752bab 100644
43229--- a/drivers/isdn/gigaset/interface.c
43230+++ b/drivers/isdn/gigaset/interface.c
43231@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43232 }
43233 tty->driver_data = cs;
43234
43235- ++cs->port.count;
43236+ atomic_inc(&cs->port.count);
43237
43238- if (cs->port.count == 1) {
43239+ if (atomic_read(&cs->port.count) == 1) {
43240 tty_port_tty_set(&cs->port, tty);
43241 cs->port.low_latency = 1;
43242 }
43243@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43244
43245 if (!cs->connected)
43246 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43247- else if (!cs->port.count)
43248+ else if (!atomic_read(&cs->port.count))
43249 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43250- else if (!--cs->port.count)
43251+ else if (!atomic_dec_return(&cs->port.count))
43252 tty_port_tty_set(&cs->port, NULL);
43253
43254 mutex_unlock(&cs->mutex);
43255diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43256index 8c91fd5..14f13ce 100644
43257--- a/drivers/isdn/gigaset/ser-gigaset.c
43258+++ b/drivers/isdn/gigaset/ser-gigaset.c
43259@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43260 }
43261
43262 static const struct gigaset_ops ops = {
43263- gigaset_write_cmd,
43264- gigaset_write_room,
43265- gigaset_chars_in_buffer,
43266- gigaset_brkchars,
43267- gigaset_init_bchannel,
43268- gigaset_close_bchannel,
43269- gigaset_initbcshw,
43270- gigaset_freebcshw,
43271- gigaset_reinitbcshw,
43272- gigaset_initcshw,
43273- gigaset_freecshw,
43274- gigaset_set_modem_ctrl,
43275- gigaset_baud_rate,
43276- gigaset_set_line_ctrl,
43277- gigaset_m10x_send_skb, /* asyncdata.c */
43278- gigaset_m10x_input, /* asyncdata.c */
43279+ .write_cmd = gigaset_write_cmd,
43280+ .write_room = gigaset_write_room,
43281+ .chars_in_buffer = gigaset_chars_in_buffer,
43282+ .brkchars = gigaset_brkchars,
43283+ .init_bchannel = gigaset_init_bchannel,
43284+ .close_bchannel = gigaset_close_bchannel,
43285+ .initbcshw = gigaset_initbcshw,
43286+ .freebcshw = gigaset_freebcshw,
43287+ .reinitbcshw = gigaset_reinitbcshw,
43288+ .initcshw = gigaset_initcshw,
43289+ .freecshw = gigaset_freecshw,
43290+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43291+ .baud_rate = gigaset_baud_rate,
43292+ .set_line_ctrl = gigaset_set_line_ctrl,
43293+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43294+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43295 };
43296
43297
43298diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43299index d0a41cb..b953e50 100644
43300--- a/drivers/isdn/gigaset/usb-gigaset.c
43301+++ b/drivers/isdn/gigaset/usb-gigaset.c
43302@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43303 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43304 memcpy(cs->hw.usb->bchars, buf, 6);
43305 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43306- 0, 0, &buf, 6, 2000);
43307+ 0, 0, buf, 6, 2000);
43308 }
43309
43310 static void gigaset_freebcshw(struct bc_state *bcs)
43311@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43312 }
43313
43314 static const struct gigaset_ops ops = {
43315- gigaset_write_cmd,
43316- gigaset_write_room,
43317- gigaset_chars_in_buffer,
43318- gigaset_brkchars,
43319- gigaset_init_bchannel,
43320- gigaset_close_bchannel,
43321- gigaset_initbcshw,
43322- gigaset_freebcshw,
43323- gigaset_reinitbcshw,
43324- gigaset_initcshw,
43325- gigaset_freecshw,
43326- gigaset_set_modem_ctrl,
43327- gigaset_baud_rate,
43328- gigaset_set_line_ctrl,
43329- gigaset_m10x_send_skb,
43330- gigaset_m10x_input,
43331+ .write_cmd = gigaset_write_cmd,
43332+ .write_room = gigaset_write_room,
43333+ .chars_in_buffer = gigaset_chars_in_buffer,
43334+ .brkchars = gigaset_brkchars,
43335+ .init_bchannel = gigaset_init_bchannel,
43336+ .close_bchannel = gigaset_close_bchannel,
43337+ .initbcshw = gigaset_initbcshw,
43338+ .freebcshw = gigaset_freebcshw,
43339+ .reinitbcshw = gigaset_reinitbcshw,
43340+ .initcshw = gigaset_initcshw,
43341+ .freecshw = gigaset_freecshw,
43342+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43343+ .baud_rate = gigaset_baud_rate,
43344+ .set_line_ctrl = gigaset_set_line_ctrl,
43345+ .send_skb = gigaset_m10x_send_skb,
43346+ .handle_input = gigaset_m10x_input,
43347 };
43348
43349 /*
43350diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43351index 4d9b195..455075c 100644
43352--- a/drivers/isdn/hardware/avm/b1.c
43353+++ b/drivers/isdn/hardware/avm/b1.c
43354@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43355 }
43356 if (left) {
43357 if (t4file->user) {
43358- if (copy_from_user(buf, dp, left))
43359+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43360 return -EFAULT;
43361 } else {
43362 memcpy(buf, dp, left);
43363@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43364 }
43365 if (left) {
43366 if (config->user) {
43367- if (copy_from_user(buf, dp, left))
43368+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43369 return -EFAULT;
43370 } else {
43371 memcpy(buf, dp, left);
43372diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43373index 9bb12ba..d4262f7 100644
43374--- a/drivers/isdn/i4l/isdn_common.c
43375+++ b/drivers/isdn/i4l/isdn_common.c
43376@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43377 } else
43378 return -EINVAL;
43379 case IIOCDBGVAR:
43380+ if (!capable(CAP_SYS_RAWIO))
43381+ return -EPERM;
43382 if (arg) {
43383 if (copy_to_user(argp, &dev, sizeof(ulong)))
43384 return -EFAULT;
43385diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43386index 91d5730..336523e 100644
43387--- a/drivers/isdn/i4l/isdn_concap.c
43388+++ b/drivers/isdn/i4l/isdn_concap.c
43389@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43390 }
43391
43392 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43393- &isdn_concap_dl_data_req,
43394- &isdn_concap_dl_connect_req,
43395- &isdn_concap_dl_disconn_req
43396+ .data_req = &isdn_concap_dl_data_req,
43397+ .connect_req = &isdn_concap_dl_connect_req,
43398+ .disconn_req = &isdn_concap_dl_disconn_req
43399 };
43400
43401 /* The following should better go into a dedicated source file such that
43402diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43403index 3c5f249..5fac4d0 100644
43404--- a/drivers/isdn/i4l/isdn_tty.c
43405+++ b/drivers/isdn/i4l/isdn_tty.c
43406@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43407
43408 #ifdef ISDN_DEBUG_MODEM_OPEN
43409 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43410- port->count);
43411+ atomic_read(&port->count));
43412 #endif
43413- port->count++;
43414+ atomic_inc(&port->count);
43415 port->tty = tty;
43416 /*
43417 * Start up serial port
43418@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43419 #endif
43420 return;
43421 }
43422- if ((tty->count == 1) && (port->count != 1)) {
43423+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43424 /*
43425 * Uh, oh. tty->count is 1, which means that the tty
43426 * structure will be freed. Info->count should always
43427@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43428 * serial port won't be shutdown.
43429 */
43430 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43431- "info->count is %d\n", port->count);
43432- port->count = 1;
43433+ "info->count is %d\n", atomic_read(&port->count));
43434+ atomic_set(&port->count, 1);
43435 }
43436- if (--port->count < 0) {
43437+ if (atomic_dec_return(&port->count) < 0) {
43438 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43439- info->line, port->count);
43440- port->count = 0;
43441+ info->line, atomic_read(&port->count));
43442+ atomic_set(&port->count, 0);
43443 }
43444- if (port->count) {
43445+ if (atomic_read(&port->count)) {
43446 #ifdef ISDN_DEBUG_MODEM_OPEN
43447 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43448 #endif
43449@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43450 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43451 return;
43452 isdn_tty_shutdown(info);
43453- port->count = 0;
43454+ atomic_set(&port->count, 0);
43455 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43456 port->tty = NULL;
43457 wake_up_interruptible(&port->open_wait);
43458@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43459 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43460 modem_info *info = &dev->mdm.info[i];
43461
43462- if (info->port.count == 0)
43463+ if (atomic_read(&info->port.count) == 0)
43464 continue;
43465 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43466 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43467diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43468index e2d4e58..40cd045 100644
43469--- a/drivers/isdn/i4l/isdn_x25iface.c
43470+++ b/drivers/isdn/i4l/isdn_x25iface.c
43471@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43472
43473
43474 static struct concap_proto_ops ix25_pops = {
43475- &isdn_x25iface_proto_new,
43476- &isdn_x25iface_proto_del,
43477- &isdn_x25iface_proto_restart,
43478- &isdn_x25iface_proto_close,
43479- &isdn_x25iface_xmit,
43480- &isdn_x25iface_receive,
43481- &isdn_x25iface_connect_ind,
43482- &isdn_x25iface_disconn_ind
43483+ .proto_new = &isdn_x25iface_proto_new,
43484+ .proto_del = &isdn_x25iface_proto_del,
43485+ .restart = &isdn_x25iface_proto_restart,
43486+ .close = &isdn_x25iface_proto_close,
43487+ .encap_and_xmit = &isdn_x25iface_xmit,
43488+ .data_ind = &isdn_x25iface_receive,
43489+ .connect_ind = &isdn_x25iface_connect_ind,
43490+ .disconn_ind = &isdn_x25iface_disconn_ind
43491 };
43492
43493 /* error message helper function */
43494diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43495index 53d487f..cae33fe 100644
43496--- a/drivers/isdn/icn/icn.c
43497+++ b/drivers/isdn/icn/icn.c
43498@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43499 if (count > len)
43500 count = len;
43501 if (user) {
43502- if (copy_from_user(msg, buf, count))
43503+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43504 return -EFAULT;
43505 } else
43506 memcpy(msg, buf, count);
43507@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43508 ulong a;
43509 ulong flags;
43510 int i;
43511- char cbuf[60];
43512+ char cbuf[80];
43513 isdn_ctrl cmd;
43514 icn_cdef cdef;
43515 char __user *arg;
43516@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43517 break;
43518 if ((c->arg & 255) < ICN_BCH) {
43519 char *p;
43520- char dial[50];
43521 char dcode[4];
43522
43523 a = c->arg;
43524@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43525 } else
43526 /* Normal Dial */
43527 strcpy(dcode, "CAL");
43528- strcpy(dial, p);
43529- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43530- dcode, dial, c->parm.setup.si1,
43531- c->parm.setup.si2, c->parm.setup.eazmsn);
43532+ snprintf(cbuf, sizeof(cbuf),
43533+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43534+ dcode, p, c->parm.setup.si1,
43535+ c->parm.setup.si2, c->parm.setup.eazmsn);
43536 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43537 }
43538 break;
43539diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43540index a4f05c5..1433bc5 100644
43541--- a/drivers/isdn/mISDN/dsp_cmx.c
43542+++ b/drivers/isdn/mISDN/dsp_cmx.c
43543@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43544 static u16 dsp_count; /* last sample count */
43545 static int dsp_count_valid; /* if we have last sample count */
43546
43547-void
43548+void __intentional_overflow(-1)
43549 dsp_cmx_send(void *arg)
43550 {
43551 struct dsp_conf *conf;
43552diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43553index d93e245..e7ece6b 100644
43554--- a/drivers/leds/leds-clevo-mail.c
43555+++ b/drivers/leds/leds-clevo-mail.c
43556@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43557 * detected as working, but in reality it is not) as low as
43558 * possible.
43559 */
43560-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43561+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43562 {
43563 .callback = clevo_mail_led_dmi_callback,
43564 .ident = "Clevo D410J",
43565diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43566index 5b8f938..b73d657 100644
43567--- a/drivers/leds/leds-ss4200.c
43568+++ b/drivers/leds/leds-ss4200.c
43569@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43570 * detected as working, but in reality it is not) as low as
43571 * possible.
43572 */
43573-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43574+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43575 {
43576 .callback = ss4200_led_dmi_callback,
43577 .ident = "Intel SS4200-E",
43578diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43579index 0bf1e4e..b4bf44e 100644
43580--- a/drivers/lguest/core.c
43581+++ b/drivers/lguest/core.c
43582@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43583 * The end address needs +1 because __get_vm_area allocates an
43584 * extra guard page, so we need space for that.
43585 */
43586+
43587+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43588+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43589+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43590+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43591+#else
43592 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43593 VM_ALLOC, switcher_addr, switcher_addr
43594 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43595+#endif
43596+
43597 if (!switcher_vma) {
43598 err = -ENOMEM;
43599 printk("lguest: could not map switcher pages high\n");
43600@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43601 * Now the Switcher is mapped at the right address, we can't fail!
43602 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43603 */
43604- memcpy(switcher_vma->addr, start_switcher_text,
43605+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43606 end_switcher_text - start_switcher_text);
43607
43608 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43609diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43610index bfb39bb..08a603b 100644
43611--- a/drivers/lguest/page_tables.c
43612+++ b/drivers/lguest/page_tables.c
43613@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43614 /*:*/
43615
43616 #ifdef CONFIG_X86_PAE
43617-static void release_pmd(pmd_t *spmd)
43618+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43619 {
43620 /* If the entry's not present, there's nothing to release. */
43621 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43622diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43623index 922a1ac..9dd0c2a 100644
43624--- a/drivers/lguest/x86/core.c
43625+++ b/drivers/lguest/x86/core.c
43626@@ -59,7 +59,7 @@ static struct {
43627 /* Offset from where switcher.S was compiled to where we've copied it */
43628 static unsigned long switcher_offset(void)
43629 {
43630- return switcher_addr - (unsigned long)start_switcher_text;
43631+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43632 }
43633
43634 /* This cpu's struct lguest_pages (after the Switcher text page) */
43635@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43636 * These copies are pretty cheap, so we do them unconditionally: */
43637 /* Save the current Host top-level page directory.
43638 */
43639+
43640+#ifdef CONFIG_PAX_PER_CPU_PGD
43641+ pages->state.host_cr3 = read_cr3();
43642+#else
43643 pages->state.host_cr3 = __pa(current->mm->pgd);
43644+#endif
43645+
43646 /*
43647 * Set up the Guest's page tables to see this CPU's pages (and no
43648 * other CPU's pages).
43649@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43650 * compiled-in switcher code and the high-mapped copy we just made.
43651 */
43652 for (i = 0; i < IDT_ENTRIES; i++)
43653- default_idt_entries[i] += switcher_offset();
43654+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43655
43656 /*
43657 * Set up the Switcher's per-cpu areas.
43658@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43659 * it will be undisturbed when we switch. To change %cs and jump we
43660 * need this structure to feed to Intel's "lcall" instruction.
43661 */
43662- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43663+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43664 lguest_entry.segment = LGUEST_CS;
43665
43666 /*
43667diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43668index 40634b0..4f5855e 100644
43669--- a/drivers/lguest/x86/switcher_32.S
43670+++ b/drivers/lguest/x86/switcher_32.S
43671@@ -87,6 +87,7 @@
43672 #include <asm/page.h>
43673 #include <asm/segment.h>
43674 #include <asm/lguest.h>
43675+#include <asm/processor-flags.h>
43676
43677 // We mark the start of the code to copy
43678 // It's placed in .text tho it's never run here
43679@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43680 // Changes type when we load it: damn Intel!
43681 // For after we switch over our page tables
43682 // That entry will be read-only: we'd crash.
43683+
43684+#ifdef CONFIG_PAX_KERNEXEC
43685+ mov %cr0, %edx
43686+ xor $X86_CR0_WP, %edx
43687+ mov %edx, %cr0
43688+#endif
43689+
43690 movl $(GDT_ENTRY_TSS*8), %edx
43691 ltr %dx
43692
43693@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43694 // Let's clear it again for our return.
43695 // The GDT descriptor of the Host
43696 // Points to the table after two "size" bytes
43697- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43698+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43699 // Clear "used" from type field (byte 5, bit 2)
43700- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43701+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43702+
43703+#ifdef CONFIG_PAX_KERNEXEC
43704+ mov %cr0, %eax
43705+ xor $X86_CR0_WP, %eax
43706+ mov %eax, %cr0
43707+#endif
43708
43709 // Once our page table's switched, the Guest is live!
43710 // The Host fades as we run this final step.
43711@@ -295,13 +309,12 @@ deliver_to_host:
43712 // I consulted gcc, and it gave
43713 // These instructions, which I gladly credit:
43714 leal (%edx,%ebx,8), %eax
43715- movzwl (%eax),%edx
43716- movl 4(%eax), %eax
43717- xorw %ax, %ax
43718- orl %eax, %edx
43719+ movl 4(%eax), %edx
43720+ movw (%eax), %dx
43721 // Now the address of the handler's in %edx
43722 // We call it now: its "iret" drops us home.
43723- jmp *%edx
43724+ ljmp $__KERNEL_CS, $1f
43725+1: jmp *%edx
43726
43727 // Every interrupt can come to us here
43728 // But we must truly tell each apart.
43729diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43730index 7ef7461..5a09dac 100644
43731--- a/drivers/md/bcache/closure.h
43732+++ b/drivers/md/bcache/closure.h
43733@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43734 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43735 struct workqueue_struct *wq)
43736 {
43737- BUG_ON(object_is_on_stack(cl));
43738+ BUG_ON(object_starts_on_stack(cl));
43739 closure_set_ip(cl);
43740 cl->fn = fn;
43741 cl->wq = wq;
43742diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43743index 4195a01..42527ac 100644
43744--- a/drivers/md/bitmap.c
43745+++ b/drivers/md/bitmap.c
43746@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43747 chunk_kb ? "KB" : "B");
43748 if (bitmap->storage.file) {
43749 seq_printf(seq, ", file: ");
43750- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43751+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43752 }
43753
43754 seq_printf(seq, "\n");
43755diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43756index 5152142..623d141 100644
43757--- a/drivers/md/dm-ioctl.c
43758+++ b/drivers/md/dm-ioctl.c
43759@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43760 cmd == DM_LIST_VERSIONS_CMD)
43761 return 0;
43762
43763- if ((cmd == DM_DEV_CREATE_CMD)) {
43764+ if (cmd == DM_DEV_CREATE_CMD) {
43765 if (!*param->name) {
43766 DMWARN("name not supplied when creating device");
43767 return -EINVAL;
43768diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43769index 7dfdb5c..4caada6 100644
43770--- a/drivers/md/dm-raid1.c
43771+++ b/drivers/md/dm-raid1.c
43772@@ -40,7 +40,7 @@ enum dm_raid1_error {
43773
43774 struct mirror {
43775 struct mirror_set *ms;
43776- atomic_t error_count;
43777+ atomic_unchecked_t error_count;
43778 unsigned long error_type;
43779 struct dm_dev *dev;
43780 sector_t offset;
43781@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43782 struct mirror *m;
43783
43784 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43785- if (!atomic_read(&m->error_count))
43786+ if (!atomic_read_unchecked(&m->error_count))
43787 return m;
43788
43789 return NULL;
43790@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43791 * simple way to tell if a device has encountered
43792 * errors.
43793 */
43794- atomic_inc(&m->error_count);
43795+ atomic_inc_unchecked(&m->error_count);
43796
43797 if (test_and_set_bit(error_type, &m->error_type))
43798 return;
43799@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43800 struct mirror *m = get_default_mirror(ms);
43801
43802 do {
43803- if (likely(!atomic_read(&m->error_count)))
43804+ if (likely(!atomic_read_unchecked(&m->error_count)))
43805 return m;
43806
43807 if (m-- == ms->mirror)
43808@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43809 {
43810 struct mirror *default_mirror = get_default_mirror(m->ms);
43811
43812- return !atomic_read(&default_mirror->error_count);
43813+ return !atomic_read_unchecked(&default_mirror->error_count);
43814 }
43815
43816 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43817@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43818 */
43819 if (likely(region_in_sync(ms, region, 1)))
43820 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43821- else if (m && atomic_read(&m->error_count))
43822+ else if (m && atomic_read_unchecked(&m->error_count))
43823 m = NULL;
43824
43825 if (likely(m))
43826@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43827 }
43828
43829 ms->mirror[mirror].ms = ms;
43830- atomic_set(&(ms->mirror[mirror].error_count), 0);
43831+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43832 ms->mirror[mirror].error_type = 0;
43833 ms->mirror[mirror].offset = offset;
43834
43835@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43836 */
43837 static char device_status_char(struct mirror *m)
43838 {
43839- if (!atomic_read(&(m->error_count)))
43840+ if (!atomic_read_unchecked(&(m->error_count)))
43841 return 'A';
43842
43843 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43844diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43845index 28a9012..9c0f6a5 100644
43846--- a/drivers/md/dm-stats.c
43847+++ b/drivers/md/dm-stats.c
43848@@ -382,7 +382,7 @@ do_sync_free:
43849 synchronize_rcu_expedited();
43850 dm_stat_free(&s->rcu_head);
43851 } else {
43852- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43853+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43854 call_rcu(&s->rcu_head, dm_stat_free);
43855 }
43856 return 0;
43857@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43858 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43859 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43860 ));
43861- ACCESS_ONCE(last->last_sector) = end_sector;
43862- ACCESS_ONCE(last->last_rw) = bi_rw;
43863+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43864+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43865 }
43866
43867 rcu_read_lock();
43868diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43869index d1600d2..4c3af3a 100644
43870--- a/drivers/md/dm-stripe.c
43871+++ b/drivers/md/dm-stripe.c
43872@@ -21,7 +21,7 @@ struct stripe {
43873 struct dm_dev *dev;
43874 sector_t physical_start;
43875
43876- atomic_t error_count;
43877+ atomic_unchecked_t error_count;
43878 };
43879
43880 struct stripe_c {
43881@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43882 kfree(sc);
43883 return r;
43884 }
43885- atomic_set(&(sc->stripe[i].error_count), 0);
43886+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43887 }
43888
43889 ti->private = sc;
43890@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43891 DMEMIT("%d ", sc->stripes);
43892 for (i = 0; i < sc->stripes; i++) {
43893 DMEMIT("%s ", sc->stripe[i].dev->name);
43894- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43895+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43896 'D' : 'A';
43897 }
43898 buffer[i] = '\0';
43899@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43900 */
43901 for (i = 0; i < sc->stripes; i++)
43902 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43903- atomic_inc(&(sc->stripe[i].error_count));
43904- if (atomic_read(&(sc->stripe[i].error_count)) <
43905+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43906+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43907 DM_IO_ERROR_THRESHOLD)
43908 schedule_work(&sc->trigger_event);
43909 }
43910diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43911index 6a7f2b8..fea0bde 100644
43912--- a/drivers/md/dm-table.c
43913+++ b/drivers/md/dm-table.c
43914@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43915 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43916 struct mapped_device *md)
43917 {
43918- static char *_claim_ptr = "I belong to device-mapper";
43919+ static char _claim_ptr[] = "I belong to device-mapper";
43920 struct block_device *bdev;
43921
43922 int r;
43923@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43924 if (!dev_size)
43925 return 0;
43926
43927- if ((start >= dev_size) || (start + len > dev_size)) {
43928+ if ((start >= dev_size) || (len > dev_size - start)) {
43929 DMWARN("%s: %s too small for target: "
43930 "start=%llu, len=%llu, dev_size=%llu",
43931 dm_device_name(ti->table->md), bdevname(bdev, b),
43932diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43933index fb9efc8..81e8986 100644
43934--- a/drivers/md/dm-thin-metadata.c
43935+++ b/drivers/md/dm-thin-metadata.c
43936@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43937 {
43938 pmd->info.tm = pmd->tm;
43939 pmd->info.levels = 2;
43940- pmd->info.value_type.context = pmd->data_sm;
43941+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43942 pmd->info.value_type.size = sizeof(__le64);
43943 pmd->info.value_type.inc = data_block_inc;
43944 pmd->info.value_type.dec = data_block_dec;
43945@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43946
43947 pmd->bl_info.tm = pmd->tm;
43948 pmd->bl_info.levels = 1;
43949- pmd->bl_info.value_type.context = pmd->data_sm;
43950+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43951 pmd->bl_info.value_type.size = sizeof(__le64);
43952 pmd->bl_info.value_type.inc = data_block_inc;
43953 pmd->bl_info.value_type.dec = data_block_dec;
43954diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43955index 8c53b09..f1fb2b0 100644
43956--- a/drivers/md/dm.c
43957+++ b/drivers/md/dm.c
43958@@ -185,9 +185,9 @@ struct mapped_device {
43959 /*
43960 * Event handling.
43961 */
43962- atomic_t event_nr;
43963+ atomic_unchecked_t event_nr;
43964 wait_queue_head_t eventq;
43965- atomic_t uevent_seq;
43966+ atomic_unchecked_t uevent_seq;
43967 struct list_head uevent_list;
43968 spinlock_t uevent_lock; /* Protect access to uevent_list */
43969
43970@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
43971 spin_lock_init(&md->deferred_lock);
43972 atomic_set(&md->holders, 1);
43973 atomic_set(&md->open_count, 0);
43974- atomic_set(&md->event_nr, 0);
43975- atomic_set(&md->uevent_seq, 0);
43976+ atomic_set_unchecked(&md->event_nr, 0);
43977+ atomic_set_unchecked(&md->uevent_seq, 0);
43978 INIT_LIST_HEAD(&md->uevent_list);
43979 spin_lock_init(&md->uevent_lock);
43980
43981@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
43982
43983 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43984
43985- atomic_inc(&md->event_nr);
43986+ atomic_inc_unchecked(&md->event_nr);
43987 wake_up(&md->eventq);
43988 }
43989
43990@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43991
43992 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43993 {
43994- return atomic_add_return(1, &md->uevent_seq);
43995+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43996 }
43997
43998 uint32_t dm_get_event_nr(struct mapped_device *md)
43999 {
44000- return atomic_read(&md->event_nr);
44001+ return atomic_read_unchecked(&md->event_nr);
44002 }
44003
44004 int dm_wait_event(struct mapped_device *md, int event_nr)
44005 {
44006 return wait_event_interruptible(md->eventq,
44007- (event_nr != atomic_read(&md->event_nr)));
44008+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44009 }
44010
44011 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44012diff --git a/drivers/md/md.c b/drivers/md/md.c
44013index 4ad5cc4..0f19664 100644
44014--- a/drivers/md/md.c
44015+++ b/drivers/md/md.c
44016@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44017 * start build, activate spare
44018 */
44019 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44020-static atomic_t md_event_count;
44021+static atomic_unchecked_t md_event_count;
44022 void md_new_event(struct mddev *mddev)
44023 {
44024- atomic_inc(&md_event_count);
44025+ atomic_inc_unchecked(&md_event_count);
44026 wake_up(&md_event_waiters);
44027 }
44028 EXPORT_SYMBOL_GPL(md_new_event);
44029@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44030 */
44031 static void md_new_event_inintr(struct mddev *mddev)
44032 {
44033- atomic_inc(&md_event_count);
44034+ atomic_inc_unchecked(&md_event_count);
44035 wake_up(&md_event_waiters);
44036 }
44037
44038@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44039 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44040 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44041 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44042- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44043+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44044
44045 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44046 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44047@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44048 else
44049 sb->resync_offset = cpu_to_le64(0);
44050
44051- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44052+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44053
44054 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44055 sb->size = cpu_to_le64(mddev->dev_sectors);
44056@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44057 static ssize_t
44058 errors_show(struct md_rdev *rdev, char *page)
44059 {
44060- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44061+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44062 }
44063
44064 static ssize_t
44065@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44066 char *e;
44067 unsigned long n = simple_strtoul(buf, &e, 10);
44068 if (*buf && (*e == 0 || *e == '\n')) {
44069- atomic_set(&rdev->corrected_errors, n);
44070+ atomic_set_unchecked(&rdev->corrected_errors, n);
44071 return len;
44072 }
44073 return -EINVAL;
44074@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44075 rdev->sb_loaded = 0;
44076 rdev->bb_page = NULL;
44077 atomic_set(&rdev->nr_pending, 0);
44078- atomic_set(&rdev->read_errors, 0);
44079- atomic_set(&rdev->corrected_errors, 0);
44080+ atomic_set_unchecked(&rdev->read_errors, 0);
44081+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44082
44083 INIT_LIST_HEAD(&rdev->same_set);
44084 init_waitqueue_head(&rdev->blocked_wait);
44085@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44086
44087 spin_unlock(&pers_lock);
44088 seq_printf(seq, "\n");
44089- seq->poll_event = atomic_read(&md_event_count);
44090+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44091 return 0;
44092 }
44093 if (v == (void*)2) {
44094@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44095 return error;
44096
44097 seq = file->private_data;
44098- seq->poll_event = atomic_read(&md_event_count);
44099+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44100 return error;
44101 }
44102
44103@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44104 /* always allow read */
44105 mask = POLLIN | POLLRDNORM;
44106
44107- if (seq->poll_event != atomic_read(&md_event_count))
44108+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44109 mask |= POLLERR | POLLPRI;
44110 return mask;
44111 }
44112@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44113 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44114 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44115 (int)part_stat_read(&disk->part0, sectors[1]) -
44116- atomic_read(&disk->sync_io);
44117+ atomic_read_unchecked(&disk->sync_io);
44118 /* sync IO will cause sync_io to increase before the disk_stats
44119 * as sync_io is counted when a request starts, and
44120 * disk_stats is counted when it completes.
44121diff --git a/drivers/md/md.h b/drivers/md/md.h
44122index 07bba96..2d6788c 100644
44123--- a/drivers/md/md.h
44124+++ b/drivers/md/md.h
44125@@ -94,13 +94,13 @@ struct md_rdev {
44126 * only maintained for arrays that
44127 * support hot removal
44128 */
44129- atomic_t read_errors; /* number of consecutive read errors that
44130+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44131 * we have tried to ignore.
44132 */
44133 struct timespec last_read_error; /* monotonic time since our
44134 * last read error
44135 */
44136- atomic_t corrected_errors; /* number of corrected read errors,
44137+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44138 * for reporting to userspace and storing
44139 * in superblock.
44140 */
44141@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44142
44143 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44144 {
44145- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44146+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44147 }
44148
44149 struct md_personality
44150diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44151index 786b689..ea8c956 100644
44152--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44153+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44154@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44155 * Flick into a mode where all blocks get allocated in the new area.
44156 */
44157 smm->begin = old_len;
44158- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44159+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44160
44161 /*
44162 * Extend.
44163@@ -710,7 +710,7 @@ out:
44164 /*
44165 * Switch back to normal behaviour.
44166 */
44167- memcpy(sm, &ops, sizeof(*sm));
44168+ memcpy((void *)sm, &ops, sizeof(*sm));
44169 return r;
44170 }
44171
44172diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44173index 3e6d115..ffecdeb 100644
44174--- a/drivers/md/persistent-data/dm-space-map.h
44175+++ b/drivers/md/persistent-data/dm-space-map.h
44176@@ -71,6 +71,7 @@ struct dm_space_map {
44177 dm_sm_threshold_fn fn,
44178 void *context);
44179 };
44180+typedef struct dm_space_map __no_const dm_space_map_no_const;
44181
44182 /*----------------------------------------------------------------*/
44183
44184diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44185index 4a6ca1c..e952750 100644
44186--- a/drivers/md/raid1.c
44187+++ b/drivers/md/raid1.c
44188@@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44189 if (r1_sync_page_io(rdev, sect, s,
44190 bio->bi_io_vec[idx].bv_page,
44191 READ) != 0)
44192- atomic_add(s, &rdev->corrected_errors);
44193+ atomic_add_unchecked(s, &rdev->corrected_errors);
44194 }
44195 sectors -= s;
44196 sect += s;
44197@@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44198 test_bit(In_sync, &rdev->flags)) {
44199 if (r1_sync_page_io(rdev, sect, s,
44200 conf->tmppage, READ)) {
44201- atomic_add(s, &rdev->corrected_errors);
44202+ atomic_add_unchecked(s, &rdev->corrected_errors);
44203 printk(KERN_INFO
44204 "md/raid1:%s: read error corrected "
44205 "(%d sectors at %llu on %s)\n",
44206diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44207index 33fc408..fc61709 100644
44208--- a/drivers/md/raid10.c
44209+++ b/drivers/md/raid10.c
44210@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44211 /* The write handler will notice the lack of
44212 * R10BIO_Uptodate and record any errors etc
44213 */
44214- atomic_add(r10_bio->sectors,
44215+ atomic_add_unchecked(r10_bio->sectors,
44216 &conf->mirrors[d].rdev->corrected_errors);
44217
44218 /* for reconstruct, we always reschedule after a read.
44219@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44220 {
44221 struct timespec cur_time_mon;
44222 unsigned long hours_since_last;
44223- unsigned int read_errors = atomic_read(&rdev->read_errors);
44224+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44225
44226 ktime_get_ts(&cur_time_mon);
44227
44228@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44229 * overflowing the shift of read_errors by hours_since_last.
44230 */
44231 if (hours_since_last >= 8 * sizeof(read_errors))
44232- atomic_set(&rdev->read_errors, 0);
44233+ atomic_set_unchecked(&rdev->read_errors, 0);
44234 else
44235- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44236+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44237 }
44238
44239 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44240@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44241 return;
44242
44243 check_decay_read_errors(mddev, rdev);
44244- atomic_inc(&rdev->read_errors);
44245- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44246+ atomic_inc_unchecked(&rdev->read_errors);
44247+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44248 char b[BDEVNAME_SIZE];
44249 bdevname(rdev->bdev, b);
44250
44251@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44252 "md/raid10:%s: %s: Raid device exceeded "
44253 "read_error threshold [cur %d:max %d]\n",
44254 mdname(mddev), b,
44255- atomic_read(&rdev->read_errors), max_read_errors);
44256+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44257 printk(KERN_NOTICE
44258 "md/raid10:%s: %s: Failing raid device\n",
44259 mdname(mddev), b);
44260@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44261 sect +
44262 choose_data_offset(r10_bio, rdev)),
44263 bdevname(rdev->bdev, b));
44264- atomic_add(s, &rdev->corrected_errors);
44265+ atomic_add_unchecked(s, &rdev->corrected_errors);
44266 }
44267
44268 rdev_dec_pending(rdev, mddev);
44269diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44270index 16f5c21..4df20dc 100644
44271--- a/drivers/md/raid5.c
44272+++ b/drivers/md/raid5.c
44273@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44274 mdname(conf->mddev), STRIPE_SECTORS,
44275 (unsigned long long)s,
44276 bdevname(rdev->bdev, b));
44277- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44278+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44279 clear_bit(R5_ReadError, &sh->dev[i].flags);
44280 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44281 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44282 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44283
44284- if (atomic_read(&rdev->read_errors))
44285- atomic_set(&rdev->read_errors, 0);
44286+ if (atomic_read_unchecked(&rdev->read_errors))
44287+ atomic_set_unchecked(&rdev->read_errors, 0);
44288 } else {
44289 const char *bdn = bdevname(rdev->bdev, b);
44290 int retry = 0;
44291 int set_bad = 0;
44292
44293 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44294- atomic_inc(&rdev->read_errors);
44295+ atomic_inc_unchecked(&rdev->read_errors);
44296 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44297 printk_ratelimited(
44298 KERN_WARNING
44299@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44300 mdname(conf->mddev),
44301 (unsigned long long)s,
44302 bdn);
44303- } else if (atomic_read(&rdev->read_errors)
44304+ } else if (atomic_read_unchecked(&rdev->read_errors)
44305 > conf->max_nr_stripes)
44306 printk(KERN_WARNING
44307 "md/raid:%s: Too many read errors, failing device %s.\n",
44308diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44309index 983db75..ef9248c 100644
44310--- a/drivers/media/dvb-core/dvbdev.c
44311+++ b/drivers/media/dvb-core/dvbdev.c
44312@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44313 const struct dvb_device *template, void *priv, int type)
44314 {
44315 struct dvb_device *dvbdev;
44316- struct file_operations *dvbdevfops;
44317+ file_operations_no_const *dvbdevfops;
44318 struct device *clsdev;
44319 int minor;
44320 int id;
44321diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44322index 9b6c3bb..baeb5c7 100644
44323--- a/drivers/media/dvb-frontends/dib3000.h
44324+++ b/drivers/media/dvb-frontends/dib3000.h
44325@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44326 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44327 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44328 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44329-};
44330+} __no_const;
44331
44332 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44333 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44334diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44335index d5a7a13..703560f 100644
44336--- a/drivers/media/media-device.c
44337+++ b/drivers/media/media-device.c
44338@@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44339 struct media_entity *ent;
44340 struct media_entity_desc u_ent;
44341
44342+ memset(&u_ent, 0, sizeof(u_ent));
44343 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44344 return -EFAULT;
44345
44346diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44347index ed8cb90..5ef7f79 100644
44348--- a/drivers/media/pci/cx88/cx88-video.c
44349+++ b/drivers/media/pci/cx88/cx88-video.c
44350@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44351
44352 /* ------------------------------------------------------------------ */
44353
44354-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44355-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44356-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44357+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44358+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44359+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44360
44361 module_param_array(video_nr, int, NULL, 0444);
44362 module_param_array(vbi_nr, int, NULL, 0444);
44363diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44364index 802642d..5534900 100644
44365--- a/drivers/media/pci/ivtv/ivtv-driver.c
44366+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44367@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44368 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44369
44370 /* ivtv instance counter */
44371-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44372+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44373
44374 /* Parameter declarations */
44375 static int cardtype[IVTV_MAX_CARDS];
44376diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44377index dfd0a21..6bbb465 100644
44378--- a/drivers/media/platform/omap/omap_vout.c
44379+++ b/drivers/media/platform/omap/omap_vout.c
44380@@ -63,7 +63,6 @@ enum omap_vout_channels {
44381 OMAP_VIDEO2,
44382 };
44383
44384-static struct videobuf_queue_ops video_vbq_ops;
44385 /* Variables configurable through module params*/
44386 static u32 video1_numbuffers = 3;
44387 static u32 video2_numbuffers = 3;
44388@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44389 {
44390 struct videobuf_queue *q;
44391 struct omap_vout_device *vout = NULL;
44392+ static struct videobuf_queue_ops video_vbq_ops = {
44393+ .buf_setup = omap_vout_buffer_setup,
44394+ .buf_prepare = omap_vout_buffer_prepare,
44395+ .buf_release = omap_vout_buffer_release,
44396+ .buf_queue = omap_vout_buffer_queue,
44397+ };
44398
44399 vout = video_drvdata(file);
44400 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44401@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44402 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44403
44404 q = &vout->vbq;
44405- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44406- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44407- video_vbq_ops.buf_release = omap_vout_buffer_release;
44408- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44409 spin_lock_init(&vout->vbq_lock);
44410
44411 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44412diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44413index fb2acc5..a2fcbdc4 100644
44414--- a/drivers/media/platform/s5p-tv/mixer.h
44415+++ b/drivers/media/platform/s5p-tv/mixer.h
44416@@ -156,7 +156,7 @@ struct mxr_layer {
44417 /** layer index (unique identifier) */
44418 int idx;
44419 /** callbacks for layer methods */
44420- struct mxr_layer_ops ops;
44421+ struct mxr_layer_ops *ops;
44422 /** format array */
44423 const struct mxr_format **fmt_array;
44424 /** size of format array */
44425diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44426index 74344c7..a39e70e 100644
44427--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44428+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44429@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44430 {
44431 struct mxr_layer *layer;
44432 int ret;
44433- struct mxr_layer_ops ops = {
44434+ static struct mxr_layer_ops ops = {
44435 .release = mxr_graph_layer_release,
44436 .buffer_set = mxr_graph_buffer_set,
44437 .stream_set = mxr_graph_stream_set,
44438diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44439index b713403..53cb5ad 100644
44440--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44441+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44442@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44443 layer->update_buf = next;
44444 }
44445
44446- layer->ops.buffer_set(layer, layer->update_buf);
44447+ layer->ops->buffer_set(layer, layer->update_buf);
44448
44449 if (done && done != layer->shadow_buf)
44450 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44451diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44452index c5059ba..2649f28 100644
44453--- a/drivers/media/platform/s5p-tv/mixer_video.c
44454+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44455@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44456 layer->geo.src.height = layer->geo.src.full_height;
44457
44458 mxr_geometry_dump(mdev, &layer->geo);
44459- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44460+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44461 mxr_geometry_dump(mdev, &layer->geo);
44462 }
44463
44464@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44465 layer->geo.dst.full_width = mbus_fmt.width;
44466 layer->geo.dst.full_height = mbus_fmt.height;
44467 layer->geo.dst.field = mbus_fmt.field;
44468- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44469+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44470
44471 mxr_geometry_dump(mdev, &layer->geo);
44472 }
44473@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44474 /* set source size to highest accepted value */
44475 geo->src.full_width = max(geo->dst.full_width, pix->width);
44476 geo->src.full_height = max(geo->dst.full_height, pix->height);
44477- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44478+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44479 mxr_geometry_dump(mdev, &layer->geo);
44480 /* set cropping to total visible screen */
44481 geo->src.width = pix->width;
44482@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44483 geo->src.x_offset = 0;
44484 geo->src.y_offset = 0;
44485 /* assure consistency of geometry */
44486- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44487+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44488 mxr_geometry_dump(mdev, &layer->geo);
44489 /* set full size to lowest possible value */
44490 geo->src.full_width = 0;
44491 geo->src.full_height = 0;
44492- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44493+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44494 mxr_geometry_dump(mdev, &layer->geo);
44495
44496 /* returning results */
44497@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44498 target->width = s->r.width;
44499 target->height = s->r.height;
44500
44501- layer->ops.fix_geometry(layer, stage, s->flags);
44502+ layer->ops->fix_geometry(layer, stage, s->flags);
44503
44504 /* retrieve update selection rectangle */
44505 res.left = target->x_offset;
44506@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44507 mxr_output_get(mdev);
44508
44509 mxr_layer_update_output(layer);
44510- layer->ops.format_set(layer);
44511+ layer->ops->format_set(layer);
44512 /* enabling layer in hardware */
44513 spin_lock_irqsave(&layer->enq_slock, flags);
44514 layer->state = MXR_LAYER_STREAMING;
44515 spin_unlock_irqrestore(&layer->enq_slock, flags);
44516
44517- layer->ops.stream_set(layer, MXR_ENABLE);
44518+ layer->ops->stream_set(layer, MXR_ENABLE);
44519 mxr_streamer_get(mdev);
44520
44521 return 0;
44522@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44523 spin_unlock_irqrestore(&layer->enq_slock, flags);
44524
44525 /* disabling layer in hardware */
44526- layer->ops.stream_set(layer, MXR_DISABLE);
44527+ layer->ops->stream_set(layer, MXR_DISABLE);
44528 /* remove one streamer */
44529 mxr_streamer_put(mdev);
44530 /* allow changes in output configuration */
44531@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44532
44533 void mxr_layer_release(struct mxr_layer *layer)
44534 {
44535- if (layer->ops.release)
44536- layer->ops.release(layer);
44537+ if (layer->ops->release)
44538+ layer->ops->release(layer);
44539 }
44540
44541 void mxr_base_layer_release(struct mxr_layer *layer)
44542@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44543
44544 layer->mdev = mdev;
44545 layer->idx = idx;
44546- layer->ops = *ops;
44547+ layer->ops = ops;
44548
44549 spin_lock_init(&layer->enq_slock);
44550 INIT_LIST_HEAD(&layer->enq_list);
44551diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44552index c9388c4..ce71ece 100644
44553--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44554+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44555@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44556 {
44557 struct mxr_layer *layer;
44558 int ret;
44559- struct mxr_layer_ops ops = {
44560+ static struct mxr_layer_ops ops = {
44561 .release = mxr_vp_layer_release,
44562 .buffer_set = mxr_vp_buffer_set,
44563 .stream_set = mxr_vp_stream_set,
44564diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44565index 2d4e73b..8b4d5b6 100644
44566--- a/drivers/media/platform/vivi.c
44567+++ b/drivers/media/platform/vivi.c
44568@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44569 MODULE_LICENSE("Dual BSD/GPL");
44570 MODULE_VERSION(VIVI_VERSION);
44571
44572-static unsigned video_nr = -1;
44573-module_param(video_nr, uint, 0644);
44574+static int video_nr = -1;
44575+module_param(video_nr, int, 0644);
44576 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44577
44578 static unsigned n_devs = 1;
44579diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44580index 545c04c..a14bded 100644
44581--- a/drivers/media/radio/radio-cadet.c
44582+++ b/drivers/media/radio/radio-cadet.c
44583@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44584 unsigned char readbuf[RDS_BUFFER];
44585 int i = 0;
44586
44587+ if (count > RDS_BUFFER)
44588+ return -EFAULT;
44589 mutex_lock(&dev->lock);
44590 if (dev->rdsstat == 0)
44591 cadet_start_rds(dev);
44592@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44593 while (i < count && dev->rdsin != dev->rdsout)
44594 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44595
44596- if (i && copy_to_user(data, readbuf, i))
44597+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44598 i = -EFAULT;
44599 unlock:
44600 mutex_unlock(&dev->lock);
44601diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44602index 5236035..c622c74 100644
44603--- a/drivers/media/radio/radio-maxiradio.c
44604+++ b/drivers/media/radio/radio-maxiradio.c
44605@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44606 /* TEA5757 pin mappings */
44607 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44608
44609-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44610+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44611
44612 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44613 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44614diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44615index 050b3bb..79f62b9 100644
44616--- a/drivers/media/radio/radio-shark.c
44617+++ b/drivers/media/radio/radio-shark.c
44618@@ -79,7 +79,7 @@ struct shark_device {
44619 u32 last_val;
44620 };
44621
44622-static atomic_t shark_instance = ATOMIC_INIT(0);
44623+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44624
44625 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44626 {
44627diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44628index 8654e0d..0608a64 100644
44629--- a/drivers/media/radio/radio-shark2.c
44630+++ b/drivers/media/radio/radio-shark2.c
44631@@ -74,7 +74,7 @@ struct shark_device {
44632 u8 *transfer_buffer;
44633 };
44634
44635-static atomic_t shark_instance = ATOMIC_INIT(0);
44636+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44637
44638 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44639 {
44640diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44641index 2fd9009..278cc1e 100644
44642--- a/drivers/media/radio/radio-si476x.c
44643+++ b/drivers/media/radio/radio-si476x.c
44644@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44645 struct si476x_radio *radio;
44646 struct v4l2_ctrl *ctrl;
44647
44648- static atomic_t instance = ATOMIC_INIT(0);
44649+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44650
44651 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44652 if (!radio)
44653diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44654index a1c641e..3007da9 100644
44655--- a/drivers/media/usb/dvb-usb/cxusb.c
44656+++ b/drivers/media/usb/dvb-usb/cxusb.c
44657@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44658
44659 struct dib0700_adapter_state {
44660 int (*set_param_save) (struct dvb_frontend *);
44661-};
44662+} __no_const;
44663
44664 static int dib7070_set_param_override(struct dvb_frontend *fe)
44665 {
44666diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44667index ae0f56a..ec71784 100644
44668--- a/drivers/media/usb/dvb-usb/dw2102.c
44669+++ b/drivers/media/usb/dvb-usb/dw2102.c
44670@@ -118,7 +118,7 @@ struct su3000_state {
44671
44672 struct s6x0_state {
44673 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44674-};
44675+} __no_const;
44676
44677 /* debug */
44678 static int dvb_usb_dw2102_debug;
44679diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44680index b63a5e5..b16a062 100644
44681--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44682+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44683@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44684 __u32 reserved;
44685 };
44686
44687-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44688+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44689 enum v4l2_memory memory)
44690 {
44691 void __user *up_pln;
44692@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44693 return 0;
44694 }
44695
44696-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44697+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44698 enum v4l2_memory memory)
44699 {
44700 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44701@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44702 * by passing a very big num_planes value */
44703 uplane = compat_alloc_user_space(num_planes *
44704 sizeof(struct v4l2_plane));
44705- kp->m.planes = uplane;
44706+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44707
44708 while (--num_planes >= 0) {
44709 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44710@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44711 if (num_planes == 0)
44712 return 0;
44713
44714- uplane = kp->m.planes;
44715+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44716 if (get_user(p, &up->m.planes))
44717 return -EFAULT;
44718 uplane32 = compat_ptr(p);
44719@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44720 get_user(kp->capability, &up->capability) ||
44721 get_user(kp->flags, &up->flags))
44722 return -EFAULT;
44723- kp->base = compat_ptr(tmp);
44724+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44725 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44726 return 0;
44727 }
44728@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44729 n * sizeof(struct v4l2_ext_control32)))
44730 return -EFAULT;
44731 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44732- kp->controls = kcontrols;
44733+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44734 while (--n >= 0) {
44735 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44736 return -EFAULT;
44737@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44738 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44739 {
44740 struct v4l2_ext_control32 __user *ucontrols;
44741- struct v4l2_ext_control __user *kcontrols = kp->controls;
44742+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44743 int n = kp->count;
44744 compat_caddr_t p;
44745
44746@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44747 put_user(kp->start_block, &up->start_block) ||
44748 put_user(kp->blocks, &up->blocks) ||
44749 put_user(tmp, &up->edid) ||
44750- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44751+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44752 return -EFAULT;
44753 return 0;
44754 }
44755diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44756index 6ff002b..6b9316b 100644
44757--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44758+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44759@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44760 return 0;
44761
44762 case V4L2_CTRL_TYPE_STRING:
44763- len = strlen(c->string);
44764- if (len < ctrl->minimum)
44765+ len = strlen_user(c->string);
44766+ if (!len || len < ctrl->minimum)
44767 return -ERANGE;
44768 if ((len - ctrl->minimum) % ctrl->step)
44769 return -ERANGE;
44770diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44771index 02d1b63..5fd6b16 100644
44772--- a/drivers/media/v4l2-core/v4l2-device.c
44773+++ b/drivers/media/v4l2-core/v4l2-device.c
44774@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44775 EXPORT_SYMBOL_GPL(v4l2_device_put);
44776
44777 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44778- atomic_t *instance)
44779+ atomic_unchecked_t *instance)
44780 {
44781- int num = atomic_inc_return(instance) - 1;
44782+ int num = atomic_inc_return_unchecked(instance) - 1;
44783 int len = strlen(basename);
44784
44785 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44786diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44787index 707aef7..93b8ac0 100644
44788--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44789+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44790@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
44791 struct file *file, void *fh, void *p);
44792 } u;
44793 void (*debug)(const void *arg, bool write_only);
44794-};
44795+} __do_const;
44796+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44797
44798 /* This control needs a priority check */
44799 #define INFO_FL_PRIO (1 << 0)
44800@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
44801 struct video_device *vfd = video_devdata(file);
44802 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44803 bool write_only = false;
44804- struct v4l2_ioctl_info default_info;
44805+ v4l2_ioctl_info_no_const default_info;
44806 const struct v4l2_ioctl_info *info;
44807 void *fh = file->private_data;
44808 struct v4l2_fh *vfh = NULL;
44809@@ -2197,7 +2198,7 @@ done:
44810 }
44811
44812 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44813- void * __user *user_ptr, void ***kernel_ptr)
44814+ void __user **user_ptr, void ***kernel_ptr)
44815 {
44816 int ret = 0;
44817
44818@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44819 ret = -EINVAL;
44820 break;
44821 }
44822- *user_ptr = (void __user *)buf->m.planes;
44823+ *user_ptr = (void __force_user *)buf->m.planes;
44824 *kernel_ptr = (void *)&buf->m.planes;
44825 *array_size = sizeof(struct v4l2_plane) * buf->length;
44826 ret = 1;
44827@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44828 ret = -EINVAL;
44829 break;
44830 }
44831- *user_ptr = (void __user *)ctrls->controls;
44832+ *user_ptr = (void __force_user *)ctrls->controls;
44833 *kernel_ptr = (void *)&ctrls->controls;
44834 *array_size = sizeof(struct v4l2_ext_control)
44835 * ctrls->count;
44836@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44837 }
44838
44839 if (has_array_args) {
44840- *kernel_ptr = user_ptr;
44841+ *kernel_ptr = (void __force_kernel *)user_ptr;
44842 if (copy_to_user(user_ptr, mbuf, array_size))
44843 err = -EFAULT;
44844 goto out_array_args;
44845diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44846index 570b18a..f880314 100644
44847--- a/drivers/message/fusion/mptbase.c
44848+++ b/drivers/message/fusion/mptbase.c
44849@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44850 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44851 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44852
44853+#ifdef CONFIG_GRKERNSEC_HIDESYM
44854+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44855+#else
44856 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44857 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44858+#endif
44859+
44860 /*
44861 * Rounding UP to nearest 4-kB boundary here...
44862 */
44863@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44864 ioc->facts.GlobalCredits);
44865
44866 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44867+#ifdef CONFIG_GRKERNSEC_HIDESYM
44868+ NULL, NULL);
44869+#else
44870 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44871+#endif
44872 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44873 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44874 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44875diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44876index 00d339c..2ea899d 100644
44877--- a/drivers/message/fusion/mptsas.c
44878+++ b/drivers/message/fusion/mptsas.c
44879@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44880 return 0;
44881 }
44882
44883+static inline void
44884+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44885+{
44886+ if (phy_info->port_details) {
44887+ phy_info->port_details->rphy = rphy;
44888+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44889+ ioc->name, rphy));
44890+ }
44891+
44892+ if (rphy) {
44893+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44894+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44895+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44896+ ioc->name, rphy, rphy->dev.release));
44897+ }
44898+}
44899+
44900 /* no mutex */
44901 static void
44902 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44903@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44904 return NULL;
44905 }
44906
44907-static inline void
44908-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44909-{
44910- if (phy_info->port_details) {
44911- phy_info->port_details->rphy = rphy;
44912- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44913- ioc->name, rphy));
44914- }
44915-
44916- if (rphy) {
44917- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44918- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44919- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44920- ioc->name, rphy, rphy->dev.release));
44921- }
44922-}
44923-
44924 static inline struct sas_port *
44925 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44926 {
44927diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44928index 727819c..ad74694 100644
44929--- a/drivers/message/fusion/mptscsih.c
44930+++ b/drivers/message/fusion/mptscsih.c
44931@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44932
44933 h = shost_priv(SChost);
44934
44935- if (h) {
44936- if (h->info_kbuf == NULL)
44937- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44938- return h->info_kbuf;
44939- h->info_kbuf[0] = '\0';
44940+ if (!h)
44941+ return NULL;
44942
44943- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44944- h->info_kbuf[size-1] = '\0';
44945- }
44946+ if (h->info_kbuf == NULL)
44947+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44948+ return h->info_kbuf;
44949+ h->info_kbuf[0] = '\0';
44950+
44951+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44952+ h->info_kbuf[size-1] = '\0';
44953
44954 return h->info_kbuf;
44955 }
44956diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44957index b7d87cd..3fb36da 100644
44958--- a/drivers/message/i2o/i2o_proc.c
44959+++ b/drivers/message/i2o/i2o_proc.c
44960@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44961 "Array Controller Device"
44962 };
44963
44964-static char *chtostr(char *tmp, u8 *chars, int n)
44965-{
44966- tmp[0] = 0;
44967- return strncat(tmp, (char *)chars, n);
44968-}
44969-
44970 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44971 char *group)
44972 {
44973@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44974 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44975 {
44976 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44977- static u32 work32[5];
44978- static u8 *work8 = (u8 *) work32;
44979- static u16 *work16 = (u16 *) work32;
44980+ u32 work32[5];
44981+ u8 *work8 = (u8 *) work32;
44982+ u16 *work16 = (u16 *) work32;
44983 int token;
44984 u32 hwcap;
44985
44986@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44987 } *result;
44988
44989 i2o_exec_execute_ddm_table ddm_table;
44990- char tmp[28 + 1];
44991
44992 result = kmalloc(sizeof(*result), GFP_KERNEL);
44993 if (!result)
44994@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44995
44996 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44997 seq_printf(seq, "%-#8x", ddm_table.module_id);
44998- seq_printf(seq, "%-29s",
44999- chtostr(tmp, ddm_table.module_name_version, 28));
45000+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45001 seq_printf(seq, "%9d ", ddm_table.data_size);
45002 seq_printf(seq, "%8d", ddm_table.code_size);
45003
45004@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45005
45006 i2o_driver_result_table *result;
45007 i2o_driver_store_table *dst;
45008- char tmp[28 + 1];
45009
45010 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45011 if (result == NULL)
45012@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45013
45014 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45015 seq_printf(seq, "%-#8x", dst->module_id);
45016- seq_printf(seq, "%-29s",
45017- chtostr(tmp, dst->module_name_version, 28));
45018- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45019+ seq_printf(seq, "%-.28s", dst->module_name_version);
45020+ seq_printf(seq, "%-.8s", dst->date);
45021 seq_printf(seq, "%8d ", dst->module_size);
45022 seq_printf(seq, "%8d ", dst->mpb_size);
45023 seq_printf(seq, "0x%04x", dst->module_flags);
45024@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45025 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45026 {
45027 struct i2o_device *d = (struct i2o_device *)seq->private;
45028- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45029+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45030 // == (allow) 512d bytes (max)
45031- static u16 *work16 = (u16 *) work32;
45032+ u16 *work16 = (u16 *) work32;
45033 int token;
45034- char tmp[16 + 1];
45035
45036 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45037
45038@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45039 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45040 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45041 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45042- seq_printf(seq, "Vendor info : %s\n",
45043- chtostr(tmp, (u8 *) (work32 + 2), 16));
45044- seq_printf(seq, "Product info : %s\n",
45045- chtostr(tmp, (u8 *) (work32 + 6), 16));
45046- seq_printf(seq, "Description : %s\n",
45047- chtostr(tmp, (u8 *) (work32 + 10), 16));
45048- seq_printf(seq, "Product rev. : %s\n",
45049- chtostr(tmp, (u8 *) (work32 + 14), 8));
45050+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45051+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45052+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45053+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45054
45055 seq_printf(seq, "Serial number : ");
45056 print_serial_number(seq, (u8 *) (work32 + 16),
45057@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45058 u8 pad[256]; // allow up to 256 byte (max) serial number
45059 } result;
45060
45061- char tmp[24 + 1];
45062-
45063 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45064
45065 if (token < 0) {
45066@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45067 }
45068
45069 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45070- seq_printf(seq, "Module name : %s\n",
45071- chtostr(tmp, result.module_name, 24));
45072- seq_printf(seq, "Module revision : %s\n",
45073- chtostr(tmp, result.module_rev, 8));
45074+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45075+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45076
45077 seq_printf(seq, "Serial number : ");
45078 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45079@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45080 u8 instance_number[4];
45081 } result;
45082
45083- char tmp[64 + 1];
45084-
45085 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45086
45087 if (token < 0) {
45088@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45089 return 0;
45090 }
45091
45092- seq_printf(seq, "Device name : %s\n",
45093- chtostr(tmp, result.device_name, 64));
45094- seq_printf(seq, "Service name : %s\n",
45095- chtostr(tmp, result.service_name, 64));
45096- seq_printf(seq, "Physical name : %s\n",
45097- chtostr(tmp, result.physical_location, 64));
45098- seq_printf(seq, "Instance number : %s\n",
45099- chtostr(tmp, result.instance_number, 4));
45100+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45101+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45102+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45103+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45104
45105 return 0;
45106 }
45107@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45108 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45109 {
45110 struct i2o_device *d = (struct i2o_device *)seq->private;
45111- static u32 work32[12];
45112- static u16 *work16 = (u16 *) work32;
45113- static u8 *work8 = (u8 *) work32;
45114+ u32 work32[12];
45115+ u16 *work16 = (u16 *) work32;
45116+ u8 *work8 = (u8 *) work32;
45117 int token;
45118
45119 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45120diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45121index a8c08f3..155fe3d 100644
45122--- a/drivers/message/i2o/iop.c
45123+++ b/drivers/message/i2o/iop.c
45124@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45125
45126 spin_lock_irqsave(&c->context_list_lock, flags);
45127
45128- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45129- atomic_inc(&c->context_list_counter);
45130+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45131+ atomic_inc_unchecked(&c->context_list_counter);
45132
45133- entry->context = atomic_read(&c->context_list_counter);
45134+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45135
45136 list_add(&entry->list, &c->context_list);
45137
45138@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45139
45140 #if BITS_PER_LONG == 64
45141 spin_lock_init(&c->context_list_lock);
45142- atomic_set(&c->context_list_counter, 0);
45143+ atomic_set_unchecked(&c->context_list_counter, 0);
45144 INIT_LIST_HEAD(&c->context_list);
45145 #endif
45146
45147diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45148index d1a22aa..d0f7bf7 100644
45149--- a/drivers/mfd/ab8500-debugfs.c
45150+++ b/drivers/mfd/ab8500-debugfs.c
45151@@ -100,7 +100,7 @@ static int irq_last;
45152 static u32 *irq_count;
45153 static int num_irqs;
45154
45155-static struct device_attribute **dev_attr;
45156+static device_attribute_no_const **dev_attr;
45157 static char **event_name;
45158
45159 static u8 avg_sample = SAMPLE_16;
45160diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45161index 81b7d88..95ae998 100644
45162--- a/drivers/mfd/janz-cmodio.c
45163+++ b/drivers/mfd/janz-cmodio.c
45164@@ -13,6 +13,7 @@
45165
45166 #include <linux/kernel.h>
45167 #include <linux/module.h>
45168+#include <linux/slab.h>
45169 #include <linux/init.h>
45170 #include <linux/pci.h>
45171 #include <linux/interrupt.h>
45172diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45173index a83eed5..62a58a9 100644
45174--- a/drivers/mfd/max8925-i2c.c
45175+++ b/drivers/mfd/max8925-i2c.c
45176@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45177 const struct i2c_device_id *id)
45178 {
45179 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45180- static struct max8925_chip *chip;
45181+ struct max8925_chip *chip;
45182 struct device_node *node = client->dev.of_node;
45183
45184 if (node && !pdata) {
45185diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45186index d657331..0d9a80f 100644
45187--- a/drivers/mfd/tps65910.c
45188+++ b/drivers/mfd/tps65910.c
45189@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45190 struct tps65910_platform_data *pdata)
45191 {
45192 int ret = 0;
45193- static struct regmap_irq_chip *tps6591x_irqs_chip;
45194+ struct regmap_irq_chip *tps6591x_irqs_chip;
45195
45196 if (!irq) {
45197 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45198diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45199index 9aa6d1e..1631bfc 100644
45200--- a/drivers/mfd/twl4030-irq.c
45201+++ b/drivers/mfd/twl4030-irq.c
45202@@ -35,6 +35,7 @@
45203 #include <linux/of.h>
45204 #include <linux/irqdomain.h>
45205 #include <linux/i2c/twl.h>
45206+#include <asm/pgtable.h>
45207
45208 #include "twl-core.h"
45209
45210@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45211 * Install an irq handler for each of the SIH modules;
45212 * clone dummy irq_chip since PIH can't *do* anything
45213 */
45214- twl4030_irq_chip = dummy_irq_chip;
45215- twl4030_irq_chip.name = "twl4030";
45216+ pax_open_kernel();
45217+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45218+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45219
45220- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45221+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45222+ pax_close_kernel();
45223
45224 for (i = irq_base; i < irq_end; i++) {
45225 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45226diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45227index 464419b..64bae8d 100644
45228--- a/drivers/misc/c2port/core.c
45229+++ b/drivers/misc/c2port/core.c
45230@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45231 goto error_idr_alloc;
45232 c2dev->id = ret;
45233
45234- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45235+ pax_open_kernel();
45236+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45237+ pax_close_kernel();
45238
45239 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45240 "c2port%d", c2dev->id);
45241diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45242index 9c34e57..b981cda 100644
45243--- a/drivers/misc/eeprom/sunxi_sid.c
45244+++ b/drivers/misc/eeprom/sunxi_sid.c
45245@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45246
45247 platform_set_drvdata(pdev, sid_data);
45248
45249- sid_bin_attr.size = sid_data->keysize;
45250+ pax_open_kernel();
45251+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45252+ pax_close_kernel();
45253 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45254 return -ENODEV;
45255
45256diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45257index 36f5d52..32311c3 100644
45258--- a/drivers/misc/kgdbts.c
45259+++ b/drivers/misc/kgdbts.c
45260@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45261 char before[BREAK_INSTR_SIZE];
45262 char after[BREAK_INSTR_SIZE];
45263
45264- probe_kernel_read(before, (char *)kgdbts_break_test,
45265+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45266 BREAK_INSTR_SIZE);
45267 init_simple_test();
45268 ts.tst = plant_and_detach_test;
45269@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45270 /* Activate test with initial breakpoint */
45271 if (!is_early)
45272 kgdb_breakpoint();
45273- probe_kernel_read(after, (char *)kgdbts_break_test,
45274+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45275 BREAK_INSTR_SIZE);
45276 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45277 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45278diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45279index 036effe..b3a6336 100644
45280--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45281+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45282@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45283 * the lid is closed. This leads to interrupts as soon as a little move
45284 * is done.
45285 */
45286- atomic_inc(&lis3->count);
45287+ atomic_inc_unchecked(&lis3->count);
45288
45289 wake_up_interruptible(&lis3->misc_wait);
45290 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45291@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45292 if (lis3->pm_dev)
45293 pm_runtime_get_sync(lis3->pm_dev);
45294
45295- atomic_set(&lis3->count, 0);
45296+ atomic_set_unchecked(&lis3->count, 0);
45297 return 0;
45298 }
45299
45300@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45301 add_wait_queue(&lis3->misc_wait, &wait);
45302 while (true) {
45303 set_current_state(TASK_INTERRUPTIBLE);
45304- data = atomic_xchg(&lis3->count, 0);
45305+ data = atomic_xchg_unchecked(&lis3->count, 0);
45306 if (data)
45307 break;
45308
45309@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45310 struct lis3lv02d, miscdev);
45311
45312 poll_wait(file, &lis3->misc_wait, wait);
45313- if (atomic_read(&lis3->count))
45314+ if (atomic_read_unchecked(&lis3->count))
45315 return POLLIN | POLLRDNORM;
45316 return 0;
45317 }
45318diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45319index c439c82..1f20f57 100644
45320--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45321+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45322@@ -297,7 +297,7 @@ struct lis3lv02d {
45323 struct input_polled_dev *idev; /* input device */
45324 struct platform_device *pdev; /* platform device */
45325 struct regulator_bulk_data regulators[2];
45326- atomic_t count; /* interrupt count after last read */
45327+ atomic_unchecked_t count; /* interrupt count after last read */
45328 union axis_conversion ac; /* hw -> logical axis */
45329 int mapped_btns[3];
45330
45331diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45332index 2f30bad..c4c13d0 100644
45333--- a/drivers/misc/sgi-gru/gruhandles.c
45334+++ b/drivers/misc/sgi-gru/gruhandles.c
45335@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45336 unsigned long nsec;
45337
45338 nsec = CLKS2NSEC(clks);
45339- atomic_long_inc(&mcs_op_statistics[op].count);
45340- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45341+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45342+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45343 if (mcs_op_statistics[op].max < nsec)
45344 mcs_op_statistics[op].max = nsec;
45345 }
45346diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45347index 4f76359..cdfcb2e 100644
45348--- a/drivers/misc/sgi-gru/gruprocfs.c
45349+++ b/drivers/misc/sgi-gru/gruprocfs.c
45350@@ -32,9 +32,9 @@
45351
45352 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45353
45354-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45355+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45356 {
45357- unsigned long val = atomic_long_read(v);
45358+ unsigned long val = atomic_long_read_unchecked(v);
45359
45360 seq_printf(s, "%16lu %s\n", val, id);
45361 }
45362@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45363
45364 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45365 for (op = 0; op < mcsop_last; op++) {
45366- count = atomic_long_read(&mcs_op_statistics[op].count);
45367- total = atomic_long_read(&mcs_op_statistics[op].total);
45368+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45369+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45370 max = mcs_op_statistics[op].max;
45371 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45372 count ? total / count : 0, max);
45373diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45374index 5c3ce24..4915ccb 100644
45375--- a/drivers/misc/sgi-gru/grutables.h
45376+++ b/drivers/misc/sgi-gru/grutables.h
45377@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45378 * GRU statistics.
45379 */
45380 struct gru_stats_s {
45381- atomic_long_t vdata_alloc;
45382- atomic_long_t vdata_free;
45383- atomic_long_t gts_alloc;
45384- atomic_long_t gts_free;
45385- atomic_long_t gms_alloc;
45386- atomic_long_t gms_free;
45387- atomic_long_t gts_double_allocate;
45388- atomic_long_t assign_context;
45389- atomic_long_t assign_context_failed;
45390- atomic_long_t free_context;
45391- atomic_long_t load_user_context;
45392- atomic_long_t load_kernel_context;
45393- atomic_long_t lock_kernel_context;
45394- atomic_long_t unlock_kernel_context;
45395- atomic_long_t steal_user_context;
45396- atomic_long_t steal_kernel_context;
45397- atomic_long_t steal_context_failed;
45398- atomic_long_t nopfn;
45399- atomic_long_t asid_new;
45400- atomic_long_t asid_next;
45401- atomic_long_t asid_wrap;
45402- atomic_long_t asid_reuse;
45403- atomic_long_t intr;
45404- atomic_long_t intr_cbr;
45405- atomic_long_t intr_tfh;
45406- atomic_long_t intr_spurious;
45407- atomic_long_t intr_mm_lock_failed;
45408- atomic_long_t call_os;
45409- atomic_long_t call_os_wait_queue;
45410- atomic_long_t user_flush_tlb;
45411- atomic_long_t user_unload_context;
45412- atomic_long_t user_exception;
45413- atomic_long_t set_context_option;
45414- atomic_long_t check_context_retarget_intr;
45415- atomic_long_t check_context_unload;
45416- atomic_long_t tlb_dropin;
45417- atomic_long_t tlb_preload_page;
45418- atomic_long_t tlb_dropin_fail_no_asid;
45419- atomic_long_t tlb_dropin_fail_upm;
45420- atomic_long_t tlb_dropin_fail_invalid;
45421- atomic_long_t tlb_dropin_fail_range_active;
45422- atomic_long_t tlb_dropin_fail_idle;
45423- atomic_long_t tlb_dropin_fail_fmm;
45424- atomic_long_t tlb_dropin_fail_no_exception;
45425- atomic_long_t tfh_stale_on_fault;
45426- atomic_long_t mmu_invalidate_range;
45427- atomic_long_t mmu_invalidate_page;
45428- atomic_long_t flush_tlb;
45429- atomic_long_t flush_tlb_gru;
45430- atomic_long_t flush_tlb_gru_tgh;
45431- atomic_long_t flush_tlb_gru_zero_asid;
45432+ atomic_long_unchecked_t vdata_alloc;
45433+ atomic_long_unchecked_t vdata_free;
45434+ atomic_long_unchecked_t gts_alloc;
45435+ atomic_long_unchecked_t gts_free;
45436+ atomic_long_unchecked_t gms_alloc;
45437+ atomic_long_unchecked_t gms_free;
45438+ atomic_long_unchecked_t gts_double_allocate;
45439+ atomic_long_unchecked_t assign_context;
45440+ atomic_long_unchecked_t assign_context_failed;
45441+ atomic_long_unchecked_t free_context;
45442+ atomic_long_unchecked_t load_user_context;
45443+ atomic_long_unchecked_t load_kernel_context;
45444+ atomic_long_unchecked_t lock_kernel_context;
45445+ atomic_long_unchecked_t unlock_kernel_context;
45446+ atomic_long_unchecked_t steal_user_context;
45447+ atomic_long_unchecked_t steal_kernel_context;
45448+ atomic_long_unchecked_t steal_context_failed;
45449+ atomic_long_unchecked_t nopfn;
45450+ atomic_long_unchecked_t asid_new;
45451+ atomic_long_unchecked_t asid_next;
45452+ atomic_long_unchecked_t asid_wrap;
45453+ atomic_long_unchecked_t asid_reuse;
45454+ atomic_long_unchecked_t intr;
45455+ atomic_long_unchecked_t intr_cbr;
45456+ atomic_long_unchecked_t intr_tfh;
45457+ atomic_long_unchecked_t intr_spurious;
45458+ atomic_long_unchecked_t intr_mm_lock_failed;
45459+ atomic_long_unchecked_t call_os;
45460+ atomic_long_unchecked_t call_os_wait_queue;
45461+ atomic_long_unchecked_t user_flush_tlb;
45462+ atomic_long_unchecked_t user_unload_context;
45463+ atomic_long_unchecked_t user_exception;
45464+ atomic_long_unchecked_t set_context_option;
45465+ atomic_long_unchecked_t check_context_retarget_intr;
45466+ atomic_long_unchecked_t check_context_unload;
45467+ atomic_long_unchecked_t tlb_dropin;
45468+ atomic_long_unchecked_t tlb_preload_page;
45469+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45470+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45471+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45472+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45473+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45474+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45475+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45476+ atomic_long_unchecked_t tfh_stale_on_fault;
45477+ atomic_long_unchecked_t mmu_invalidate_range;
45478+ atomic_long_unchecked_t mmu_invalidate_page;
45479+ atomic_long_unchecked_t flush_tlb;
45480+ atomic_long_unchecked_t flush_tlb_gru;
45481+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45482+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45483
45484- atomic_long_t copy_gpa;
45485- atomic_long_t read_gpa;
45486+ atomic_long_unchecked_t copy_gpa;
45487+ atomic_long_unchecked_t read_gpa;
45488
45489- atomic_long_t mesq_receive;
45490- atomic_long_t mesq_receive_none;
45491- atomic_long_t mesq_send;
45492- atomic_long_t mesq_send_failed;
45493- atomic_long_t mesq_noop;
45494- atomic_long_t mesq_send_unexpected_error;
45495- atomic_long_t mesq_send_lb_overflow;
45496- atomic_long_t mesq_send_qlimit_reached;
45497- atomic_long_t mesq_send_amo_nacked;
45498- atomic_long_t mesq_send_put_nacked;
45499- atomic_long_t mesq_page_overflow;
45500- atomic_long_t mesq_qf_locked;
45501- atomic_long_t mesq_qf_noop_not_full;
45502- atomic_long_t mesq_qf_switch_head_failed;
45503- atomic_long_t mesq_qf_unexpected_error;
45504- atomic_long_t mesq_noop_unexpected_error;
45505- atomic_long_t mesq_noop_lb_overflow;
45506- atomic_long_t mesq_noop_qlimit_reached;
45507- atomic_long_t mesq_noop_amo_nacked;
45508- atomic_long_t mesq_noop_put_nacked;
45509- atomic_long_t mesq_noop_page_overflow;
45510+ atomic_long_unchecked_t mesq_receive;
45511+ atomic_long_unchecked_t mesq_receive_none;
45512+ atomic_long_unchecked_t mesq_send;
45513+ atomic_long_unchecked_t mesq_send_failed;
45514+ atomic_long_unchecked_t mesq_noop;
45515+ atomic_long_unchecked_t mesq_send_unexpected_error;
45516+ atomic_long_unchecked_t mesq_send_lb_overflow;
45517+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45518+ atomic_long_unchecked_t mesq_send_amo_nacked;
45519+ atomic_long_unchecked_t mesq_send_put_nacked;
45520+ atomic_long_unchecked_t mesq_page_overflow;
45521+ atomic_long_unchecked_t mesq_qf_locked;
45522+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45523+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45524+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45525+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45526+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45527+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45528+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45529+ atomic_long_unchecked_t mesq_noop_put_nacked;
45530+ atomic_long_unchecked_t mesq_noop_page_overflow;
45531
45532 };
45533
45534@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45535 tghop_invalidate, mcsop_last};
45536
45537 struct mcs_op_statistic {
45538- atomic_long_t count;
45539- atomic_long_t total;
45540+ atomic_long_unchecked_t count;
45541+ atomic_long_unchecked_t total;
45542 unsigned long max;
45543 };
45544
45545@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45546
45547 #define STAT(id) do { \
45548 if (gru_options & OPT_STATS) \
45549- atomic_long_inc(&gru_stats.id); \
45550+ atomic_long_inc_unchecked(&gru_stats.id); \
45551 } while (0)
45552
45553 #ifdef CONFIG_SGI_GRU_DEBUG
45554diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45555index c862cd4..0d176fe 100644
45556--- a/drivers/misc/sgi-xp/xp.h
45557+++ b/drivers/misc/sgi-xp/xp.h
45558@@ -288,7 +288,7 @@ struct xpc_interface {
45559 xpc_notify_func, void *);
45560 void (*received) (short, int, void *);
45561 enum xp_retval (*partid_to_nasids) (short, void *);
45562-};
45563+} __no_const;
45564
45565 extern struct xpc_interface xpc_interface;
45566
45567diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45568index 01be66d..e3a0c7e 100644
45569--- a/drivers/misc/sgi-xp/xp_main.c
45570+++ b/drivers/misc/sgi-xp/xp_main.c
45571@@ -78,13 +78,13 @@ xpc_notloaded(void)
45572 }
45573
45574 struct xpc_interface xpc_interface = {
45575- (void (*)(int))xpc_notloaded,
45576- (void (*)(int))xpc_notloaded,
45577- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45578- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45579+ .connect = (void (*)(int))xpc_notloaded,
45580+ .disconnect = (void (*)(int))xpc_notloaded,
45581+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45582+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45583 void *))xpc_notloaded,
45584- (void (*)(short, int, void *))xpc_notloaded,
45585- (enum xp_retval(*)(short, void *))xpc_notloaded
45586+ .received = (void (*)(short, int, void *))xpc_notloaded,
45587+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45588 };
45589 EXPORT_SYMBOL_GPL(xpc_interface);
45590
45591diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45592index b94d5f7..7f494c5 100644
45593--- a/drivers/misc/sgi-xp/xpc.h
45594+++ b/drivers/misc/sgi-xp/xpc.h
45595@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45596 void (*received_payload) (struct xpc_channel *, void *);
45597 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45598 };
45599+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45600
45601 /* struct xpc_partition act_state values (for XPC HB) */
45602
45603@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45604 /* found in xpc_main.c */
45605 extern struct device *xpc_part;
45606 extern struct device *xpc_chan;
45607-extern struct xpc_arch_operations xpc_arch_ops;
45608+extern xpc_arch_operations_no_const xpc_arch_ops;
45609 extern int xpc_disengage_timelimit;
45610 extern int xpc_disengage_timedout;
45611 extern int xpc_activate_IRQ_rcvd;
45612diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45613index 82dc574..8539ab2 100644
45614--- a/drivers/misc/sgi-xp/xpc_main.c
45615+++ b/drivers/misc/sgi-xp/xpc_main.c
45616@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45617 .notifier_call = xpc_system_die,
45618 };
45619
45620-struct xpc_arch_operations xpc_arch_ops;
45621+xpc_arch_operations_no_const xpc_arch_ops;
45622
45623 /*
45624 * Timer function to enforce the timelimit on the partition disengage.
45625@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45626
45627 if (((die_args->trapnr == X86_TRAP_MF) ||
45628 (die_args->trapnr == X86_TRAP_XF)) &&
45629- !user_mode_vm(die_args->regs))
45630+ !user_mode(die_args->regs))
45631 xpc_die_deactivate();
45632
45633 break;
45634diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45635index 7b5424f..ed1d6ac 100644
45636--- a/drivers/mmc/card/block.c
45637+++ b/drivers/mmc/card/block.c
45638@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45639 if (idata->ic.postsleep_min_us)
45640 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45641
45642- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45643+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45644 err = -EFAULT;
45645 goto cmd_rel_host;
45646 }
45647diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45648index e5b5eeb..7bf2212 100644
45649--- a/drivers/mmc/core/mmc_ops.c
45650+++ b/drivers/mmc/core/mmc_ops.c
45651@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45652 void *data_buf;
45653 int is_on_stack;
45654
45655- is_on_stack = object_is_on_stack(buf);
45656+ is_on_stack = object_starts_on_stack(buf);
45657 if (is_on_stack) {
45658 /*
45659 * dma onto stack is unsafe/nonportable, but callers to this
45660diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45661index 6bf24ab..13d0293b 100644
45662--- a/drivers/mmc/host/dw_mmc.h
45663+++ b/drivers/mmc/host/dw_mmc.h
45664@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45665 int (*parse_dt)(struct dw_mci *host);
45666 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45667 struct dw_mci_tuning_data *tuning_data);
45668-};
45669+} __do_const;
45670 #endif /* _DW_MMC_H_ */
45671diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45672index b931226..df6a085 100644
45673--- a/drivers/mmc/host/mmci.c
45674+++ b/drivers/mmc/host/mmci.c
45675@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45676 }
45677
45678 if (variant->busy_detect) {
45679- mmci_ops.card_busy = mmci_card_busy;
45680+ pax_open_kernel();
45681+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45682+ pax_close_kernel();
45683 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45684 }
45685
45686diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45687index b841bb7..d82712f5 100644
45688--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45689+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45690@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45691 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45692 }
45693
45694- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45695- sdhci_esdhc_ops.platform_execute_tuning =
45696+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45697+ pax_open_kernel();
45698+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45699 esdhc_executing_tuning;
45700+ pax_close_kernel();
45701+ }
45702
45703 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45704 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45705diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45706index 6debda9..2ba7427 100644
45707--- a/drivers/mmc/host/sdhci-s3c.c
45708+++ b/drivers/mmc/host/sdhci-s3c.c
45709@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45710 * we can use overriding functions instead of default.
45711 */
45712 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45713- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45714- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45715- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45716+ pax_open_kernel();
45717+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45718+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45719+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45720+ pax_close_kernel();
45721 }
45722
45723 /* It supports additional host capabilities if needed */
45724diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45725index 096993f..f02c23b 100644
45726--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45727+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45728@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45729 size_t totlen = 0, thislen;
45730 int ret = 0;
45731 size_t buflen = 0;
45732- static char *buffer;
45733+ char *buffer;
45734
45735 if (!ECCBUF_SIZE) {
45736 /* We should fall back to a general writev implementation.
45737diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45738index c07cd57..61c4fbd 100644
45739--- a/drivers/mtd/nand/denali.c
45740+++ b/drivers/mtd/nand/denali.c
45741@@ -24,6 +24,7 @@
45742 #include <linux/slab.h>
45743 #include <linux/mtd/mtd.h>
45744 #include <linux/module.h>
45745+#include <linux/slab.h>
45746
45747 #include "denali.h"
45748
45749diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45750index ca6369f..0ce9fed 100644
45751--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45752+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45753@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45754
45755 /* first try to map the upper buffer directly */
45756 if (virt_addr_valid(this->upper_buf) &&
45757- !object_is_on_stack(this->upper_buf)) {
45758+ !object_starts_on_stack(this->upper_buf)) {
45759 sg_init_one(sgl, this->upper_buf, this->upper_len);
45760 ret = dma_map_sg(this->dev, sgl, 1, dr);
45761 if (ret == 0)
45762diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45763index 51b9d6a..52af9a7 100644
45764--- a/drivers/mtd/nftlmount.c
45765+++ b/drivers/mtd/nftlmount.c
45766@@ -24,6 +24,7 @@
45767 #include <asm/errno.h>
45768 #include <linux/delay.h>
45769 #include <linux/slab.h>
45770+#include <linux/sched.h>
45771 #include <linux/mtd/mtd.h>
45772 #include <linux/mtd/nand.h>
45773 #include <linux/mtd/nftl.h>
45774diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45775index 4b8e895..6b3c498 100644
45776--- a/drivers/mtd/sm_ftl.c
45777+++ b/drivers/mtd/sm_ftl.c
45778@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45779 #define SM_CIS_VENDOR_OFFSET 0x59
45780 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45781 {
45782- struct attribute_group *attr_group;
45783+ attribute_group_no_const *attr_group;
45784 struct attribute **attributes;
45785 struct sm_sysfs_attribute *vendor_attribute;
45786
45787diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45788index e5628fc..ffe54d1 100644
45789--- a/drivers/net/bonding/bond_main.c
45790+++ b/drivers/net/bonding/bond_main.c
45791@@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
45792
45793 bond_netlink_fini();
45794 unregister_pernet_subsys(&bond_net_ops);
45795+ rtnl_link_unregister(&bond_link_ops);
45796
45797 #ifdef CONFIG_NET_POLL_CONTROLLER
45798 /*
45799diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45800index 70651f8..7eb1bdf 100644
45801--- a/drivers/net/bonding/bond_netlink.c
45802+++ b/drivers/net/bonding/bond_netlink.c
45803@@ -542,7 +542,7 @@ nla_put_failure:
45804 return -EMSGSIZE;
45805 }
45806
45807-struct rtnl_link_ops bond_link_ops __read_mostly = {
45808+struct rtnl_link_ops bond_link_ops = {
45809 .kind = "bond",
45810 .priv_size = sizeof(struct bonding),
45811 .setup = bond_setup,
45812diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45813index 9e7d95d..d447b88 100644
45814--- a/drivers/net/can/Kconfig
45815+++ b/drivers/net/can/Kconfig
45816@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45817
45818 config CAN_FLEXCAN
45819 tristate "Support for Freescale FLEXCAN based chips"
45820- depends on ARM || PPC
45821+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45822 ---help---
45823 Say Y here if you want to support for Freescale FlexCAN.
45824
45825diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45826index 455d4c3..3353ee7 100644
45827--- a/drivers/net/ethernet/8390/ax88796.c
45828+++ b/drivers/net/ethernet/8390/ax88796.c
45829@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45830 if (ax->plat->reg_offsets)
45831 ei_local->reg_offset = ax->plat->reg_offsets;
45832 else {
45833+ resource_size_t _mem_size = mem_size;
45834+ do_div(_mem_size, 0x18);
45835 ei_local->reg_offset = ax->reg_offsets;
45836 for (ret = 0; ret < 0x18; ret++)
45837- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45838+ ax->reg_offsets[ret] = _mem_size * ret;
45839 }
45840
45841 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45842diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45843index a89a40f..5a8a2ac 100644
45844--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45845+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45846@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45847 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45848 {
45849 /* RX_MODE controlling object */
45850- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45851+ bnx2x_init_rx_mode_obj(bp);
45852
45853 /* multicast configuration controlling object */
45854 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45855diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45856index 0fb6ff2..78fd55c 100644
45857--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45858+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45859@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45860 return rc;
45861 }
45862
45863-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45864- struct bnx2x_rx_mode_obj *o)
45865+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45866 {
45867 if (CHIP_IS_E1x(bp)) {
45868- o->wait_comp = bnx2x_empty_rx_mode_wait;
45869- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45870+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45871+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45872 } else {
45873- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45874- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45875+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45876+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45877 }
45878 }
45879
45880diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45881index 00d7f21..2cddec4 100644
45882--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45883+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45884@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45885
45886 /********************* RX MODE ****************/
45887
45888-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45889- struct bnx2x_rx_mode_obj *o);
45890+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45891
45892 /**
45893 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45894diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45895index 04321e5..b51cdc4 100644
45896--- a/drivers/net/ethernet/broadcom/tg3.h
45897+++ b/drivers/net/ethernet/broadcom/tg3.h
45898@@ -150,6 +150,7 @@
45899 #define CHIPREV_ID_5750_A0 0x4000
45900 #define CHIPREV_ID_5750_A1 0x4001
45901 #define CHIPREV_ID_5750_A3 0x4003
45902+#define CHIPREV_ID_5750_C1 0x4201
45903 #define CHIPREV_ID_5750_C2 0x4202
45904 #define CHIPREV_ID_5752_A0_HW 0x5000
45905 #define CHIPREV_ID_5752_A0 0x6000
45906diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45907index 13f9636..228040f 100644
45908--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45909+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45910@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45911 }
45912
45913 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45914- bna_cb_ioceth_enable,
45915- bna_cb_ioceth_disable,
45916- bna_cb_ioceth_hbfail,
45917- bna_cb_ioceth_reset
45918+ .enable_cbfn = bna_cb_ioceth_enable,
45919+ .disable_cbfn = bna_cb_ioceth_disable,
45920+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45921+ .reset_cbfn = bna_cb_ioceth_reset
45922 };
45923
45924 static void bna_attr_init(struct bna_ioceth *ioceth)
45925diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45926index 8cffcdf..aadf043 100644
45927--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45928+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45929@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45930 */
45931 struct l2t_skb_cb {
45932 arp_failure_handler_func arp_failure_handler;
45933-};
45934+} __no_const;
45935
45936 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45937
45938diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45939index 34e2488..07e2079 100644
45940--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45941+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45942@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45943
45944 int i;
45945 struct adapter *ap = netdev2adap(dev);
45946- static const unsigned int *reg_ranges;
45947+ const unsigned int *reg_ranges;
45948 int arr_size = 0, buf_size = 0;
45949
45950 if (is_t4(ap->params.chip)) {
45951diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45952index c05b66d..ed69872 100644
45953--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45954+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45955@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45956 for (i=0; i<ETH_ALEN; i++) {
45957 tmp.addr[i] = dev->dev_addr[i];
45958 }
45959- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45960+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45961 break;
45962
45963 case DE4X5_SET_HWADDR: /* Set the hardware address */
45964@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45965 spin_lock_irqsave(&lp->lock, flags);
45966 memcpy(&statbuf, &lp->pktStats, ioc->len);
45967 spin_unlock_irqrestore(&lp->lock, flags);
45968- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45969+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45970 return -EFAULT;
45971 break;
45972 }
45973diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45974index 36c8061..ca5e1e0 100644
45975--- a/drivers/net/ethernet/emulex/benet/be_main.c
45976+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45977@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45978
45979 if (wrapped)
45980 newacc += 65536;
45981- ACCESS_ONCE(*acc) = newacc;
45982+ ACCESS_ONCE_RW(*acc) = newacc;
45983 }
45984
45985 static void populate_erx_stats(struct be_adapter *adapter,
45986diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45987index c11ecbc..13bb299 100644
45988--- a/drivers/net/ethernet/faraday/ftgmac100.c
45989+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45990@@ -30,6 +30,8 @@
45991 #include <linux/netdevice.h>
45992 #include <linux/phy.h>
45993 #include <linux/platform_device.h>
45994+#include <linux/interrupt.h>
45995+#include <linux/irqreturn.h>
45996 #include <net/ip.h>
45997
45998 #include "ftgmac100.h"
45999diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46000index 8be5b40..081bc1b 100644
46001--- a/drivers/net/ethernet/faraday/ftmac100.c
46002+++ b/drivers/net/ethernet/faraday/ftmac100.c
46003@@ -31,6 +31,8 @@
46004 #include <linux/module.h>
46005 #include <linux/netdevice.h>
46006 #include <linux/platform_device.h>
46007+#include <linux/interrupt.h>
46008+#include <linux/irqreturn.h>
46009
46010 #include "ftmac100.h"
46011
46012diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46013index e33ec6c..f54cfe7 100644
46014--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46015+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46016@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46017 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46018
46019 /* Update the base adjustement value. */
46020- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46021+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46022 smp_mb(); /* Force the above update. */
46023 }
46024
46025diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46026index 5184e2a..acb28c3 100644
46027--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46028+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46029@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46030 }
46031
46032 /* update the base incval used to calculate frequency adjustment */
46033- ACCESS_ONCE(adapter->base_incval) = incval;
46034+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46035 smp_mb();
46036
46037 /* need lock to prevent incorrect read while modifying cyclecounter */
46038diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46039index 089b713..28d87ae 100644
46040--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46041+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46042@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46043 struct __vxge_hw_fifo *fifo;
46044 struct vxge_hw_fifo_config *config;
46045 u32 txdl_size, txdl_per_memblock;
46046- struct vxge_hw_mempool_cbs fifo_mp_callback;
46047+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46048+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46049+ };
46050+
46051 struct __vxge_hw_virtualpath *vpath;
46052
46053 if ((vp == NULL) || (attr == NULL)) {
46054@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46055 goto exit;
46056 }
46057
46058- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46059-
46060 fifo->mempool =
46061 __vxge_hw_mempool_create(vpath->hldev,
46062 fifo->config->memblock_size,
46063diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46064index 90a2dda..47e620e 100644
46065--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46066+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46067@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46068 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46069 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46070 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46071- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46072+ pax_open_kernel();
46073+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46074+ pax_close_kernel();
46075 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46076 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46077 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46078diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46079index be7d7a6..a8983f8 100644
46080--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46081+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46082@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46083 case QLCNIC_NON_PRIV_FUNC:
46084 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46085 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46086- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46087+ pax_open_kernel();
46088+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46089+ pax_close_kernel();
46090 break;
46091 case QLCNIC_PRIV_FUNC:
46092 ahw->op_mode = QLCNIC_PRIV_FUNC;
46093 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46094- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46095+ pax_open_kernel();
46096+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46097+ pax_close_kernel();
46098 break;
46099 case QLCNIC_MGMT_FUNC:
46100 ahw->op_mode = QLCNIC_MGMT_FUNC;
46101 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46102- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46103+ pax_open_kernel();
46104+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46105+ pax_close_kernel();
46106 break;
46107 default:
46108 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46109diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46110index 7763962..c3499a7 100644
46111--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46112+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46113@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46114 struct qlcnic_dump_entry *entry;
46115 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46116 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46117- static const struct qlcnic_dump_operations *fw_dump_ops;
46118+ const struct qlcnic_dump_operations *fw_dump_ops;
46119 struct device *dev = &adapter->pdev->dev;
46120 struct qlcnic_hardware_context *ahw;
46121 void *temp_buffer;
46122diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46123index 3ff7bc3..366091b 100644
46124--- a/drivers/net/ethernet/realtek/r8169.c
46125+++ b/drivers/net/ethernet/realtek/r8169.c
46126@@ -758,22 +758,22 @@ struct rtl8169_private {
46127 struct mdio_ops {
46128 void (*write)(struct rtl8169_private *, int, int);
46129 int (*read)(struct rtl8169_private *, int);
46130- } mdio_ops;
46131+ } __no_const mdio_ops;
46132
46133 struct pll_power_ops {
46134 void (*down)(struct rtl8169_private *);
46135 void (*up)(struct rtl8169_private *);
46136- } pll_power_ops;
46137+ } __no_const pll_power_ops;
46138
46139 struct jumbo_ops {
46140 void (*enable)(struct rtl8169_private *);
46141 void (*disable)(struct rtl8169_private *);
46142- } jumbo_ops;
46143+ } __no_const jumbo_ops;
46144
46145 struct csi_ops {
46146 void (*write)(struct rtl8169_private *, int, int);
46147 u32 (*read)(struct rtl8169_private *, int);
46148- } csi_ops;
46149+ } __no_const csi_ops;
46150
46151 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46152 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46153diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46154index d7a3682..9ce272a 100644
46155--- a/drivers/net/ethernet/sfc/ptp.c
46156+++ b/drivers/net/ethernet/sfc/ptp.c
46157@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46158 ptp->start.dma_addr);
46159
46160 /* Clear flag that signals MC ready */
46161- ACCESS_ONCE(*start) = 0;
46162+ ACCESS_ONCE_RW(*start) = 0;
46163 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46164 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46165 EFX_BUG_ON_PARANOID(rc);
46166diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46167index 50617c5..b13724c 100644
46168--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46169+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46170@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46171
46172 writel(value, ioaddr + MMC_CNTRL);
46173
46174- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46175- MMC_CNTRL, value);
46176+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46177+// MMC_CNTRL, value);
46178 }
46179
46180 /* To mask all all interrupts.*/
46181diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46182index 7b594ce..1f6c5708 100644
46183--- a/drivers/net/hyperv/hyperv_net.h
46184+++ b/drivers/net/hyperv/hyperv_net.h
46185@@ -100,7 +100,7 @@ struct rndis_device {
46186
46187 enum rndis_device_state state;
46188 bool link_state;
46189- atomic_t new_req_id;
46190+ atomic_unchecked_t new_req_id;
46191
46192 spinlock_t request_lock;
46193 struct list_head req_list;
46194diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46195index b54fd25..9bd2bae 100644
46196--- a/drivers/net/hyperv/rndis_filter.c
46197+++ b/drivers/net/hyperv/rndis_filter.c
46198@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46199 * template
46200 */
46201 set = &rndis_msg->msg.set_req;
46202- set->req_id = atomic_inc_return(&dev->new_req_id);
46203+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46204
46205 /* Add to the request list */
46206 spin_lock_irqsave(&dev->request_lock, flags);
46207@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46208
46209 /* Setup the rndis set */
46210 halt = &request->request_msg.msg.halt_req;
46211- halt->req_id = atomic_inc_return(&dev->new_req_id);
46212+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46213
46214 /* Ignore return since this msg is optional. */
46215 rndis_filter_send_request(dev, request);
46216diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46217index bf0d55e..82bcfbd1 100644
46218--- a/drivers/net/ieee802154/fakehard.c
46219+++ b/drivers/net/ieee802154/fakehard.c
46220@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46221 phy->transmit_power = 0xbf;
46222
46223 dev->netdev_ops = &fake_ops;
46224- dev->ml_priv = &fake_mlme;
46225+ dev->ml_priv = (void *)&fake_mlme;
46226
46227 priv = netdev_priv(dev);
46228 priv->phy = phy;
46229diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46230index 1831fb7..9c24bca 100644
46231--- a/drivers/net/macvlan.c
46232+++ b/drivers/net/macvlan.c
46233@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46234 int macvlan_link_register(struct rtnl_link_ops *ops)
46235 {
46236 /* common fields */
46237- ops->priv_size = sizeof(struct macvlan_dev);
46238- ops->validate = macvlan_validate;
46239- ops->maxtype = IFLA_MACVLAN_MAX;
46240- ops->policy = macvlan_policy;
46241- ops->changelink = macvlan_changelink;
46242- ops->get_size = macvlan_get_size;
46243- ops->fill_info = macvlan_fill_info;
46244+ pax_open_kernel();
46245+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46246+ *(void **)&ops->validate = macvlan_validate;
46247+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46248+ *(const void **)&ops->policy = macvlan_policy;
46249+ *(void **)&ops->changelink = macvlan_changelink;
46250+ *(void **)&ops->get_size = macvlan_get_size;
46251+ *(void **)&ops->fill_info = macvlan_fill_info;
46252+ pax_close_kernel();
46253
46254 return rtnl_link_register(ops);
46255 };
46256@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46257 return NOTIFY_DONE;
46258 }
46259
46260-static struct notifier_block macvlan_notifier_block __read_mostly = {
46261+static struct notifier_block macvlan_notifier_block = {
46262 .notifier_call = macvlan_device_event,
46263 };
46264
46265diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46266index ff111a8..c4c3ac4 100644
46267--- a/drivers/net/macvtap.c
46268+++ b/drivers/net/macvtap.c
46269@@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46270 }
46271
46272 ret = 0;
46273- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46274+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46275 put_user(q->flags, &ifr->ifr_flags))
46276 ret = -EFAULT;
46277 macvtap_put_vlan(vlan);
46278@@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46279 return NOTIFY_DONE;
46280 }
46281
46282-static struct notifier_block macvtap_notifier_block __read_mostly = {
46283+static struct notifier_block macvtap_notifier_block = {
46284 .notifier_call = macvtap_device_event,
46285 };
46286
46287diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46288index daec9b0..6428fcb 100644
46289--- a/drivers/net/phy/mdio-bitbang.c
46290+++ b/drivers/net/phy/mdio-bitbang.c
46291@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46292 struct mdiobb_ctrl *ctrl = bus->priv;
46293
46294 module_put(ctrl->ops->owner);
46295+ mdiobus_unregister(bus);
46296 mdiobus_free(bus);
46297 }
46298 EXPORT_SYMBOL(free_mdio_bitbang);
46299diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46300index 72ff14b..11d442d 100644
46301--- a/drivers/net/ppp/ppp_generic.c
46302+++ b/drivers/net/ppp/ppp_generic.c
46303@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46304 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46305 struct ppp_stats stats;
46306 struct ppp_comp_stats cstats;
46307- char *vers;
46308
46309 switch (cmd) {
46310 case SIOCGPPPSTATS:
46311@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46312 break;
46313
46314 case SIOCGPPPVER:
46315- vers = PPP_VERSION;
46316- if (copy_to_user(addr, vers, strlen(vers) + 1))
46317+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46318 break;
46319 err = 0;
46320 break;
46321diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46322index 1252d9c..80e660b 100644
46323--- a/drivers/net/slip/slhc.c
46324+++ b/drivers/net/slip/slhc.c
46325@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46326 register struct tcphdr *thp;
46327 register struct iphdr *ip;
46328 register struct cstate *cs;
46329- int len, hdrlen;
46330+ long len, hdrlen;
46331 unsigned char *cp = icp;
46332
46333 /* We've got a compressed packet; read the change byte */
46334diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46335index c8624a8..f0a4f6a 100644
46336--- a/drivers/net/team/team.c
46337+++ b/drivers/net/team/team.c
46338@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46339 return NOTIFY_DONE;
46340 }
46341
46342-static struct notifier_block team_notifier_block __read_mostly = {
46343+static struct notifier_block team_notifier_block = {
46344 .notifier_call = team_device_event,
46345 };
46346
46347diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46348index 26f8635..c237839 100644
46349--- a/drivers/net/tun.c
46350+++ b/drivers/net/tun.c
46351@@ -1876,7 +1876,7 @@ unlock:
46352 }
46353
46354 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46355- unsigned long arg, int ifreq_len)
46356+ unsigned long arg, size_t ifreq_len)
46357 {
46358 struct tun_file *tfile = file->private_data;
46359 struct tun_struct *tun;
46360@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46361 unsigned int ifindex;
46362 int ret;
46363
46364+ if (ifreq_len > sizeof ifr)
46365+ return -EFAULT;
46366+
46367 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46368 if (copy_from_user(&ifr, argp, ifreq_len))
46369 return -EFAULT;
46370diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
46371index d350d27..75d7d9d 100644
46372--- a/drivers/net/usb/cdc_ncm.c
46373+++ b/drivers/net/usb/cdc_ncm.c
46374@@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
46375 skb_out->len > CDC_NCM_MIN_TX_PKT)
46376 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
46377 ctx->tx_max - skb_out->len);
46378- else if ((skb_out->len % dev->maxpacket) == 0)
46379+ else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
46380 *skb_put(skb_out, 1) = 0; /* force short packet */
46381
46382 /* set final frame length */
46383diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46384index 660bd5e..ac59452 100644
46385--- a/drivers/net/usb/hso.c
46386+++ b/drivers/net/usb/hso.c
46387@@ -71,7 +71,7 @@
46388 #include <asm/byteorder.h>
46389 #include <linux/serial_core.h>
46390 #include <linux/serial.h>
46391-
46392+#include <asm/local.h>
46393
46394 #define MOD_AUTHOR "Option Wireless"
46395 #define MOD_DESCRIPTION "USB High Speed Option driver"
46396@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46397 struct urb *urb;
46398
46399 urb = serial->rx_urb[0];
46400- if (serial->port.count > 0) {
46401+ if (atomic_read(&serial->port.count) > 0) {
46402 count = put_rxbuf_data(urb, serial);
46403 if (count == -1)
46404 return;
46405@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46406 DUMP1(urb->transfer_buffer, urb->actual_length);
46407
46408 /* Anyone listening? */
46409- if (serial->port.count == 0)
46410+ if (atomic_read(&serial->port.count) == 0)
46411 return;
46412
46413 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46414@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46415 tty_port_tty_set(&serial->port, tty);
46416
46417 /* check for port already opened, if not set the termios */
46418- serial->port.count++;
46419- if (serial->port.count == 1) {
46420+ if (atomic_inc_return(&serial->port.count) == 1) {
46421 serial->rx_state = RX_IDLE;
46422 /* Force default termio settings */
46423 _hso_serial_set_termios(tty, NULL);
46424@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46425 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46426 if (result) {
46427 hso_stop_serial_device(serial->parent);
46428- serial->port.count--;
46429+ atomic_dec(&serial->port.count);
46430 kref_put(&serial->parent->ref, hso_serial_ref_free);
46431 }
46432 } else {
46433@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46434
46435 /* reset the rts and dtr */
46436 /* do the actual close */
46437- serial->port.count--;
46438+ atomic_dec(&serial->port.count);
46439
46440- if (serial->port.count <= 0) {
46441- serial->port.count = 0;
46442+ if (atomic_read(&serial->port.count) <= 0) {
46443+ atomic_set(&serial->port.count, 0);
46444 tty_port_tty_set(&serial->port, NULL);
46445 if (!usb_gone)
46446 hso_stop_serial_device(serial->parent);
46447@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46448
46449 /* the actual setup */
46450 spin_lock_irqsave(&serial->serial_lock, flags);
46451- if (serial->port.count)
46452+ if (atomic_read(&serial->port.count))
46453 _hso_serial_set_termios(tty, old);
46454 else
46455 tty->termios = *old;
46456@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46457 D1("Pending read interrupt on port %d\n", i);
46458 spin_lock(&serial->serial_lock);
46459 if (serial->rx_state == RX_IDLE &&
46460- serial->port.count > 0) {
46461+ atomic_read(&serial->port.count) > 0) {
46462 /* Setup and send a ctrl req read on
46463 * port i */
46464 if (!serial->rx_urb_filled[0]) {
46465@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46466 /* Start all serial ports */
46467 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46468 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46469- if (dev2ser(serial_table[i])->port.count) {
46470+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46471 result =
46472 hso_start_serial_device(serial_table[i], GFP_NOIO);
46473 hso_kick_transmit(dev2ser(serial_table[i]));
46474diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46475index adb12f3..48005ab 100644
46476--- a/drivers/net/usb/r8152.c
46477+++ b/drivers/net/usb/r8152.c
46478@@ -513,7 +513,7 @@ struct r8152 {
46479 void (*disable)(struct r8152 *);
46480 void (*down)(struct r8152 *);
46481 void (*unload)(struct r8152 *);
46482- } rtl_ops;
46483+ } __no_const rtl_ops;
46484
46485 int intr_interval;
46486 u32 msg_enable;
46487diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46488index a2515887..6d13233 100644
46489--- a/drivers/net/usb/sierra_net.c
46490+++ b/drivers/net/usb/sierra_net.c
46491@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46492 /* atomic counter partially included in MAC address to make sure 2 devices
46493 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46494 */
46495-static atomic_t iface_counter = ATOMIC_INIT(0);
46496+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46497
46498 /*
46499 * SYNC Timer Delay definition used to set the expiry time
46500@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46501 dev->net->netdev_ops = &sierra_net_device_ops;
46502
46503 /* change MAC addr to include, ifacenum, and to be unique */
46504- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46505+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46506 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46507
46508 /* we will have to manufacture ethernet headers, prepare template */
46509diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46510index d091e52..568bb179 100644
46511--- a/drivers/net/vxlan.c
46512+++ b/drivers/net/vxlan.c
46513@@ -2847,7 +2847,7 @@ nla_put_failure:
46514 return -EMSGSIZE;
46515 }
46516
46517-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46518+static struct rtnl_link_ops vxlan_link_ops = {
46519 .kind = "vxlan",
46520 .maxtype = IFLA_VXLAN_MAX,
46521 .policy = vxlan_policy,
46522@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46523 return NOTIFY_DONE;
46524 }
46525
46526-static struct notifier_block vxlan_notifier_block __read_mostly = {
46527+static struct notifier_block vxlan_notifier_block = {
46528 .notifier_call = vxlan_lowerdev_event,
46529 };
46530
46531diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46532index 5920c99..ff2e4a5 100644
46533--- a/drivers/net/wan/lmc/lmc_media.c
46534+++ b/drivers/net/wan/lmc/lmc_media.c
46535@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46536 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46537
46538 lmc_media_t lmc_ds3_media = {
46539- lmc_ds3_init, /* special media init stuff */
46540- lmc_ds3_default, /* reset to default state */
46541- lmc_ds3_set_status, /* reset status to state provided */
46542- lmc_dummy_set_1, /* set clock source */
46543- lmc_dummy_set2_1, /* set line speed */
46544- lmc_ds3_set_100ft, /* set cable length */
46545- lmc_ds3_set_scram, /* set scrambler */
46546- lmc_ds3_get_link_status, /* get link status */
46547- lmc_dummy_set_1, /* set link status */
46548- lmc_ds3_set_crc_length, /* set CRC length */
46549- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46550- lmc_ds3_watchdog
46551+ .init = lmc_ds3_init, /* special media init stuff */
46552+ .defaults = lmc_ds3_default, /* reset to default state */
46553+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46554+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46555+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46556+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46557+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46558+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46559+ .set_link_status = lmc_dummy_set_1, /* set link status */
46560+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46561+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46562+ .watchdog = lmc_ds3_watchdog
46563 };
46564
46565 lmc_media_t lmc_hssi_media = {
46566- lmc_hssi_init, /* special media init stuff */
46567- lmc_hssi_default, /* reset to default state */
46568- lmc_hssi_set_status, /* reset status to state provided */
46569- lmc_hssi_set_clock, /* set clock source */
46570- lmc_dummy_set2_1, /* set line speed */
46571- lmc_dummy_set_1, /* set cable length */
46572- lmc_dummy_set_1, /* set scrambler */
46573- lmc_hssi_get_link_status, /* get link status */
46574- lmc_hssi_set_link_status, /* set link status */
46575- lmc_hssi_set_crc_length, /* set CRC length */
46576- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46577- lmc_hssi_watchdog
46578+ .init = lmc_hssi_init, /* special media init stuff */
46579+ .defaults = lmc_hssi_default, /* reset to default state */
46580+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46581+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46582+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46583+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46584+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46585+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46586+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46587+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46588+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46589+ .watchdog = lmc_hssi_watchdog
46590 };
46591
46592-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46593- lmc_ssi_default, /* reset to default state */
46594- lmc_ssi_set_status, /* reset status to state provided */
46595- lmc_ssi_set_clock, /* set clock source */
46596- lmc_ssi_set_speed, /* set line speed */
46597- lmc_dummy_set_1, /* set cable length */
46598- lmc_dummy_set_1, /* set scrambler */
46599- lmc_ssi_get_link_status, /* get link status */
46600- lmc_ssi_set_link_status, /* set link status */
46601- lmc_ssi_set_crc_length, /* set CRC length */
46602- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46603- lmc_ssi_watchdog
46604+lmc_media_t lmc_ssi_media = {
46605+ .init = lmc_ssi_init, /* special media init stuff */
46606+ .defaults = lmc_ssi_default, /* reset to default state */
46607+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46608+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46609+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46610+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46611+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46612+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46613+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46614+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46615+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46616+ .watchdog = lmc_ssi_watchdog
46617 };
46618
46619 lmc_media_t lmc_t1_media = {
46620- lmc_t1_init, /* special media init stuff */
46621- lmc_t1_default, /* reset to default state */
46622- lmc_t1_set_status, /* reset status to state provided */
46623- lmc_t1_set_clock, /* set clock source */
46624- lmc_dummy_set2_1, /* set line speed */
46625- lmc_dummy_set_1, /* set cable length */
46626- lmc_dummy_set_1, /* set scrambler */
46627- lmc_t1_get_link_status, /* get link status */
46628- lmc_dummy_set_1, /* set link status */
46629- lmc_t1_set_crc_length, /* set CRC length */
46630- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46631- lmc_t1_watchdog
46632+ .init = lmc_t1_init, /* special media init stuff */
46633+ .defaults = lmc_t1_default, /* reset to default state */
46634+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46635+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46636+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46637+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46638+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46639+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46640+ .set_link_status = lmc_dummy_set_1, /* set link status */
46641+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46642+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46643+ .watchdog = lmc_t1_watchdog
46644 };
46645
46646 static void
46647diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46648index feacc3b..5bac0de 100644
46649--- a/drivers/net/wan/z85230.c
46650+++ b/drivers/net/wan/z85230.c
46651@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46652
46653 struct z8530_irqhandler z8530_sync =
46654 {
46655- z8530_rx,
46656- z8530_tx,
46657- z8530_status
46658+ .rx = z8530_rx,
46659+ .tx = z8530_tx,
46660+ .status = z8530_status
46661 };
46662
46663 EXPORT_SYMBOL(z8530_sync);
46664@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46665 }
46666
46667 static struct z8530_irqhandler z8530_dma_sync = {
46668- z8530_dma_rx,
46669- z8530_dma_tx,
46670- z8530_dma_status
46671+ .rx = z8530_dma_rx,
46672+ .tx = z8530_dma_tx,
46673+ .status = z8530_dma_status
46674 };
46675
46676 static struct z8530_irqhandler z8530_txdma_sync = {
46677- z8530_rx,
46678- z8530_dma_tx,
46679- z8530_dma_status
46680+ .rx = z8530_rx,
46681+ .tx = z8530_dma_tx,
46682+ .status = z8530_dma_status
46683 };
46684
46685 /**
46686@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46687
46688 struct z8530_irqhandler z8530_nop=
46689 {
46690- z8530_rx_clear,
46691- z8530_tx_clear,
46692- z8530_status_clear
46693+ .rx = z8530_rx_clear,
46694+ .tx = z8530_tx_clear,
46695+ .status = z8530_status_clear
46696 };
46697
46698
46699diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46700index 0b60295..b8bfa5b 100644
46701--- a/drivers/net/wimax/i2400m/rx.c
46702+++ b/drivers/net/wimax/i2400m/rx.c
46703@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46704 if (i2400m->rx_roq == NULL)
46705 goto error_roq_alloc;
46706
46707- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46708+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46709 GFP_KERNEL);
46710 if (rd == NULL) {
46711 result = -ENOMEM;
46712diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46713index edf4b57..68b51c0 100644
46714--- a/drivers/net/wireless/airo.c
46715+++ b/drivers/net/wireless/airo.c
46716@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46717 struct airo_info *ai = dev->ml_priv;
46718 int ridcode;
46719 int enabled;
46720- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46721+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46722 unsigned char *iobuf;
46723
46724 /* Only super-user can write RIDs */
46725diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46726index 99b3bfa..9559372 100644
46727--- a/drivers/net/wireless/at76c50x-usb.c
46728+++ b/drivers/net/wireless/at76c50x-usb.c
46729@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46730 }
46731
46732 /* Convert timeout from the DFU status to jiffies */
46733-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46734+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46735 {
46736 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46737 | (s->poll_timeout[1] << 8)
46738diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46739index edc57ab..ff49e0a 100644
46740--- a/drivers/net/wireless/ath/ath10k/htc.c
46741+++ b/drivers/net/wireless/ath/ath10k/htc.c
46742@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46743 /* registered target arrival callback from the HIF layer */
46744 int ath10k_htc_init(struct ath10k *ar)
46745 {
46746- struct ath10k_hif_cb htc_callbacks;
46747+ static struct ath10k_hif_cb htc_callbacks = {
46748+ .rx_completion = ath10k_htc_rx_completion_handler,
46749+ .tx_completion = ath10k_htc_tx_completion_handler,
46750+ };
46751 struct ath10k_htc_ep *ep = NULL;
46752 struct ath10k_htc *htc = &ar->htc;
46753
46754@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
46755 ath10k_htc_reset_endpoint_states(htc);
46756
46757 /* setup HIF layer callbacks */
46758- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46759- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46760 htc->ar = ar;
46761
46762 /* Get HIF default pipe for HTC message exchange */
46763diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46764index 4716d33..a688310 100644
46765--- a/drivers/net/wireless/ath/ath10k/htc.h
46766+++ b/drivers/net/wireless/ath/ath10k/htc.h
46767@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46768
46769 struct ath10k_htc_ops {
46770 void (*target_send_suspend_complete)(struct ath10k *ar);
46771-};
46772+} __no_const;
46773
46774 struct ath10k_htc_ep_ops {
46775 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46776 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46777 void (*ep_tx_credits)(struct ath10k *);
46778-};
46779+} __no_const;
46780
46781 /* service connection information */
46782 struct ath10k_htc_svc_conn_req {
46783diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46784index 741b38d..b7ae41b 100644
46785--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46786+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46787@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46788 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46789 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46790
46791- ACCESS_ONCE(ads->ds_link) = i->link;
46792- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46793+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46794+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46795
46796 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46797 ctl6 = SM(i->keytype, AR_EncrType);
46798@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46799
46800 if ((i->is_first || i->is_last) &&
46801 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46802- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46803+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46804 | set11nTries(i->rates, 1)
46805 | set11nTries(i->rates, 2)
46806 | set11nTries(i->rates, 3)
46807 | (i->dur_update ? AR_DurUpdateEna : 0)
46808 | SM(0, AR_BurstDur);
46809
46810- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46811+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46812 | set11nRate(i->rates, 1)
46813 | set11nRate(i->rates, 2)
46814 | set11nRate(i->rates, 3);
46815 } else {
46816- ACCESS_ONCE(ads->ds_ctl2) = 0;
46817- ACCESS_ONCE(ads->ds_ctl3) = 0;
46818+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46819+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46820 }
46821
46822 if (!i->is_first) {
46823- ACCESS_ONCE(ads->ds_ctl0) = 0;
46824- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46825- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46826+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46827+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46828+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46829 return;
46830 }
46831
46832@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46833 break;
46834 }
46835
46836- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46837+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46838 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46839 | SM(i->txpower, AR_XmitPower)
46840 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46841@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46842 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46843 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46844
46845- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46846- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46847+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46848+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46849
46850 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46851 return;
46852
46853- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46854+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46855 | set11nPktDurRTSCTS(i->rates, 1);
46856
46857- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46858+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46859 | set11nPktDurRTSCTS(i->rates, 3);
46860
46861- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46862+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46863 | set11nRateFlags(i->rates, 1)
46864 | set11nRateFlags(i->rates, 2)
46865 | set11nRateFlags(i->rates, 3)
46866diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46867index 729ffbf..49f50e3 100644
46868--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46869+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46870@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46871 (i->qcu << AR_TxQcuNum_S) | desc_len;
46872
46873 checksum += val;
46874- ACCESS_ONCE(ads->info) = val;
46875+ ACCESS_ONCE_RW(ads->info) = val;
46876
46877 checksum += i->link;
46878- ACCESS_ONCE(ads->link) = i->link;
46879+ ACCESS_ONCE_RW(ads->link) = i->link;
46880
46881 checksum += i->buf_addr[0];
46882- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46883+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46884 checksum += i->buf_addr[1];
46885- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46886+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46887 checksum += i->buf_addr[2];
46888- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46889+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46890 checksum += i->buf_addr[3];
46891- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46892+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46893
46894 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46895- ACCESS_ONCE(ads->ctl3) = val;
46896+ ACCESS_ONCE_RW(ads->ctl3) = val;
46897 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46898- ACCESS_ONCE(ads->ctl5) = val;
46899+ ACCESS_ONCE_RW(ads->ctl5) = val;
46900 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46901- ACCESS_ONCE(ads->ctl7) = val;
46902+ ACCESS_ONCE_RW(ads->ctl7) = val;
46903 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46904- ACCESS_ONCE(ads->ctl9) = val;
46905+ ACCESS_ONCE_RW(ads->ctl9) = val;
46906
46907 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46908- ACCESS_ONCE(ads->ctl10) = checksum;
46909+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46910
46911 if (i->is_first || i->is_last) {
46912- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46913+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46914 | set11nTries(i->rates, 1)
46915 | set11nTries(i->rates, 2)
46916 | set11nTries(i->rates, 3)
46917 | (i->dur_update ? AR_DurUpdateEna : 0)
46918 | SM(0, AR_BurstDur);
46919
46920- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46921+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46922 | set11nRate(i->rates, 1)
46923 | set11nRate(i->rates, 2)
46924 | set11nRate(i->rates, 3);
46925 } else {
46926- ACCESS_ONCE(ads->ctl13) = 0;
46927- ACCESS_ONCE(ads->ctl14) = 0;
46928+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46929+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46930 }
46931
46932 ads->ctl20 = 0;
46933@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46934
46935 ctl17 = SM(i->keytype, AR_EncrType);
46936 if (!i->is_first) {
46937- ACCESS_ONCE(ads->ctl11) = 0;
46938- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46939- ACCESS_ONCE(ads->ctl15) = 0;
46940- ACCESS_ONCE(ads->ctl16) = 0;
46941- ACCESS_ONCE(ads->ctl17) = ctl17;
46942- ACCESS_ONCE(ads->ctl18) = 0;
46943- ACCESS_ONCE(ads->ctl19) = 0;
46944+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46945+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46946+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46947+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46948+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46949+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46950+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46951 return;
46952 }
46953
46954- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46955+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46956 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46957 | SM(i->txpower, AR_XmitPower)
46958 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46959@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46960 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46961 ctl12 |= SM(val, AR_PAPRDChainMask);
46962
46963- ACCESS_ONCE(ads->ctl12) = ctl12;
46964- ACCESS_ONCE(ads->ctl17) = ctl17;
46965+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46966+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46967
46968- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46969+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46970 | set11nPktDurRTSCTS(i->rates, 1);
46971
46972- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46973+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46974 | set11nPktDurRTSCTS(i->rates, 3);
46975
46976- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46977+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46978 | set11nRateFlags(i->rates, 1)
46979 | set11nRateFlags(i->rates, 2)
46980 | set11nRateFlags(i->rates, 3)
46981 | SM(i->rtscts_rate, AR_RTSCTSRate);
46982
46983- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46984+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46985 }
46986
46987 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46988diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46989index 0acd4b5..0591c91 100644
46990--- a/drivers/net/wireless/ath/ath9k/hw.h
46991+++ b/drivers/net/wireless/ath/ath9k/hw.h
46992@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46993
46994 /* ANI */
46995 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46996-};
46997+} __no_const;
46998
46999 /**
47000 * struct ath_spec_scan - parameters for Atheros spectral scan
47001@@ -706,7 +706,7 @@ struct ath_hw_ops {
47002 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47003 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47004 #endif
47005-};
47006+} __no_const;
47007
47008 struct ath_nf_limits {
47009 s16 max;
47010diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47011index 92190da..f3a4c4c 100644
47012--- a/drivers/net/wireless/b43/phy_lp.c
47013+++ b/drivers/net/wireless/b43/phy_lp.c
47014@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47015 {
47016 struct ssb_bus *bus = dev->dev->sdev->bus;
47017
47018- static const struct b206x_channel *chandata = NULL;
47019+ const struct b206x_channel *chandata = NULL;
47020 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47021 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47022 u16 old_comm15, scale;
47023diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47024index 0487461..fd9e84a 100644
47025--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47026+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47027@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47028 */
47029 if (il3945_mod_params.disable_hw_scan) {
47030 D_INFO("Disabling hw_scan\n");
47031- il3945_mac_ops.hw_scan = NULL;
47032+ pax_open_kernel();
47033+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47034+ pax_close_kernel();
47035 }
47036
47037 D_INFO("*** LOAD DRIVER ***\n");
47038diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47039index d2fe259..0c4c682 100644
47040--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47041+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47042@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47043 {
47044 struct iwl_priv *priv = file->private_data;
47045 char buf[64];
47046- int buf_size;
47047+ size_t buf_size;
47048 u32 offset, len;
47049
47050 memset(buf, 0, sizeof(buf));
47051@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47052 struct iwl_priv *priv = file->private_data;
47053
47054 char buf[8];
47055- int buf_size;
47056+ size_t buf_size;
47057 u32 reset_flag;
47058
47059 memset(buf, 0, sizeof(buf));
47060@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47061 {
47062 struct iwl_priv *priv = file->private_data;
47063 char buf[8];
47064- int buf_size;
47065+ size_t buf_size;
47066 int ht40;
47067
47068 memset(buf, 0, sizeof(buf));
47069@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47070 {
47071 struct iwl_priv *priv = file->private_data;
47072 char buf[8];
47073- int buf_size;
47074+ size_t buf_size;
47075 int value;
47076
47077 memset(buf, 0, sizeof(buf));
47078@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47079 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47080 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47081
47082-static const char *fmt_value = " %-30s %10u\n";
47083-static const char *fmt_hex = " %-30s 0x%02X\n";
47084-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47085-static const char *fmt_header =
47086+static const char fmt_value[] = " %-30s %10u\n";
47087+static const char fmt_hex[] = " %-30s 0x%02X\n";
47088+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47089+static const char fmt_header[] =
47090 "%-32s current cumulative delta max\n";
47091
47092 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47093@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47094 {
47095 struct iwl_priv *priv = file->private_data;
47096 char buf[8];
47097- int buf_size;
47098+ size_t buf_size;
47099 int clear;
47100
47101 memset(buf, 0, sizeof(buf));
47102@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47103 {
47104 struct iwl_priv *priv = file->private_data;
47105 char buf[8];
47106- int buf_size;
47107+ size_t buf_size;
47108 int trace;
47109
47110 memset(buf, 0, sizeof(buf));
47111@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47112 {
47113 struct iwl_priv *priv = file->private_data;
47114 char buf[8];
47115- int buf_size;
47116+ size_t buf_size;
47117 int missed;
47118
47119 memset(buf, 0, sizeof(buf));
47120@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47121
47122 struct iwl_priv *priv = file->private_data;
47123 char buf[8];
47124- int buf_size;
47125+ size_t buf_size;
47126 int plcp;
47127
47128 memset(buf, 0, sizeof(buf));
47129@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47130
47131 struct iwl_priv *priv = file->private_data;
47132 char buf[8];
47133- int buf_size;
47134+ size_t buf_size;
47135 int flush;
47136
47137 memset(buf, 0, sizeof(buf));
47138@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47139
47140 struct iwl_priv *priv = file->private_data;
47141 char buf[8];
47142- int buf_size;
47143+ size_t buf_size;
47144 int rts;
47145
47146 if (!priv->cfg->ht_params)
47147@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47148 {
47149 struct iwl_priv *priv = file->private_data;
47150 char buf[8];
47151- int buf_size;
47152+ size_t buf_size;
47153
47154 memset(buf, 0, sizeof(buf));
47155 buf_size = min(count, sizeof(buf) - 1);
47156@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47157 struct iwl_priv *priv = file->private_data;
47158 u32 event_log_flag;
47159 char buf[8];
47160- int buf_size;
47161+ size_t buf_size;
47162
47163 /* check that the interface is up */
47164 if (!iwl_is_ready(priv))
47165@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47166 struct iwl_priv *priv = file->private_data;
47167 char buf[8];
47168 u32 calib_disabled;
47169- int buf_size;
47170+ size_t buf_size;
47171
47172 memset(buf, 0, sizeof(buf));
47173 buf_size = min(count, sizeof(buf) - 1);
47174diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47175index ba1b1ea..0ff7e98 100644
47176--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47177+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47178@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47179 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47180 {
47181 struct iwl_nvm_data *data = priv->nvm_data;
47182- char *debug_msg;
47183+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47184
47185 if (data->sku_cap_11n_enable &&
47186 !priv->cfg->ht_params) {
47187@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47188 return -EINVAL;
47189 }
47190
47191- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47192 IWL_DEBUG_INFO(priv, debug_msg,
47193 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47194 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47195diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47196index f950780..be9df93 100644
47197--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47198+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47199@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47200 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47201
47202 char buf[8];
47203- int buf_size;
47204+ size_t buf_size;
47205 u32 reset_flag;
47206
47207 memset(buf, 0, sizeof(buf));
47208@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47209 {
47210 struct iwl_trans *trans = file->private_data;
47211 char buf[8];
47212- int buf_size;
47213+ size_t buf_size;
47214 int csr;
47215
47216 memset(buf, 0, sizeof(buf));
47217diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47218index 69d4c31..bd0b316 100644
47219--- a/drivers/net/wireless/mac80211_hwsim.c
47220+++ b/drivers/net/wireless/mac80211_hwsim.c
47221@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47222 if (channels < 1)
47223 return -EINVAL;
47224
47225- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47226- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47227- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47228- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47229- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47230- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47231- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47232- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47233- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47234- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47235- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47236- mac80211_hwsim_assign_vif_chanctx;
47237- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47238- mac80211_hwsim_unassign_vif_chanctx;
47239+ pax_open_kernel();
47240+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47241+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47242+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47243+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47244+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47245+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47246+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47247+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47248+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47249+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47250+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47251+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47252+ pax_close_kernel();
47253
47254 spin_lock_init(&hwsim_radio_lock);
47255 INIT_LIST_HEAD(&hwsim_radios);
47256diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47257index 5028557..91cf394 100644
47258--- a/drivers/net/wireless/rndis_wlan.c
47259+++ b/drivers/net/wireless/rndis_wlan.c
47260@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47261
47262 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47263
47264- if (rts_threshold < 0 || rts_threshold > 2347)
47265+ if (rts_threshold > 2347)
47266 rts_threshold = 2347;
47267
47268 tmp = cpu_to_le32(rts_threshold);
47269diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47270index e3b885d..7a7de2f 100644
47271--- a/drivers/net/wireless/rt2x00/rt2x00.h
47272+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47273@@ -375,7 +375,7 @@ struct rt2x00_intf {
47274 * for hardware which doesn't support hardware
47275 * sequence counting.
47276 */
47277- atomic_t seqno;
47278+ atomic_unchecked_t seqno;
47279 };
47280
47281 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47282diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47283index 5642ccc..01f03eb 100644
47284--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47285+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47286@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47287 * sequence counter given by mac80211.
47288 */
47289 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47290- seqno = atomic_add_return(0x10, &intf->seqno);
47291+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47292 else
47293- seqno = atomic_read(&intf->seqno);
47294+ seqno = atomic_read_unchecked(&intf->seqno);
47295
47296 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47297 hdr->seq_ctrl |= cpu_to_le16(seqno);
47298diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47299index e2b3d9c..67a5184 100644
47300--- a/drivers/net/wireless/ti/wl1251/sdio.c
47301+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47302@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47303
47304 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47305
47306- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47307- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47308+ pax_open_kernel();
47309+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47310+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47311+ pax_close_kernel();
47312
47313 wl1251_info("using dedicated interrupt line");
47314 } else {
47315- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47316- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47317+ pax_open_kernel();
47318+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47319+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47320+ pax_close_kernel();
47321
47322 wl1251_info("using SDIO interrupt");
47323 }
47324diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47325index be7129b..4161356 100644
47326--- a/drivers/net/wireless/ti/wl12xx/main.c
47327+++ b/drivers/net/wireless/ti/wl12xx/main.c
47328@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47329 sizeof(wl->conf.mem));
47330
47331 /* read data preparation is only needed by wl127x */
47332- wl->ops->prepare_read = wl127x_prepare_read;
47333+ pax_open_kernel();
47334+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47335+ pax_close_kernel();
47336
47337 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47338 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47339@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47340 sizeof(wl->conf.mem));
47341
47342 /* read data preparation is only needed by wl127x */
47343- wl->ops->prepare_read = wl127x_prepare_read;
47344+ pax_open_kernel();
47345+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47346+ pax_close_kernel();
47347
47348 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47349 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47350diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47351index ec37b16..7e34d66 100644
47352--- a/drivers/net/wireless/ti/wl18xx/main.c
47353+++ b/drivers/net/wireless/ti/wl18xx/main.c
47354@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47355 }
47356
47357 if (!checksum_param) {
47358- wl18xx_ops.set_rx_csum = NULL;
47359- wl18xx_ops.init_vif = NULL;
47360+ pax_open_kernel();
47361+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47362+ *(void **)&wl18xx_ops.init_vif = NULL;
47363+ pax_close_kernel();
47364 }
47365
47366 /* Enable 11a Band only if we have 5G antennas */
47367diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47368index a912dc0..a8225ba 100644
47369--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47370+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47371@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47372 {
47373 struct zd_usb *usb = urb->context;
47374 struct zd_usb_interrupt *intr = &usb->intr;
47375- int len;
47376+ unsigned int len;
47377 u16 int_num;
47378
47379 ZD_ASSERT(in_interrupt());
47380diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47381index 683671a..4519fc2 100644
47382--- a/drivers/nfc/nfcwilink.c
47383+++ b/drivers/nfc/nfcwilink.c
47384@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47385
47386 static int nfcwilink_probe(struct platform_device *pdev)
47387 {
47388- static struct nfcwilink *drv;
47389+ struct nfcwilink *drv;
47390 int rc;
47391 __u32 protocols;
47392
47393diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47394index d93b2b6..ae50401 100644
47395--- a/drivers/oprofile/buffer_sync.c
47396+++ b/drivers/oprofile/buffer_sync.c
47397@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47398 if (cookie == NO_COOKIE)
47399 offset = pc;
47400 if (cookie == INVALID_COOKIE) {
47401- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47402+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47403 offset = pc;
47404 }
47405 if (cookie != last_cookie) {
47406@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47407 /* add userspace sample */
47408
47409 if (!mm) {
47410- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47411+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47412 return 0;
47413 }
47414
47415 cookie = lookup_dcookie(mm, s->eip, &offset);
47416
47417 if (cookie == INVALID_COOKIE) {
47418- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47419+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47420 return 0;
47421 }
47422
47423@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47424 /* ignore backtraces if failed to add a sample */
47425 if (state == sb_bt_start) {
47426 state = sb_bt_ignore;
47427- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47428+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47429 }
47430 }
47431 release_mm(mm);
47432diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47433index c0cc4e7..44d4e54 100644
47434--- a/drivers/oprofile/event_buffer.c
47435+++ b/drivers/oprofile/event_buffer.c
47436@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47437 }
47438
47439 if (buffer_pos == buffer_size) {
47440- atomic_inc(&oprofile_stats.event_lost_overflow);
47441+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47442 return;
47443 }
47444
47445diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47446index ed2c3ec..deda85a 100644
47447--- a/drivers/oprofile/oprof.c
47448+++ b/drivers/oprofile/oprof.c
47449@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47450 if (oprofile_ops.switch_events())
47451 return;
47452
47453- atomic_inc(&oprofile_stats.multiplex_counter);
47454+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47455 start_switch_worker();
47456 }
47457
47458diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47459index ee2cfce..7f8f699 100644
47460--- a/drivers/oprofile/oprofile_files.c
47461+++ b/drivers/oprofile/oprofile_files.c
47462@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47463
47464 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47465
47466-static ssize_t timeout_read(struct file *file, char __user *buf,
47467+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47468 size_t count, loff_t *offset)
47469 {
47470 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47471diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47472index 59659ce..6c860a0 100644
47473--- a/drivers/oprofile/oprofile_stats.c
47474+++ b/drivers/oprofile/oprofile_stats.c
47475@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47476 cpu_buf->sample_invalid_eip = 0;
47477 }
47478
47479- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47480- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47481- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47482- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47483- atomic_set(&oprofile_stats.multiplex_counter, 0);
47484+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47485+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47486+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47487+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47488+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47489 }
47490
47491
47492diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47493index 1fc622b..8c48fc3 100644
47494--- a/drivers/oprofile/oprofile_stats.h
47495+++ b/drivers/oprofile/oprofile_stats.h
47496@@ -13,11 +13,11 @@
47497 #include <linux/atomic.h>
47498
47499 struct oprofile_stat_struct {
47500- atomic_t sample_lost_no_mm;
47501- atomic_t sample_lost_no_mapping;
47502- atomic_t bt_lost_no_mapping;
47503- atomic_t event_lost_overflow;
47504- atomic_t multiplex_counter;
47505+ atomic_unchecked_t sample_lost_no_mm;
47506+ atomic_unchecked_t sample_lost_no_mapping;
47507+ atomic_unchecked_t bt_lost_no_mapping;
47508+ atomic_unchecked_t event_lost_overflow;
47509+ atomic_unchecked_t multiplex_counter;
47510 };
47511
47512 extern struct oprofile_stat_struct oprofile_stats;
47513diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47514index 3f49345..c750d0b 100644
47515--- a/drivers/oprofile/oprofilefs.c
47516+++ b/drivers/oprofile/oprofilefs.c
47517@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47518
47519 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47520 {
47521- atomic_t *val = file->private_data;
47522- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47523+ atomic_unchecked_t *val = file->private_data;
47524+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47525 }
47526
47527
47528@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47529
47530
47531 int oprofilefs_create_ro_atomic(struct dentry *root,
47532- char const *name, atomic_t *val)
47533+ char const *name, atomic_unchecked_t *val)
47534 {
47535 return __oprofilefs_create_file(root, name,
47536 &atomic_ro_fops, 0444, val);
47537diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47538index 61be1d9..dec05d7 100644
47539--- a/drivers/oprofile/timer_int.c
47540+++ b/drivers/oprofile/timer_int.c
47541@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47542 return NOTIFY_OK;
47543 }
47544
47545-static struct notifier_block __refdata oprofile_cpu_notifier = {
47546+static struct notifier_block oprofile_cpu_notifier = {
47547 .notifier_call = oprofile_cpu_notify,
47548 };
47549
47550diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47551index 92ed045..62d39bd7 100644
47552--- a/drivers/parport/procfs.c
47553+++ b/drivers/parport/procfs.c
47554@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47555
47556 *ppos += len;
47557
47558- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47559+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47560 }
47561
47562 #ifdef CONFIG_PARPORT_1284
47563@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47564
47565 *ppos += len;
47566
47567- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47568+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47569 }
47570 #endif /* IEEE1284.3 support. */
47571
47572diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47573index 8dcccff..35d701d 100644
47574--- a/drivers/pci/hotplug/acpiphp_ibm.c
47575+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47576@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47577 goto init_cleanup;
47578 }
47579
47580- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47581+ pax_open_kernel();
47582+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47583+ pax_close_kernel();
47584 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47585
47586 return retval;
47587diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47588index 7536eef..52dc8fa 100644
47589--- a/drivers/pci/hotplug/cpcihp_generic.c
47590+++ b/drivers/pci/hotplug/cpcihp_generic.c
47591@@ -73,7 +73,6 @@ static u16 port;
47592 static unsigned int enum_bit;
47593 static u8 enum_mask;
47594
47595-static struct cpci_hp_controller_ops generic_hpc_ops;
47596 static struct cpci_hp_controller generic_hpc;
47597
47598 static int __init validate_parameters(void)
47599@@ -139,6 +138,10 @@ static int query_enum(void)
47600 return ((value & enum_mask) == enum_mask);
47601 }
47602
47603+static struct cpci_hp_controller_ops generic_hpc_ops = {
47604+ .query_enum = query_enum,
47605+};
47606+
47607 static int __init cpcihp_generic_init(void)
47608 {
47609 int status;
47610@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47611 pci_dev_put(dev);
47612
47613 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47614- generic_hpc_ops.query_enum = query_enum;
47615 generic_hpc.ops = &generic_hpc_ops;
47616
47617 status = cpci_hp_register_controller(&generic_hpc);
47618diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47619index e8c4a7c..7046f5c 100644
47620--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47621+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47622@@ -59,7 +59,6 @@
47623 /* local variables */
47624 static bool debug;
47625 static bool poll;
47626-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47627 static struct cpci_hp_controller zt5550_hpc;
47628
47629 /* Primary cPCI bus bridge device */
47630@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47631 return 0;
47632 }
47633
47634+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47635+ .query_enum = zt5550_hc_query_enum,
47636+};
47637+
47638 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47639 {
47640 int status;
47641@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47642 dbg("returned from zt5550_hc_config");
47643
47644 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47645- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47646 zt5550_hpc.ops = &zt5550_hpc_ops;
47647 if(!poll) {
47648 zt5550_hpc.irq = hc_dev->irq;
47649 zt5550_hpc.irq_flags = IRQF_SHARED;
47650 zt5550_hpc.dev_id = hc_dev;
47651
47652- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47653- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47654- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47655+ pax_open_kernel();
47656+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47657+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47658+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47659+ pax_open_kernel();
47660 } else {
47661 info("using ENUM# polling mode");
47662 }
47663diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47664index 76ba8a1..20ca857 100644
47665--- a/drivers/pci/hotplug/cpqphp_nvram.c
47666+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47667@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47668
47669 void compaq_nvram_init (void __iomem *rom_start)
47670 {
47671+
47672+#ifndef CONFIG_PAX_KERNEXEC
47673 if (rom_start) {
47674 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47675 }
47676+#endif
47677+
47678 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47679
47680 /* initialize our int15 lock */
47681diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47682index cfa92a9..29539c5 100644
47683--- a/drivers/pci/hotplug/pci_hotplug_core.c
47684+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47685@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47686 return -EINVAL;
47687 }
47688
47689- slot->ops->owner = owner;
47690- slot->ops->mod_name = mod_name;
47691+ pax_open_kernel();
47692+ *(struct module **)&slot->ops->owner = owner;
47693+ *(const char **)&slot->ops->mod_name = mod_name;
47694+ pax_close_kernel();
47695
47696 mutex_lock(&pci_hp_mutex);
47697 /*
47698diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47699index 53b58de..4479896 100644
47700--- a/drivers/pci/hotplug/pciehp_core.c
47701+++ b/drivers/pci/hotplug/pciehp_core.c
47702@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47703 struct slot *slot = ctrl->slot;
47704 struct hotplug_slot *hotplug = NULL;
47705 struct hotplug_slot_info *info = NULL;
47706- struct hotplug_slot_ops *ops = NULL;
47707+ hotplug_slot_ops_no_const *ops = NULL;
47708 char name[SLOT_NAME_SIZE];
47709 int retval = -ENOMEM;
47710
47711diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47712index 955ab79..d1df9c7 100644
47713--- a/drivers/pci/msi.c
47714+++ b/drivers/pci/msi.c
47715@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47716 {
47717 struct attribute **msi_attrs;
47718 struct attribute *msi_attr;
47719- struct device_attribute *msi_dev_attr;
47720- struct attribute_group *msi_irq_group;
47721+ device_attribute_no_const *msi_dev_attr;
47722+ attribute_group_no_const *msi_irq_group;
47723 const struct attribute_group **msi_irq_groups;
47724 struct msi_desc *entry;
47725 int ret = -ENOMEM;
47726@@ -589,7 +589,7 @@ error_attrs:
47727 count = 0;
47728 msi_attr = msi_attrs[count];
47729 while (msi_attr) {
47730- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47731+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47732 kfree(msi_attr->name);
47733 kfree(msi_dev_attr);
47734 ++count;
47735diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47736index 276ef9c..1d33a36 100644
47737--- a/drivers/pci/pci-sysfs.c
47738+++ b/drivers/pci/pci-sysfs.c
47739@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47740 {
47741 /* allocate attribute structure, piggyback attribute name */
47742 int name_len = write_combine ? 13 : 10;
47743- struct bin_attribute *res_attr;
47744+ bin_attribute_no_const *res_attr;
47745 int retval;
47746
47747 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47748@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47749 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47750 {
47751 int retval;
47752- struct bin_attribute *attr;
47753+ bin_attribute_no_const *attr;
47754
47755 /* If the device has VPD, try to expose it in sysfs. */
47756 if (dev->vpd) {
47757@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47758 {
47759 int retval;
47760 int rom_size = 0;
47761- struct bin_attribute *attr;
47762+ bin_attribute_no_const *attr;
47763
47764 if (!sysfs_initialized)
47765 return -EACCES;
47766diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47767index 4df38df..b6bb7fe 100644
47768--- a/drivers/pci/pci.h
47769+++ b/drivers/pci/pci.h
47770@@ -93,7 +93,7 @@ struct pci_vpd_ops {
47771 struct pci_vpd {
47772 unsigned int len;
47773 const struct pci_vpd_ops *ops;
47774- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47775+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47776 };
47777
47778 int pci_vpd_pci22_init(struct pci_dev *dev);
47779diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47780index e1e7026..d28dd33 100644
47781--- a/drivers/pci/pcie/aspm.c
47782+++ b/drivers/pci/pcie/aspm.c
47783@@ -27,9 +27,9 @@
47784 #define MODULE_PARAM_PREFIX "pcie_aspm."
47785
47786 /* Note: those are not register definitions */
47787-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47788-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47789-#define ASPM_STATE_L1 (4) /* L1 state */
47790+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47791+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47792+#define ASPM_STATE_L1 (4U) /* L1 state */
47793 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47794 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47795
47796diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47797index 6e34498..9911975 100644
47798--- a/drivers/pci/probe.c
47799+++ b/drivers/pci/probe.c
47800@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47801 struct pci_bus_region region, inverted_region;
47802 bool bar_too_big = false, bar_disabled = false;
47803
47804- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47805+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47806
47807 /* No printks while decoding is disabled! */
47808 if (!dev->mmio_always_on) {
47809diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47810index 46d1378..30e452b 100644
47811--- a/drivers/pci/proc.c
47812+++ b/drivers/pci/proc.c
47813@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47814 static int __init pci_proc_init(void)
47815 {
47816 struct pci_dev *dev = NULL;
47817+
47818+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47819+#ifdef CONFIG_GRKERNSEC_PROC_USER
47820+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47821+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47822+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47823+#endif
47824+#else
47825 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47826+#endif
47827 proc_create("devices", 0, proc_bus_pci_dir,
47828 &proc_bus_pci_dev_operations);
47829 proc_initialized = 1;
47830diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47831index 7f3aad0..7d604bb 100644
47832--- a/drivers/platform/chrome/chromeos_laptop.c
47833+++ b/drivers/platform/chrome/chromeos_laptop.c
47834@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47835 .callback = chromeos_laptop_dmi_matched, \
47836 .driver_data = (void *)&board_
47837
47838-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47839+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47840 {
47841 .ident = "Samsung Series 5 550",
47842 .matches = {
47843diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47844index c5e082f..d6307a0 100644
47845--- a/drivers/platform/x86/asus-wmi.c
47846+++ b/drivers/platform/x86/asus-wmi.c
47847@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47848 int err;
47849 u32 retval = -1;
47850
47851+#ifdef CONFIG_GRKERNSEC_KMEM
47852+ return -EPERM;
47853+#endif
47854+
47855 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47856
47857 if (err < 0)
47858@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47859 int err;
47860 u32 retval = -1;
47861
47862+#ifdef CONFIG_GRKERNSEC_KMEM
47863+ return -EPERM;
47864+#endif
47865+
47866 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47867 &retval);
47868
47869@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47870 union acpi_object *obj;
47871 acpi_status status;
47872
47873+#ifdef CONFIG_GRKERNSEC_KMEM
47874+ return -EPERM;
47875+#endif
47876+
47877 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47878 1, asus->debug.method_id,
47879 &input, &output);
47880diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47881index 62f8030..c7f2a45 100644
47882--- a/drivers/platform/x86/msi-laptop.c
47883+++ b/drivers/platform/x86/msi-laptop.c
47884@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47885
47886 if (!quirks->ec_read_only) {
47887 /* allow userland write sysfs file */
47888- dev_attr_bluetooth.store = store_bluetooth;
47889- dev_attr_wlan.store = store_wlan;
47890- dev_attr_threeg.store = store_threeg;
47891- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47892- dev_attr_wlan.attr.mode |= S_IWUSR;
47893- dev_attr_threeg.attr.mode |= S_IWUSR;
47894+ pax_open_kernel();
47895+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47896+ *(void **)&dev_attr_wlan.store = store_wlan;
47897+ *(void **)&dev_attr_threeg.store = store_threeg;
47898+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47899+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47900+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47901+ pax_close_kernel();
47902 }
47903
47904 /* disable hardware control by fn key */
47905diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47906index 70222f2..8c8ce66 100644
47907--- a/drivers/platform/x86/msi-wmi.c
47908+++ b/drivers/platform/x86/msi-wmi.c
47909@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47910 static void msi_wmi_notify(u32 value, void *context)
47911 {
47912 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47913- static struct key_entry *key;
47914+ struct key_entry *key;
47915 union acpi_object *obj;
47916 acpi_status status;
47917
47918diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47919index 8f8551a..3ace3ca 100644
47920--- a/drivers/platform/x86/sony-laptop.c
47921+++ b/drivers/platform/x86/sony-laptop.c
47922@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47923 }
47924
47925 /* High speed charging function */
47926-static struct device_attribute *hsc_handle;
47927+static device_attribute_no_const *hsc_handle;
47928
47929 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47930 struct device_attribute *attr,
47931diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47932index defb6af..7a5d3d1 100644
47933--- a/drivers/platform/x86/thinkpad_acpi.c
47934+++ b/drivers/platform/x86/thinkpad_acpi.c
47935@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47936 return 0;
47937 }
47938
47939-void static hotkey_mask_warn_incomplete_mask(void)
47940+static void hotkey_mask_warn_incomplete_mask(void)
47941 {
47942 /* log only what the user can fix... */
47943 const u32 wantedmask = hotkey_driver_mask &
47944@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47945 }
47946 }
47947
47948-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47949- struct tp_nvram_state *newn,
47950- const u32 event_mask)
47951-{
47952-
47953 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47954 do { \
47955 if ((event_mask & (1 << __scancode)) && \
47956@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47957 tpacpi_hotkey_send_key(__scancode); \
47958 } while (0)
47959
47960- void issue_volchange(const unsigned int oldvol,
47961- const unsigned int newvol)
47962- {
47963- unsigned int i = oldvol;
47964+static void issue_volchange(const unsigned int oldvol,
47965+ const unsigned int newvol,
47966+ const u32 event_mask)
47967+{
47968+ unsigned int i = oldvol;
47969
47970- while (i > newvol) {
47971- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47972- i--;
47973- }
47974- while (i < newvol) {
47975- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47976- i++;
47977- }
47978+ while (i > newvol) {
47979+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47980+ i--;
47981 }
47982+ while (i < newvol) {
47983+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47984+ i++;
47985+ }
47986+}
47987
47988- void issue_brightnesschange(const unsigned int oldbrt,
47989- const unsigned int newbrt)
47990- {
47991- unsigned int i = oldbrt;
47992+static void issue_brightnesschange(const unsigned int oldbrt,
47993+ const unsigned int newbrt,
47994+ const u32 event_mask)
47995+{
47996+ unsigned int i = oldbrt;
47997
47998- while (i > newbrt) {
47999- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48000- i--;
48001- }
48002- while (i < newbrt) {
48003- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48004- i++;
48005- }
48006+ while (i > newbrt) {
48007+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48008+ i--;
48009+ }
48010+ while (i < newbrt) {
48011+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48012+ i++;
48013 }
48014+}
48015
48016+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48017+ struct tp_nvram_state *newn,
48018+ const u32 event_mask)
48019+{
48020 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
48021 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
48022 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
48023@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48024 oldn->volume_level != newn->volume_level) {
48025 /* recently muted, or repeated mute keypress, or
48026 * multiple presses ending in mute */
48027- issue_volchange(oldn->volume_level, newn->volume_level);
48028+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48029 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
48030 }
48031 } else {
48032@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48033 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48034 }
48035 if (oldn->volume_level != newn->volume_level) {
48036- issue_volchange(oldn->volume_level, newn->volume_level);
48037+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48038 } else if (oldn->volume_toggle != newn->volume_toggle) {
48039 /* repeated vol up/down keypress at end of scale ? */
48040 if (newn->volume_level == 0)
48041@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48042 /* handle brightness */
48043 if (oldn->brightness_level != newn->brightness_level) {
48044 issue_brightnesschange(oldn->brightness_level,
48045- newn->brightness_level);
48046+ newn->brightness_level,
48047+ event_mask);
48048 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48049 /* repeated key presses that didn't change state */
48050 if (newn->brightness_level == 0)
48051@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48052 && !tp_features.bright_unkfw)
48053 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48054 }
48055+}
48056
48057 #undef TPACPI_COMPARE_KEY
48058 #undef TPACPI_MAY_SEND_KEY
48059-}
48060
48061 /*
48062 * Polling driver
48063diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48064index 769d265..a3a05ca 100644
48065--- a/drivers/pnp/pnpbios/bioscalls.c
48066+++ b/drivers/pnp/pnpbios/bioscalls.c
48067@@ -58,7 +58,7 @@ do { \
48068 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48069 } while(0)
48070
48071-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48072+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48073 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48074
48075 /*
48076@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48077
48078 cpu = get_cpu();
48079 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48080+
48081+ pax_open_kernel();
48082 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48083+ pax_close_kernel();
48084
48085 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48086 spin_lock_irqsave(&pnp_bios_lock, flags);
48087@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48088 :"memory");
48089 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48090
48091+ pax_open_kernel();
48092 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48093+ pax_close_kernel();
48094+
48095 put_cpu();
48096
48097 /* If we get here and this is set then the PnP BIOS faulted on us. */
48098@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48099 return status;
48100 }
48101
48102-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48103+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48104 {
48105 int i;
48106
48107@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48108 pnp_bios_callpoint.offset = header->fields.pm16offset;
48109 pnp_bios_callpoint.segment = PNP_CS16;
48110
48111+ pax_open_kernel();
48112+
48113 for_each_possible_cpu(i) {
48114 struct desc_struct *gdt = get_cpu_gdt_table(i);
48115 if (!gdt)
48116@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48117 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48118 (unsigned long)__va(header->fields.pm16dseg));
48119 }
48120+
48121+ pax_close_kernel();
48122 }
48123diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48124index bacddd1..65ea100 100644
48125--- a/drivers/pnp/resource.c
48126+++ b/drivers/pnp/resource.c
48127@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48128 return 1;
48129
48130 /* check if the resource is valid */
48131- if (*irq < 0 || *irq > 15)
48132+ if (*irq > 15)
48133 return 0;
48134
48135 /* check if the resource is reserved */
48136@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48137 return 1;
48138
48139 /* check if the resource is valid */
48140- if (*dma < 0 || *dma == 4 || *dma > 7)
48141+ if (*dma == 4 || *dma > 7)
48142 return 0;
48143
48144 /* check if the resource is reserved */
48145diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48146index 0c52e2a..3421ab7 100644
48147--- a/drivers/power/pda_power.c
48148+++ b/drivers/power/pda_power.c
48149@@ -37,7 +37,11 @@ static int polling;
48150
48151 #if IS_ENABLED(CONFIG_USB_PHY)
48152 static struct usb_phy *transceiver;
48153-static struct notifier_block otg_nb;
48154+static int otg_handle_notification(struct notifier_block *nb,
48155+ unsigned long event, void *unused);
48156+static struct notifier_block otg_nb = {
48157+ .notifier_call = otg_handle_notification
48158+};
48159 #endif
48160
48161 static struct regulator *ac_draw;
48162@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48163
48164 #if IS_ENABLED(CONFIG_USB_PHY)
48165 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48166- otg_nb.notifier_call = otg_handle_notification;
48167 ret = usb_register_notifier(transceiver, &otg_nb);
48168 if (ret) {
48169 dev_err(dev, "failure to register otg notifier\n");
48170diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48171index cc439fd..8fa30df 100644
48172--- a/drivers/power/power_supply.h
48173+++ b/drivers/power/power_supply.h
48174@@ -16,12 +16,12 @@ struct power_supply;
48175
48176 #ifdef CONFIG_SYSFS
48177
48178-extern void power_supply_init_attrs(struct device_type *dev_type);
48179+extern void power_supply_init_attrs(void);
48180 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48181
48182 #else
48183
48184-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48185+static inline void power_supply_init_attrs(void) {}
48186 #define power_supply_uevent NULL
48187
48188 #endif /* CONFIG_SYSFS */
48189diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48190index 2660664..75fcb04 100644
48191--- a/drivers/power/power_supply_core.c
48192+++ b/drivers/power/power_supply_core.c
48193@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48194 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48195 EXPORT_SYMBOL_GPL(power_supply_notifier);
48196
48197-static struct device_type power_supply_dev_type;
48198+extern const struct attribute_group *power_supply_attr_groups[];
48199+static struct device_type power_supply_dev_type = {
48200+ .groups = power_supply_attr_groups,
48201+};
48202
48203 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48204 struct power_supply *supply)
48205@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48206 return PTR_ERR(power_supply_class);
48207
48208 power_supply_class->dev_uevent = power_supply_uevent;
48209- power_supply_init_attrs(&power_supply_dev_type);
48210+ power_supply_init_attrs();
48211
48212 return 0;
48213 }
48214diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48215index 44420d1..967126e 100644
48216--- a/drivers/power/power_supply_sysfs.c
48217+++ b/drivers/power/power_supply_sysfs.c
48218@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48219 .is_visible = power_supply_attr_is_visible,
48220 };
48221
48222-static const struct attribute_group *power_supply_attr_groups[] = {
48223+const struct attribute_group *power_supply_attr_groups[] = {
48224 &power_supply_attr_group,
48225 NULL,
48226 };
48227
48228-void power_supply_init_attrs(struct device_type *dev_type)
48229+void power_supply_init_attrs(void)
48230 {
48231 int i;
48232
48233- dev_type->groups = power_supply_attr_groups;
48234-
48235 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48236 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48237 }
48238diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48239index 84419af..268ede8 100644
48240--- a/drivers/powercap/powercap_sys.c
48241+++ b/drivers/powercap/powercap_sys.c
48242@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48243 struct device_attribute name_attr;
48244 };
48245
48246+static ssize_t show_constraint_name(struct device *dev,
48247+ struct device_attribute *dev_attr,
48248+ char *buf);
48249+
48250 static struct powercap_constraint_attr
48251- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48252+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48253+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48254+ .power_limit_attr = {
48255+ .attr = {
48256+ .name = NULL,
48257+ .mode = S_IWUSR | S_IRUGO
48258+ },
48259+ .show = show_constraint_power_limit_uw,
48260+ .store = store_constraint_power_limit_uw
48261+ },
48262+
48263+ .time_window_attr = {
48264+ .attr = {
48265+ .name = NULL,
48266+ .mode = S_IWUSR | S_IRUGO
48267+ },
48268+ .show = show_constraint_time_window_us,
48269+ .store = store_constraint_time_window_us
48270+ },
48271+
48272+ .max_power_attr = {
48273+ .attr = {
48274+ .name = NULL,
48275+ .mode = S_IRUGO
48276+ },
48277+ .show = show_constraint_max_power_uw,
48278+ .store = NULL
48279+ },
48280+
48281+ .min_power_attr = {
48282+ .attr = {
48283+ .name = NULL,
48284+ .mode = S_IRUGO
48285+ },
48286+ .show = show_constraint_min_power_uw,
48287+ .store = NULL
48288+ },
48289+
48290+ .max_time_window_attr = {
48291+ .attr = {
48292+ .name = NULL,
48293+ .mode = S_IRUGO
48294+ },
48295+ .show = show_constraint_max_time_window_us,
48296+ .store = NULL
48297+ },
48298+
48299+ .min_time_window_attr = {
48300+ .attr = {
48301+ .name = NULL,
48302+ .mode = S_IRUGO
48303+ },
48304+ .show = show_constraint_min_time_window_us,
48305+ .store = NULL
48306+ },
48307+
48308+ .name_attr = {
48309+ .attr = {
48310+ .name = NULL,
48311+ .mode = S_IRUGO
48312+ },
48313+ .show = show_constraint_name,
48314+ .store = NULL
48315+ }
48316+ }
48317+};
48318
48319 /* A list of powercap control_types */
48320 static LIST_HEAD(powercap_cntrl_list);
48321@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48322 }
48323
48324 static int create_constraint_attribute(int id, const char *name,
48325- int mode,
48326- struct device_attribute *dev_attr,
48327- ssize_t (*show)(struct device *,
48328- struct device_attribute *, char *),
48329- ssize_t (*store)(struct device *,
48330- struct device_attribute *,
48331- const char *, size_t)
48332- )
48333+ struct device_attribute *dev_attr)
48334 {
48335+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48336
48337- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48338- id, name);
48339- if (!dev_attr->attr.name)
48340+ if (!name)
48341 return -ENOMEM;
48342- dev_attr->attr.mode = mode;
48343- dev_attr->show = show;
48344- dev_attr->store = store;
48345+
48346+ pax_open_kernel();
48347+ *(const char **)&dev_attr->attr.name = name;
48348+ pax_close_kernel();
48349
48350 return 0;
48351 }
48352@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48353
48354 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48355 ret = create_constraint_attribute(i, "power_limit_uw",
48356- S_IWUSR | S_IRUGO,
48357- &constraint_attrs[i].power_limit_attr,
48358- show_constraint_power_limit_uw,
48359- store_constraint_power_limit_uw);
48360+ &constraint_attrs[i].power_limit_attr);
48361 if (ret)
48362 goto err_alloc;
48363 ret = create_constraint_attribute(i, "time_window_us",
48364- S_IWUSR | S_IRUGO,
48365- &constraint_attrs[i].time_window_attr,
48366- show_constraint_time_window_us,
48367- store_constraint_time_window_us);
48368+ &constraint_attrs[i].time_window_attr);
48369 if (ret)
48370 goto err_alloc;
48371- ret = create_constraint_attribute(i, "name", S_IRUGO,
48372- &constraint_attrs[i].name_attr,
48373- show_constraint_name,
48374- NULL);
48375+ ret = create_constraint_attribute(i, "name",
48376+ &constraint_attrs[i].name_attr);
48377 if (ret)
48378 goto err_alloc;
48379- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48380- &constraint_attrs[i].max_power_attr,
48381- show_constraint_max_power_uw,
48382- NULL);
48383+ ret = create_constraint_attribute(i, "max_power_uw",
48384+ &constraint_attrs[i].max_power_attr);
48385 if (ret)
48386 goto err_alloc;
48387- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48388- &constraint_attrs[i].min_power_attr,
48389- show_constraint_min_power_uw,
48390- NULL);
48391+ ret = create_constraint_attribute(i, "min_power_uw",
48392+ &constraint_attrs[i].min_power_attr);
48393 if (ret)
48394 goto err_alloc;
48395 ret = create_constraint_attribute(i, "max_time_window_us",
48396- S_IRUGO,
48397- &constraint_attrs[i].max_time_window_attr,
48398- show_constraint_max_time_window_us,
48399- NULL);
48400+ &constraint_attrs[i].max_time_window_attr);
48401 if (ret)
48402 goto err_alloc;
48403 ret = create_constraint_attribute(i, "min_time_window_us",
48404- S_IRUGO,
48405- &constraint_attrs[i].min_time_window_attr,
48406- show_constraint_min_time_window_us,
48407- NULL);
48408+ &constraint_attrs[i].min_time_window_attr);
48409 if (ret)
48410 goto err_alloc;
48411
48412@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48413 power_zone->zone_dev_attrs[count++] =
48414 &dev_attr_max_energy_range_uj.attr;
48415 if (power_zone->ops->get_energy_uj) {
48416+ pax_open_kernel();
48417 if (power_zone->ops->reset_energy_uj)
48418- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48419+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48420 else
48421- dev_attr_energy_uj.attr.mode = S_IRUGO;
48422+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48423+ pax_close_kernel();
48424 power_zone->zone_dev_attrs[count++] =
48425 &dev_attr_energy_uj.attr;
48426 }
48427diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48428index afca1bc..86840b8 100644
48429--- a/drivers/regulator/core.c
48430+++ b/drivers/regulator/core.c
48431@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48432 {
48433 const struct regulation_constraints *constraints = NULL;
48434 const struct regulator_init_data *init_data;
48435- static atomic_t regulator_no = ATOMIC_INIT(0);
48436+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48437 struct regulator_dev *rdev;
48438 struct device *dev;
48439 int ret, i;
48440@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48441 rdev->dev.of_node = config->of_node;
48442 rdev->dev.parent = dev;
48443 dev_set_name(&rdev->dev, "regulator.%d",
48444- atomic_inc_return(&regulator_no) - 1);
48445+ atomic_inc_return_unchecked(&regulator_no) - 1);
48446 ret = device_register(&rdev->dev);
48447 if (ret != 0) {
48448 put_device(&rdev->dev);
48449diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48450index 8d94d3d..653b623 100644
48451--- a/drivers/regulator/max8660.c
48452+++ b/drivers/regulator/max8660.c
48453@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48454 max8660->shadow_regs[MAX8660_OVER1] = 5;
48455 } else {
48456 /* Otherwise devices can be toggled via software */
48457- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48458- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48459+ pax_open_kernel();
48460+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48461+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48462+ pax_close_kernel();
48463 }
48464
48465 /*
48466diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48467index 892aa1e..ebd1b9c 100644
48468--- a/drivers/regulator/max8973-regulator.c
48469+++ b/drivers/regulator/max8973-regulator.c
48470@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48471 if (!pdata || !pdata->enable_ext_control) {
48472 max->desc.enable_reg = MAX8973_VOUT;
48473 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48474- max->ops.enable = regulator_enable_regmap;
48475- max->ops.disable = regulator_disable_regmap;
48476- max->ops.is_enabled = regulator_is_enabled_regmap;
48477+ pax_open_kernel();
48478+ *(void **)&max->ops.enable = regulator_enable_regmap;
48479+ *(void **)&max->ops.disable = regulator_disable_regmap;
48480+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48481+ pax_close_kernel();
48482 }
48483
48484 if (pdata) {
48485diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48486index f374fa5..26f0683 100644
48487--- a/drivers/regulator/mc13892-regulator.c
48488+++ b/drivers/regulator/mc13892-regulator.c
48489@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48490 }
48491 mc13xxx_unlock(mc13892);
48492
48493- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48494+ pax_open_kernel();
48495+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48496 = mc13892_vcam_set_mode;
48497- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48498+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48499 = mc13892_vcam_get_mode;
48500+ pax_close_kernel();
48501
48502 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48503 ARRAY_SIZE(mc13892_regulators));
48504diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48505index cae212f..58a3980 100644
48506--- a/drivers/rtc/rtc-cmos.c
48507+++ b/drivers/rtc/rtc-cmos.c
48508@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48509 hpet_rtc_timer_init();
48510
48511 /* export at least the first block of NVRAM */
48512- nvram.size = address_space - NVRAM_OFFSET;
48513+ pax_open_kernel();
48514+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48515+ pax_close_kernel();
48516 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48517 if (retval < 0) {
48518 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48519diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48520index d049393..bb20be0 100644
48521--- a/drivers/rtc/rtc-dev.c
48522+++ b/drivers/rtc/rtc-dev.c
48523@@ -16,6 +16,7 @@
48524 #include <linux/module.h>
48525 #include <linux/rtc.h>
48526 #include <linux/sched.h>
48527+#include <linux/grsecurity.h>
48528 #include "rtc-core.h"
48529
48530 static dev_t rtc_devt;
48531@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48532 if (copy_from_user(&tm, uarg, sizeof(tm)))
48533 return -EFAULT;
48534
48535+ gr_log_timechange();
48536+
48537 return rtc_set_time(rtc, &tm);
48538
48539 case RTC_PIE_ON:
48540diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48541index 4e75345..09f8663 100644
48542--- a/drivers/rtc/rtc-ds1307.c
48543+++ b/drivers/rtc/rtc-ds1307.c
48544@@ -107,7 +107,7 @@ struct ds1307 {
48545 u8 offset; /* register's offset */
48546 u8 regs[11];
48547 u16 nvram_offset;
48548- struct bin_attribute *nvram;
48549+ bin_attribute_no_const *nvram;
48550 enum ds_type type;
48551 unsigned long flags;
48552 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48553diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48554index 11880c1..b823aa4 100644
48555--- a/drivers/rtc/rtc-m48t59.c
48556+++ b/drivers/rtc/rtc-m48t59.c
48557@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48558 if (IS_ERR(m48t59->rtc))
48559 return PTR_ERR(m48t59->rtc);
48560
48561- m48t59_nvram_attr.size = pdata->offset;
48562+ pax_open_kernel();
48563+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48564+ pax_close_kernel();
48565
48566 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48567 if (ret)
48568diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48569index 14b5f8d..cc9bd26 100644
48570--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48571+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48572@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48573 for (bit = 0; bit < 8; bit++) {
48574
48575 if ((pci_status[i] & (0x1 << bit)) != 0) {
48576- static const char *s;
48577+ const char *s;
48578
48579 s = pci_status_strings[bit];
48580 if (i == 7/*TARG*/ && bit == 3)
48581@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48582
48583 for (bit = 0; bit < 8; bit++) {
48584
48585- if ((split_status[i] & (0x1 << bit)) != 0) {
48586- static const char *s;
48587-
48588- s = split_status_strings[bit];
48589- printk(s, ahd_name(ahd),
48590+ if ((split_status[i] & (0x1 << bit)) != 0)
48591+ printk(split_status_strings[bit], ahd_name(ahd),
48592 split_status_source[i]);
48593- }
48594
48595 if (i > 1)
48596 continue;
48597
48598- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48599- static const char *s;
48600-
48601- s = split_status_strings[bit];
48602- printk(s, ahd_name(ahd), "SG");
48603- }
48604+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48605+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48606 }
48607 }
48608 /*
48609diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48610index e693af6..2e525b6 100644
48611--- a/drivers/scsi/bfa/bfa_fcpim.h
48612+++ b/drivers/scsi/bfa/bfa_fcpim.h
48613@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48614
48615 struct bfa_itn_s {
48616 bfa_isr_func_t isr;
48617-};
48618+} __no_const;
48619
48620 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48621 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48622diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48623index a3ab5cc..8143622 100644
48624--- a/drivers/scsi/bfa/bfa_fcs.c
48625+++ b/drivers/scsi/bfa/bfa_fcs.c
48626@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48627 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48628
48629 static struct bfa_fcs_mod_s fcs_modules[] = {
48630- { bfa_fcs_port_attach, NULL, NULL },
48631- { bfa_fcs_uf_attach, NULL, NULL },
48632- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48633- bfa_fcs_fabric_modexit },
48634+ {
48635+ .attach = bfa_fcs_port_attach,
48636+ .modinit = NULL,
48637+ .modexit = NULL
48638+ },
48639+ {
48640+ .attach = bfa_fcs_uf_attach,
48641+ .modinit = NULL,
48642+ .modexit = NULL
48643+ },
48644+ {
48645+ .attach = bfa_fcs_fabric_attach,
48646+ .modinit = bfa_fcs_fabric_modinit,
48647+ .modexit = bfa_fcs_fabric_modexit
48648+ },
48649 };
48650
48651 /*
48652diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48653index ff75ef8..2dfe00a 100644
48654--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48655+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48656@@ -89,15 +89,26 @@ static struct {
48657 void (*offline) (struct bfa_fcs_lport_s *port);
48658 } __port_action[] = {
48659 {
48660- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48661- bfa_fcs_lport_unknown_offline}, {
48662- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48663- bfa_fcs_lport_fab_offline}, {
48664- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48665- bfa_fcs_lport_n2n_offline}, {
48666- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48667- bfa_fcs_lport_loop_offline},
48668- };
48669+ .init = bfa_fcs_lport_unknown_init,
48670+ .online = bfa_fcs_lport_unknown_online,
48671+ .offline = bfa_fcs_lport_unknown_offline
48672+ },
48673+ {
48674+ .init = bfa_fcs_lport_fab_init,
48675+ .online = bfa_fcs_lport_fab_online,
48676+ .offline = bfa_fcs_lport_fab_offline
48677+ },
48678+ {
48679+ .init = bfa_fcs_lport_n2n_init,
48680+ .online = bfa_fcs_lport_n2n_online,
48681+ .offline = bfa_fcs_lport_n2n_offline
48682+ },
48683+ {
48684+ .init = bfa_fcs_lport_loop_init,
48685+ .online = bfa_fcs_lport_loop_online,
48686+ .offline = bfa_fcs_lport_loop_offline
48687+ },
48688+};
48689
48690 /*
48691 * fcs_port_sm FCS logical port state machine
48692diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48693index 2e28392..9d865b6 100644
48694--- a/drivers/scsi/bfa/bfa_ioc.h
48695+++ b/drivers/scsi/bfa/bfa_ioc.h
48696@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48697 bfa_ioc_disable_cbfn_t disable_cbfn;
48698 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48699 bfa_ioc_reset_cbfn_t reset_cbfn;
48700-};
48701+} __no_const;
48702
48703 /*
48704 * IOC event notification mechanism.
48705@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48706 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48707 enum bfi_ioc_state fwstate);
48708 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48709-};
48710+} __no_const;
48711
48712 /*
48713 * Queue element to wait for room in request queue. FIFO order is
48714diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48715index a14c784..6de6790 100644
48716--- a/drivers/scsi/bfa/bfa_modules.h
48717+++ b/drivers/scsi/bfa/bfa_modules.h
48718@@ -78,12 +78,12 @@ enum {
48719 \
48720 extern struct bfa_module_s hal_mod_ ## __mod; \
48721 struct bfa_module_s hal_mod_ ## __mod = { \
48722- bfa_ ## __mod ## _meminfo, \
48723- bfa_ ## __mod ## _attach, \
48724- bfa_ ## __mod ## _detach, \
48725- bfa_ ## __mod ## _start, \
48726- bfa_ ## __mod ## _stop, \
48727- bfa_ ## __mod ## _iocdisable, \
48728+ .meminfo = bfa_ ## __mod ## _meminfo, \
48729+ .attach = bfa_ ## __mod ## _attach, \
48730+ .detach = bfa_ ## __mod ## _detach, \
48731+ .start = bfa_ ## __mod ## _start, \
48732+ .stop = bfa_ ## __mod ## _stop, \
48733+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48734 }
48735
48736 #define BFA_CACHELINE_SZ (256)
48737diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48738index 045c4e1..13de803 100644
48739--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48740+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48741@@ -33,8 +33,8 @@
48742 */
48743 #include "libfcoe.h"
48744
48745-static atomic_t ctlr_num;
48746-static atomic_t fcf_num;
48747+static atomic_unchecked_t ctlr_num;
48748+static atomic_unchecked_t fcf_num;
48749
48750 /*
48751 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48752@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48753 if (!ctlr)
48754 goto out;
48755
48756- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48757+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48758 ctlr->f = f;
48759 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48760 INIT_LIST_HEAD(&ctlr->fcfs);
48761@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48762 fcf->dev.parent = &ctlr->dev;
48763 fcf->dev.bus = &fcoe_bus_type;
48764 fcf->dev.type = &fcoe_fcf_device_type;
48765- fcf->id = atomic_inc_return(&fcf_num) - 1;
48766+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48767 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48768
48769 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48770@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48771 {
48772 int error;
48773
48774- atomic_set(&ctlr_num, 0);
48775- atomic_set(&fcf_num, 0);
48776+ atomic_set_unchecked(&ctlr_num, 0);
48777+ atomic_set_unchecked(&fcf_num, 0);
48778
48779 error = bus_register(&fcoe_bus_type);
48780 if (error)
48781diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48782index f28ea07..34b16d3 100644
48783--- a/drivers/scsi/hosts.c
48784+++ b/drivers/scsi/hosts.c
48785@@ -42,7 +42,7 @@
48786 #include "scsi_logging.h"
48787
48788
48789-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48790+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48791
48792
48793 static void scsi_host_cls_release(struct device *dev)
48794@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48795 * subtract one because we increment first then return, but we need to
48796 * know what the next host number was before increment
48797 */
48798- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48799+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48800 shost->dma_channel = 0xff;
48801
48802 /* These three are default values which can be overridden */
48803diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48804index 868318a..e07ef3b 100644
48805--- a/drivers/scsi/hpsa.c
48806+++ b/drivers/scsi/hpsa.c
48807@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48808 unsigned long flags;
48809
48810 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48811- return h->access.command_completed(h, q);
48812+ return h->access->command_completed(h, q);
48813
48814 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48815 a = rq->head[rq->current_entry];
48816@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
48817 while (!list_empty(&h->reqQ)) {
48818 c = list_entry(h->reqQ.next, struct CommandList, list);
48819 /* can't do anything if fifo is full */
48820- if ((h->access.fifo_full(h))) {
48821+ if ((h->access->fifo_full(h))) {
48822 h->fifo_recently_full = 1;
48823 dev_warn(&h->pdev->dev, "fifo full\n");
48824 break;
48825@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
48826
48827 /* Tell the controller execute command */
48828 spin_unlock_irqrestore(&h->lock, flags);
48829- h->access.submit_command(h, c);
48830+ h->access->submit_command(h, c);
48831 spin_lock_irqsave(&h->lock, flags);
48832 }
48833 spin_unlock_irqrestore(&h->lock, flags);
48834@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
48835
48836 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48837 {
48838- return h->access.command_completed(h, q);
48839+ return h->access->command_completed(h, q);
48840 }
48841
48842 static inline bool interrupt_pending(struct ctlr_info *h)
48843 {
48844- return h->access.intr_pending(h);
48845+ return h->access->intr_pending(h);
48846 }
48847
48848 static inline long interrupt_not_for_us(struct ctlr_info *h)
48849 {
48850- return (h->access.intr_pending(h) == 0) ||
48851+ return (h->access->intr_pending(h) == 0) ||
48852 (h->interrupts_enabled == 0);
48853 }
48854
48855@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48856 if (prod_index < 0)
48857 return -ENODEV;
48858 h->product_name = products[prod_index].product_name;
48859- h->access = *(products[prod_index].access);
48860+ h->access = products[prod_index].access;
48861
48862 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48863 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48864@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48865 {
48866 unsigned long flags;
48867
48868- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48869+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48870 spin_lock_irqsave(&h->lock, flags);
48871 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48872 spin_unlock_irqrestore(&h->lock, flags);
48873@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
48874 }
48875
48876 /* make sure the board interrupts are off */
48877- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48878+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48879
48880 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48881 goto clean2;
48882@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
48883 * fake ones to scoop up any residual completions.
48884 */
48885 spin_lock_irqsave(&h->lock, flags);
48886- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48887+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48888 spin_unlock_irqrestore(&h->lock, flags);
48889 free_irqs(h);
48890 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48891@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
48892 dev_info(&h->pdev->dev, "Board READY.\n");
48893 dev_info(&h->pdev->dev,
48894 "Waiting for stale completions to drain.\n");
48895- h->access.set_intr_mask(h, HPSA_INTR_ON);
48896+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48897 msleep(10000);
48898- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48899+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48900
48901 rc = controller_reset_failed(h->cfgtable);
48902 if (rc)
48903@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
48904 }
48905
48906 /* Turn the interrupts on so we can service requests */
48907- h->access.set_intr_mask(h, HPSA_INTR_ON);
48908+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48909
48910 hpsa_hba_inquiry(h);
48911 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48912@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48913 * To write all data in the battery backed cache to disks
48914 */
48915 hpsa_flush_cache(h);
48916- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48917+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48918 hpsa_free_irqs_and_disable_msix(h);
48919 }
48920
48921@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48922 return;
48923 }
48924 /* Change the access methods to the performant access methods */
48925- h->access = SA5_performant_access;
48926+ h->access = &SA5_performant_access;
48927 h->transMethod = CFGTBL_Trans_Performant;
48928 }
48929
48930diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48931index 01c3283..4655219 100644
48932--- a/drivers/scsi/hpsa.h
48933+++ b/drivers/scsi/hpsa.h
48934@@ -79,7 +79,7 @@ struct ctlr_info {
48935 unsigned int msix_vector;
48936 unsigned int msi_vector;
48937 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48938- struct access_method access;
48939+ struct access_method *access;
48940
48941 /* queue and queue Info */
48942 struct list_head reqQ;
48943@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48944 }
48945
48946 static struct access_method SA5_access = {
48947- SA5_submit_command,
48948- SA5_intr_mask,
48949- SA5_fifo_full,
48950- SA5_intr_pending,
48951- SA5_completed,
48952+ .submit_command = SA5_submit_command,
48953+ .set_intr_mask = SA5_intr_mask,
48954+ .fifo_full = SA5_fifo_full,
48955+ .intr_pending = SA5_intr_pending,
48956+ .command_completed = SA5_completed,
48957 };
48958
48959 static struct access_method SA5_performant_access = {
48960- SA5_submit_command,
48961- SA5_performant_intr_mask,
48962- SA5_fifo_full,
48963- SA5_performant_intr_pending,
48964- SA5_performant_completed,
48965+ .submit_command = SA5_submit_command,
48966+ .set_intr_mask = SA5_performant_intr_mask,
48967+ .fifo_full = SA5_fifo_full,
48968+ .intr_pending = SA5_performant_intr_pending,
48969+ .command_completed = SA5_performant_completed,
48970 };
48971
48972 struct board_type {
48973diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48974index 1b3a094..068e683 100644
48975--- a/drivers/scsi/libfc/fc_exch.c
48976+++ b/drivers/scsi/libfc/fc_exch.c
48977@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48978 u16 pool_max_index;
48979
48980 struct {
48981- atomic_t no_free_exch;
48982- atomic_t no_free_exch_xid;
48983- atomic_t xid_not_found;
48984- atomic_t xid_busy;
48985- atomic_t seq_not_found;
48986- atomic_t non_bls_resp;
48987+ atomic_unchecked_t no_free_exch;
48988+ atomic_unchecked_t no_free_exch_xid;
48989+ atomic_unchecked_t xid_not_found;
48990+ atomic_unchecked_t xid_busy;
48991+ atomic_unchecked_t seq_not_found;
48992+ atomic_unchecked_t non_bls_resp;
48993 } stats;
48994 };
48995
48996@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48997 /* allocate memory for exchange */
48998 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48999 if (!ep) {
49000- atomic_inc(&mp->stats.no_free_exch);
49001+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49002 goto out;
49003 }
49004 memset(ep, 0, sizeof(*ep));
49005@@ -874,7 +874,7 @@ out:
49006 return ep;
49007 err:
49008 spin_unlock_bh(&pool->lock);
49009- atomic_inc(&mp->stats.no_free_exch_xid);
49010+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49011 mempool_free(ep, mp->ep_pool);
49012 return NULL;
49013 }
49014@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49015 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49016 ep = fc_exch_find(mp, xid);
49017 if (!ep) {
49018- atomic_inc(&mp->stats.xid_not_found);
49019+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49020 reject = FC_RJT_OX_ID;
49021 goto out;
49022 }
49023@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49024 ep = fc_exch_find(mp, xid);
49025 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49026 if (ep) {
49027- atomic_inc(&mp->stats.xid_busy);
49028+ atomic_inc_unchecked(&mp->stats.xid_busy);
49029 reject = FC_RJT_RX_ID;
49030 goto rel;
49031 }
49032@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49033 }
49034 xid = ep->xid; /* get our XID */
49035 } else if (!ep) {
49036- atomic_inc(&mp->stats.xid_not_found);
49037+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49038 reject = FC_RJT_RX_ID; /* XID not found */
49039 goto out;
49040 }
49041@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49042 } else {
49043 sp = &ep->seq;
49044 if (sp->id != fh->fh_seq_id) {
49045- atomic_inc(&mp->stats.seq_not_found);
49046+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49047 if (f_ctl & FC_FC_END_SEQ) {
49048 /*
49049 * Update sequence_id based on incoming last
49050@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49051
49052 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49053 if (!ep) {
49054- atomic_inc(&mp->stats.xid_not_found);
49055+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49056 goto out;
49057 }
49058 if (ep->esb_stat & ESB_ST_COMPLETE) {
49059- atomic_inc(&mp->stats.xid_not_found);
49060+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49061 goto rel;
49062 }
49063 if (ep->rxid == FC_XID_UNKNOWN)
49064 ep->rxid = ntohs(fh->fh_rx_id);
49065 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49066- atomic_inc(&mp->stats.xid_not_found);
49067+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49068 goto rel;
49069 }
49070 if (ep->did != ntoh24(fh->fh_s_id) &&
49071 ep->did != FC_FID_FLOGI) {
49072- atomic_inc(&mp->stats.xid_not_found);
49073+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49074 goto rel;
49075 }
49076 sof = fr_sof(fp);
49077@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49078 sp->ssb_stat |= SSB_ST_RESP;
49079 sp->id = fh->fh_seq_id;
49080 } else if (sp->id != fh->fh_seq_id) {
49081- atomic_inc(&mp->stats.seq_not_found);
49082+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49083 goto rel;
49084 }
49085
49086@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49087 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49088
49089 if (!sp)
49090- atomic_inc(&mp->stats.xid_not_found);
49091+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49092 else
49093- atomic_inc(&mp->stats.non_bls_resp);
49094+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49095
49096 fc_frame_free(fp);
49097 }
49098@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49099
49100 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49101 mp = ema->mp;
49102- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49103+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49104 st->fc_no_free_exch_xid +=
49105- atomic_read(&mp->stats.no_free_exch_xid);
49106- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49107- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49108- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49109- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49110+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49111+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49112+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49113+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49114+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49115 }
49116 }
49117 EXPORT_SYMBOL(fc_exch_update_stats);
49118diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49119index d289583..b745eec 100644
49120--- a/drivers/scsi/libsas/sas_ata.c
49121+++ b/drivers/scsi/libsas/sas_ata.c
49122@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49123 .postreset = ata_std_postreset,
49124 .error_handler = ata_std_error_handler,
49125 .post_internal_cmd = sas_ata_post_internal,
49126- .qc_defer = ata_std_qc_defer,
49127+ .qc_defer = ata_std_qc_defer,
49128 .qc_prep = ata_noop_qc_prep,
49129 .qc_issue = sas_ata_qc_issue,
49130 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49131diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49132index 4e1b75c..0bbdfa9 100644
49133--- a/drivers/scsi/lpfc/lpfc.h
49134+++ b/drivers/scsi/lpfc/lpfc.h
49135@@ -432,7 +432,7 @@ struct lpfc_vport {
49136 struct dentry *debug_nodelist;
49137 struct dentry *vport_debugfs_root;
49138 struct lpfc_debugfs_trc *disc_trc;
49139- atomic_t disc_trc_cnt;
49140+ atomic_unchecked_t disc_trc_cnt;
49141 #endif
49142 uint8_t stat_data_enabled;
49143 uint8_t stat_data_blocked;
49144@@ -865,8 +865,8 @@ struct lpfc_hba {
49145 struct timer_list fabric_block_timer;
49146 unsigned long bit_flags;
49147 #define FABRIC_COMANDS_BLOCKED 0
49148- atomic_t num_rsrc_err;
49149- atomic_t num_cmd_success;
49150+ atomic_unchecked_t num_rsrc_err;
49151+ atomic_unchecked_t num_cmd_success;
49152 unsigned long last_rsrc_error_time;
49153 unsigned long last_ramp_down_time;
49154 unsigned long last_ramp_up_time;
49155@@ -902,7 +902,7 @@ struct lpfc_hba {
49156
49157 struct dentry *debug_slow_ring_trc;
49158 struct lpfc_debugfs_trc *slow_ring_trc;
49159- atomic_t slow_ring_trc_cnt;
49160+ atomic_unchecked_t slow_ring_trc_cnt;
49161 /* iDiag debugfs sub-directory */
49162 struct dentry *idiag_root;
49163 struct dentry *idiag_pci_cfg;
49164diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49165index b800cc9..16b6a91 100644
49166--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49167+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49168@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49169
49170 #include <linux/debugfs.h>
49171
49172-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49173+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49174 static unsigned long lpfc_debugfs_start_time = 0L;
49175
49176 /* iDiag */
49177@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49178 lpfc_debugfs_enable = 0;
49179
49180 len = 0;
49181- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49182+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49183 (lpfc_debugfs_max_disc_trc - 1);
49184 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49185 dtp = vport->disc_trc + i;
49186@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49187 lpfc_debugfs_enable = 0;
49188
49189 len = 0;
49190- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49191+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49192 (lpfc_debugfs_max_slow_ring_trc - 1);
49193 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49194 dtp = phba->slow_ring_trc + i;
49195@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49196 !vport || !vport->disc_trc)
49197 return;
49198
49199- index = atomic_inc_return(&vport->disc_trc_cnt) &
49200+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49201 (lpfc_debugfs_max_disc_trc - 1);
49202 dtp = vport->disc_trc + index;
49203 dtp->fmt = fmt;
49204 dtp->data1 = data1;
49205 dtp->data2 = data2;
49206 dtp->data3 = data3;
49207- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49208+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49209 dtp->jif = jiffies;
49210 #endif
49211 return;
49212@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49213 !phba || !phba->slow_ring_trc)
49214 return;
49215
49216- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49217+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49218 (lpfc_debugfs_max_slow_ring_trc - 1);
49219 dtp = phba->slow_ring_trc + index;
49220 dtp->fmt = fmt;
49221 dtp->data1 = data1;
49222 dtp->data2 = data2;
49223 dtp->data3 = data3;
49224- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49225+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49226 dtp->jif = jiffies;
49227 #endif
49228 return;
49229@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49230 "slow_ring buffer\n");
49231 goto debug_failed;
49232 }
49233- atomic_set(&phba->slow_ring_trc_cnt, 0);
49234+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49235 memset(phba->slow_ring_trc, 0,
49236 (sizeof(struct lpfc_debugfs_trc) *
49237 lpfc_debugfs_max_slow_ring_trc));
49238@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49239 "buffer\n");
49240 goto debug_failed;
49241 }
49242- atomic_set(&vport->disc_trc_cnt, 0);
49243+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49244
49245 snprintf(name, sizeof(name), "discovery_trace");
49246 vport->debug_disc_trc =
49247diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49248index 68c94cc..8c27be5 100644
49249--- a/drivers/scsi/lpfc/lpfc_init.c
49250+++ b/drivers/scsi/lpfc/lpfc_init.c
49251@@ -10949,8 +10949,10 @@ lpfc_init(void)
49252 "misc_register returned with status %d", error);
49253
49254 if (lpfc_enable_npiv) {
49255- lpfc_transport_functions.vport_create = lpfc_vport_create;
49256- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49257+ pax_open_kernel();
49258+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49259+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49260+ pax_close_kernel();
49261 }
49262 lpfc_transport_template =
49263 fc_attach_transport(&lpfc_transport_functions);
49264diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49265index b2ede05..aaf482ca 100644
49266--- a/drivers/scsi/lpfc/lpfc_scsi.c
49267+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49268@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49269 uint32_t evt_posted;
49270
49271 spin_lock_irqsave(&phba->hbalock, flags);
49272- atomic_inc(&phba->num_rsrc_err);
49273+ atomic_inc_unchecked(&phba->num_rsrc_err);
49274 phba->last_rsrc_error_time = jiffies;
49275
49276 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49277@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49278 unsigned long flags;
49279 struct lpfc_hba *phba = vport->phba;
49280 uint32_t evt_posted;
49281- atomic_inc(&phba->num_cmd_success);
49282+ atomic_inc_unchecked(&phba->num_cmd_success);
49283
49284 if (vport->cfg_lun_queue_depth <= queue_depth)
49285 return;
49286@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49287 unsigned long num_rsrc_err, num_cmd_success;
49288 int i;
49289
49290- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49291- num_cmd_success = atomic_read(&phba->num_cmd_success);
49292+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49293+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49294
49295 /*
49296 * The error and success command counters are global per
49297@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49298 }
49299 }
49300 lpfc_destroy_vport_work_array(phba, vports);
49301- atomic_set(&phba->num_rsrc_err, 0);
49302- atomic_set(&phba->num_cmd_success, 0);
49303+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49304+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49305 }
49306
49307 /**
49308@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49309 }
49310 }
49311 lpfc_destroy_vport_work_array(phba, vports);
49312- atomic_set(&phba->num_rsrc_err, 0);
49313- atomic_set(&phba->num_cmd_success, 0);
49314+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49315+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49316 }
49317
49318 /**
49319diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49320index 7f0af4f..193ac3e 100644
49321--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49322+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49323@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49324 {
49325 struct scsi_device *sdev = to_scsi_device(dev);
49326 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49327- static struct _raid_device *raid_device;
49328+ struct _raid_device *raid_device;
49329 unsigned long flags;
49330 Mpi2RaidVolPage0_t vol_pg0;
49331 Mpi2ConfigReply_t mpi_reply;
49332@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49333 {
49334 struct scsi_device *sdev = to_scsi_device(dev);
49335 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49336- static struct _raid_device *raid_device;
49337+ struct _raid_device *raid_device;
49338 unsigned long flags;
49339 Mpi2RaidVolPage0_t vol_pg0;
49340 Mpi2ConfigReply_t mpi_reply;
49341@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49342 struct fw_event_work *fw_event)
49343 {
49344 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49345- static struct _raid_device *raid_device;
49346+ struct _raid_device *raid_device;
49347 unsigned long flags;
49348 u16 handle;
49349
49350@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49351 u64 sas_address;
49352 struct _sas_device *sas_device;
49353 struct _sas_node *expander_device;
49354- static struct _raid_device *raid_device;
49355+ struct _raid_device *raid_device;
49356 u8 retry_count;
49357 unsigned long flags;
49358
49359diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49360index be8ce54..94ed33a 100644
49361--- a/drivers/scsi/pmcraid.c
49362+++ b/drivers/scsi/pmcraid.c
49363@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49364 res->scsi_dev = scsi_dev;
49365 scsi_dev->hostdata = res;
49366 res->change_detected = 0;
49367- atomic_set(&res->read_failures, 0);
49368- atomic_set(&res->write_failures, 0);
49369+ atomic_set_unchecked(&res->read_failures, 0);
49370+ atomic_set_unchecked(&res->write_failures, 0);
49371 rc = 0;
49372 }
49373 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49374@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49375
49376 /* If this was a SCSI read/write command keep count of errors */
49377 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49378- atomic_inc(&res->read_failures);
49379+ atomic_inc_unchecked(&res->read_failures);
49380 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49381- atomic_inc(&res->write_failures);
49382+ atomic_inc_unchecked(&res->write_failures);
49383
49384 if (!RES_IS_GSCSI(res->cfg_entry) &&
49385 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49386@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49387 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49388 * hrrq_id assigned here in queuecommand
49389 */
49390- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49391+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49392 pinstance->num_hrrq;
49393 cmd->cmd_done = pmcraid_io_done;
49394
49395@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49396 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49397 * hrrq_id assigned here in queuecommand
49398 */
49399- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49400+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49401 pinstance->num_hrrq;
49402
49403 if (request_size) {
49404@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49405
49406 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49407 /* add resources only after host is added into system */
49408- if (!atomic_read(&pinstance->expose_resources))
49409+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49410 return;
49411
49412 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49413@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49414 init_waitqueue_head(&pinstance->reset_wait_q);
49415
49416 atomic_set(&pinstance->outstanding_cmds, 0);
49417- atomic_set(&pinstance->last_message_id, 0);
49418- atomic_set(&pinstance->expose_resources, 0);
49419+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49420+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49421
49422 INIT_LIST_HEAD(&pinstance->free_res_q);
49423 INIT_LIST_HEAD(&pinstance->used_res_q);
49424@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49425 /* Schedule worker thread to handle CCN and take care of adding and
49426 * removing devices to OS
49427 */
49428- atomic_set(&pinstance->expose_resources, 1);
49429+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49430 schedule_work(&pinstance->worker_q);
49431 return rc;
49432
49433diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49434index e1d150f..6c6df44 100644
49435--- a/drivers/scsi/pmcraid.h
49436+++ b/drivers/scsi/pmcraid.h
49437@@ -748,7 +748,7 @@ struct pmcraid_instance {
49438 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49439
49440 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49441- atomic_t last_message_id;
49442+ atomic_unchecked_t last_message_id;
49443
49444 /* configuration table */
49445 struct pmcraid_config_table *cfg_table;
49446@@ -777,7 +777,7 @@ struct pmcraid_instance {
49447 atomic_t outstanding_cmds;
49448
49449 /* should add/delete resources to mid-layer now ?*/
49450- atomic_t expose_resources;
49451+ atomic_unchecked_t expose_resources;
49452
49453
49454
49455@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49456 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49457 };
49458 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49459- atomic_t read_failures; /* count of failed READ commands */
49460- atomic_t write_failures; /* count of failed WRITE commands */
49461+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49462+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49463
49464 /* To indicate add/delete/modify during CCN */
49465 u8 change_detected;
49466diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49467index 4a0d7c9..3d658d7 100644
49468--- a/drivers/scsi/qla2xxx/qla_attr.c
49469+++ b/drivers/scsi/qla2xxx/qla_attr.c
49470@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49471 return 0;
49472 }
49473
49474-struct fc_function_template qla2xxx_transport_functions = {
49475+fc_function_template_no_const qla2xxx_transport_functions = {
49476
49477 .show_host_node_name = 1,
49478 .show_host_port_name = 1,
49479@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49480 .bsg_timeout = qla24xx_bsg_timeout,
49481 };
49482
49483-struct fc_function_template qla2xxx_transport_vport_functions = {
49484+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49485
49486 .show_host_node_name = 1,
49487 .show_host_port_name = 1,
49488diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49489index 1f42662..bf9836c 100644
49490--- a/drivers/scsi/qla2xxx/qla_gbl.h
49491+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49492@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49493 struct device_attribute;
49494 extern struct device_attribute *qla2x00_host_attrs[];
49495 struct fc_function_template;
49496-extern struct fc_function_template qla2xxx_transport_functions;
49497-extern struct fc_function_template qla2xxx_transport_vport_functions;
49498+extern fc_function_template_no_const qla2xxx_transport_functions;
49499+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49500 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49501 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49502 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49503diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49504index 83cb612..9b7b08c 100644
49505--- a/drivers/scsi/qla2xxx/qla_os.c
49506+++ b/drivers/scsi/qla2xxx/qla_os.c
49507@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49508 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49509 /* Ok, a 64bit DMA mask is applicable. */
49510 ha->flags.enable_64bit_addressing = 1;
49511- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49512- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49513+ pax_open_kernel();
49514+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49515+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49516+ pax_close_kernel();
49517 return;
49518 }
49519 }
49520diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49521index aa67bb9..06d0e2a 100644
49522--- a/drivers/scsi/qla4xxx/ql4_def.h
49523+++ b/drivers/scsi/qla4xxx/ql4_def.h
49524@@ -303,7 +303,7 @@ struct ddb_entry {
49525 * (4000 only) */
49526 atomic_t relogin_timer; /* Max Time to wait for
49527 * relogin to complete */
49528- atomic_t relogin_retry_count; /* Num of times relogin has been
49529+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49530 * retried */
49531 uint32_t default_time2wait; /* Default Min time between
49532 * relogins (+aens) */
49533diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49534index c21adc3..1b4155f 100644
49535--- a/drivers/scsi/qla4xxx/ql4_os.c
49536+++ b/drivers/scsi/qla4xxx/ql4_os.c
49537@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49538 */
49539 if (!iscsi_is_session_online(cls_sess)) {
49540 /* Reset retry relogin timer */
49541- atomic_inc(&ddb_entry->relogin_retry_count);
49542+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49543 DEBUG2(ql4_printk(KERN_INFO, ha,
49544 "%s: index[%d] relogin timed out-retrying"
49545 " relogin (%d), retry (%d)\n", __func__,
49546 ddb_entry->fw_ddb_index,
49547- atomic_read(&ddb_entry->relogin_retry_count),
49548+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49549 ddb_entry->default_time2wait + 4));
49550 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49551 atomic_set(&ddb_entry->retry_relogin_timer,
49552@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49553
49554 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49555 atomic_set(&ddb_entry->relogin_timer, 0);
49556- atomic_set(&ddb_entry->relogin_retry_count, 0);
49557+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49558 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49559 ddb_entry->default_relogin_timeout =
49560 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49561diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49562index d8afec8..3ec7152 100644
49563--- a/drivers/scsi/scsi.c
49564+++ b/drivers/scsi/scsi.c
49565@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49566 struct Scsi_Host *host = cmd->device->host;
49567 int rtn = 0;
49568
49569- atomic_inc(&cmd->device->iorequest_cnt);
49570+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49571
49572 /* check if the device is still usable */
49573 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49574diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49575index 62ec84b..93159d8 100644
49576--- a/drivers/scsi/scsi_lib.c
49577+++ b/drivers/scsi/scsi_lib.c
49578@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49579 shost = sdev->host;
49580 scsi_init_cmd_errh(cmd);
49581 cmd->result = DID_NO_CONNECT << 16;
49582- atomic_inc(&cmd->device->iorequest_cnt);
49583+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49584
49585 /*
49586 * SCSI request completion path will do scsi_device_unbusy(),
49587@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49588
49589 INIT_LIST_HEAD(&cmd->eh_entry);
49590
49591- atomic_inc(&cmd->device->iodone_cnt);
49592+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49593 if (cmd->result)
49594- atomic_inc(&cmd->device->ioerr_cnt);
49595+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49596
49597 disposition = scsi_decide_disposition(cmd);
49598 if (disposition != SUCCESS &&
49599diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49600index 9117d0b..d289a7a 100644
49601--- a/drivers/scsi/scsi_sysfs.c
49602+++ b/drivers/scsi/scsi_sysfs.c
49603@@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49604 char *buf) \
49605 { \
49606 struct scsi_device *sdev = to_scsi_device(dev); \
49607- unsigned long long count = atomic_read(&sdev->field); \
49608+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49609 return snprintf(buf, 20, "0x%llx\n", count); \
49610 } \
49611 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49612diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49613index 84a1fdf..693b0d6 100644
49614--- a/drivers/scsi/scsi_tgt_lib.c
49615+++ b/drivers/scsi/scsi_tgt_lib.c
49616@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49617 int err;
49618
49619 dprintk("%lx %u\n", uaddr, len);
49620- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49621+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49622 if (err) {
49623 /*
49624 * TODO: need to fixup sg_tablesize, max_segment_size,
49625diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49626index 4628fd5..a94a1c2 100644
49627--- a/drivers/scsi/scsi_transport_fc.c
49628+++ b/drivers/scsi/scsi_transport_fc.c
49629@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49630 * Netlink Infrastructure
49631 */
49632
49633-static atomic_t fc_event_seq;
49634+static atomic_unchecked_t fc_event_seq;
49635
49636 /**
49637 * fc_get_event_number - Obtain the next sequential FC event number
49638@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49639 u32
49640 fc_get_event_number(void)
49641 {
49642- return atomic_add_return(1, &fc_event_seq);
49643+ return atomic_add_return_unchecked(1, &fc_event_seq);
49644 }
49645 EXPORT_SYMBOL(fc_get_event_number);
49646
49647@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49648 {
49649 int error;
49650
49651- atomic_set(&fc_event_seq, 0);
49652+ atomic_set_unchecked(&fc_event_seq, 0);
49653
49654 error = transport_class_register(&fc_host_class);
49655 if (error)
49656@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49657 char *cp;
49658
49659 *val = simple_strtoul(buf, &cp, 0);
49660- if ((*cp && (*cp != '\n')) || (*val < 0))
49661+ if (*cp && (*cp != '\n'))
49662 return -EINVAL;
49663 /*
49664 * Check for overflow; dev_loss_tmo is u32
49665diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49666index fd8ffe6..fd0bebf 100644
49667--- a/drivers/scsi/scsi_transport_iscsi.c
49668+++ b/drivers/scsi/scsi_transport_iscsi.c
49669@@ -79,7 +79,7 @@ struct iscsi_internal {
49670 struct transport_container session_cont;
49671 };
49672
49673-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49674+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49675 static struct workqueue_struct *iscsi_eh_timer_workq;
49676
49677 static DEFINE_IDA(iscsi_sess_ida);
49678@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49679 int err;
49680
49681 ihost = shost->shost_data;
49682- session->sid = atomic_add_return(1, &iscsi_session_nr);
49683+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49684
49685 if (target_id == ISCSI_MAX_TARGET) {
49686 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49687@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49688 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49689 ISCSI_TRANSPORT_VERSION);
49690
49691- atomic_set(&iscsi_session_nr, 0);
49692+ atomic_set_unchecked(&iscsi_session_nr, 0);
49693
49694 err = class_register(&iscsi_transport_class);
49695 if (err)
49696diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49697index d47ffc8..30f46a9 100644
49698--- a/drivers/scsi/scsi_transport_srp.c
49699+++ b/drivers/scsi/scsi_transport_srp.c
49700@@ -36,7 +36,7 @@
49701 #include "scsi_transport_srp_internal.h"
49702
49703 struct srp_host_attrs {
49704- atomic_t next_port_id;
49705+ atomic_unchecked_t next_port_id;
49706 };
49707 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49708
49709@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49710 struct Scsi_Host *shost = dev_to_shost(dev);
49711 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49712
49713- atomic_set(&srp_host->next_port_id, 0);
49714+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49715 return 0;
49716 }
49717
49718@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49719 rport_fast_io_fail_timedout);
49720 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49721
49722- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49723+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49724 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49725
49726 transport_setup_device(&rport->dev);
49727diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49728index 36d1a23..3f33303 100644
49729--- a/drivers/scsi/sd.c
49730+++ b/drivers/scsi/sd.c
49731@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
49732 sdkp->disk = gd;
49733 sdkp->index = index;
49734 atomic_set(&sdkp->openers, 0);
49735- atomic_set(&sdkp->device->ioerr_cnt, 0);
49736+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49737
49738 if (!sdp->request_queue->rq_timeout) {
49739 if (sdp->type != TYPE_MOD)
49740diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49741index df5e961..df6b97f 100644
49742--- a/drivers/scsi/sg.c
49743+++ b/drivers/scsi/sg.c
49744@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49745 sdp->disk->disk_name,
49746 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49747 NULL,
49748- (char *)arg);
49749+ (char __user *)arg);
49750 case BLKTRACESTART:
49751 return blk_trace_startstop(sdp->device->request_queue, 1);
49752 case BLKTRACESTOP:
49753diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49754index d0b28bb..a263613 100644
49755--- a/drivers/spi/spi.c
49756+++ b/drivers/spi/spi.c
49757@@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
49758 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49759
49760 /* portable code must never pass more than 32 bytes */
49761-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49762+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49763
49764 static u8 *buf;
49765
49766diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49767index 2c61783..4d49e4e 100644
49768--- a/drivers/staging/android/timed_output.c
49769+++ b/drivers/staging/android/timed_output.c
49770@@ -25,7 +25,7 @@
49771 #include "timed_output.h"
49772
49773 static struct class *timed_output_class;
49774-static atomic_t device_count;
49775+static atomic_unchecked_t device_count;
49776
49777 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49778 char *buf)
49779@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49780 timed_output_class = class_create(THIS_MODULE, "timed_output");
49781 if (IS_ERR(timed_output_class))
49782 return PTR_ERR(timed_output_class);
49783- atomic_set(&device_count, 0);
49784+ atomic_set_unchecked(&device_count, 0);
49785 timed_output_class->dev_groups = timed_output_groups;
49786 }
49787
49788@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49789 if (ret < 0)
49790 return ret;
49791
49792- tdev->index = atomic_inc_return(&device_count);
49793+ tdev->index = atomic_inc_return_unchecked(&device_count);
49794 tdev->dev = device_create(timed_output_class, NULL,
49795 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49796 if (IS_ERR(tdev->dev))
49797diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49798index fe47cd3..19a1bd1 100644
49799--- a/drivers/staging/gdm724x/gdm_tty.c
49800+++ b/drivers/staging/gdm724x/gdm_tty.c
49801@@ -44,7 +44,7 @@
49802 #define gdm_tty_send_control(n, r, v, d, l) (\
49803 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49804
49805-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49806+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49807
49808 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49809 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49810diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49811index 236ed66..dd9cd74 100644
49812--- a/drivers/staging/imx-drm/imx-drm-core.c
49813+++ b/drivers/staging/imx-drm/imx-drm-core.c
49814@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49815 goto err_busy;
49816 }
49817
49818- if (imxdrm->drm->open_count) {
49819+ if (local_read(&imxdrm->drm->open_count)) {
49820 ret = -EBUSY;
49821 goto err_busy;
49822 }
49823@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49824
49825 mutex_lock(&imxdrm->mutex);
49826
49827- if (imxdrm->drm->open_count) {
49828+ if (local_read(&imxdrm->drm->open_count)) {
49829 ret = -EBUSY;
49830 goto err_busy;
49831 }
49832@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49833
49834 mutex_lock(&imxdrm->mutex);
49835
49836- if (imxdrm->drm->open_count) {
49837+ if (local_read(&imxdrm->drm->open_count)) {
49838 ret = -EBUSY;
49839 goto err_busy;
49840 }
49841diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49842index 3f8020c..649fded 100644
49843--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49844+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49845@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49846 return 0;
49847 }
49848
49849-sfw_test_client_ops_t brw_test_client;
49850-void brw_init_test_client(void)
49851-{
49852- brw_test_client.tso_init = brw_client_init;
49853- brw_test_client.tso_fini = brw_client_fini;
49854- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49855- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49856+sfw_test_client_ops_t brw_test_client = {
49857+ .tso_init = brw_client_init,
49858+ .tso_fini = brw_client_fini,
49859+ .tso_prep_rpc = brw_client_prep_rpc,
49860+ .tso_done_rpc = brw_client_done_rpc,
49861 };
49862
49863 srpc_service_t brw_test_service;
49864diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49865index 050723a..fa6fdf1 100644
49866--- a/drivers/staging/lustre/lnet/selftest/framework.c
49867+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49868@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49869
49870 extern sfw_test_client_ops_t ping_test_client;
49871 extern srpc_service_t ping_test_service;
49872-extern void ping_init_test_client(void);
49873 extern void ping_init_test_service(void);
49874
49875 extern sfw_test_client_ops_t brw_test_client;
49876 extern srpc_service_t brw_test_service;
49877-extern void brw_init_test_client(void);
49878 extern void brw_init_test_service(void);
49879
49880
49881@@ -1684,12 +1682,10 @@ sfw_startup (void)
49882 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49883 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49884
49885- brw_init_test_client();
49886 brw_init_test_service();
49887 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49888 LASSERT (rc == 0);
49889
49890- ping_init_test_client();
49891 ping_init_test_service();
49892 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49893 LASSERT (rc == 0);
49894diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49895index 750cac4..e4d751f 100644
49896--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49897+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49898@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49899 return 0;
49900 }
49901
49902-sfw_test_client_ops_t ping_test_client;
49903-void ping_init_test_client(void)
49904-{
49905- ping_test_client.tso_init = ping_client_init;
49906- ping_test_client.tso_fini = ping_client_fini;
49907- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49908- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49909-}
49910+sfw_test_client_ops_t ping_test_client = {
49911+ .tso_init = ping_client_init,
49912+ .tso_fini = ping_client_fini,
49913+ .tso_prep_rpc = ping_client_prep_rpc,
49914+ .tso_done_rpc = ping_client_done_rpc,
49915+};
49916
49917 srpc_service_t ping_test_service;
49918 void ping_init_test_service(void)
49919diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49920index ec4bb5e..740c6dd 100644
49921--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49922+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49923@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49924 ldlm_completion_callback lcs_completion;
49925 ldlm_blocking_callback lcs_blocking;
49926 ldlm_glimpse_callback lcs_glimpse;
49927-};
49928+} __no_const;
49929
49930 /* ldlm_lockd.c */
49931 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49932diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49933index c3470ce..2bef527 100644
49934--- a/drivers/staging/lustre/lustre/include/obd.h
49935+++ b/drivers/staging/lustre/lustre/include/obd.h
49936@@ -1426,7 +1426,7 @@ struct md_ops {
49937 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49938 * wrapper function in include/linux/obd_class.h.
49939 */
49940-};
49941+} __no_const;
49942
49943 struct lsm_operations {
49944 void (*lsm_free)(struct lov_stripe_md *);
49945diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49946index c9aae13..60ea292 100644
49947--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49948+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49949@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49950 int added = (mode == LCK_NL);
49951 int overlaps = 0;
49952 int splitted = 0;
49953- const struct ldlm_callback_suite null_cbs = { NULL };
49954+ const struct ldlm_callback_suite null_cbs = { };
49955
49956 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49957 LPU64" end "LPU64"\n", *flags,
49958diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49959index e947b91..f408990 100644
49960--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49961+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49962@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49963 int LL_PROC_PROTO(proc_console_max_delay_cs)
49964 {
49965 int rc, max_delay_cs;
49966- ctl_table_t dummy = *table;
49967+ ctl_table_no_const dummy = *table;
49968 cfs_duration_t d;
49969
49970 dummy.data = &max_delay_cs;
49971@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49972 int LL_PROC_PROTO(proc_console_min_delay_cs)
49973 {
49974 int rc, min_delay_cs;
49975- ctl_table_t dummy = *table;
49976+ ctl_table_no_const dummy = *table;
49977 cfs_duration_t d;
49978
49979 dummy.data = &min_delay_cs;
49980@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49981 int LL_PROC_PROTO(proc_console_backoff)
49982 {
49983 int rc, backoff;
49984- ctl_table_t dummy = *table;
49985+ ctl_table_no_const dummy = *table;
49986
49987 dummy.data = &backoff;
49988 dummy.proc_handler = &proc_dointvec;
49989diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49990index 24ae26d..9d09cab 100644
49991--- a/drivers/staging/lustre/lustre/libcfs/module.c
49992+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49993@@ -313,11 +313,11 @@ out:
49994
49995
49996 struct cfs_psdev_ops libcfs_psdev_ops = {
49997- libcfs_psdev_open,
49998- libcfs_psdev_release,
49999- NULL,
50000- NULL,
50001- libcfs_ioctl
50002+ .p_open = libcfs_psdev_open,
50003+ .p_close = libcfs_psdev_release,
50004+ .p_read = NULL,
50005+ .p_write = NULL,
50006+ .p_ioctl = libcfs_ioctl
50007 };
50008
50009 extern int insert_proc(void);
50010diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50011index 52b7731..d604da0 100644
50012--- a/drivers/staging/lustre/lustre/llite/dir.c
50013+++ b/drivers/staging/lustre/lustre/llite/dir.c
50014@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50015 int mode;
50016 int err;
50017
50018- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50019+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50020 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50021 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50022 lump);
50023diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50024index 480b7c4..6846324 100644
50025--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50026+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50027@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50028
50029 static int solo_sysfs_init(struct solo_dev *solo_dev)
50030 {
50031- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50032+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50033 struct device *dev = &solo_dev->dev;
50034 const char *driver;
50035 int i;
50036diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50037index 1db18c7..35e6afc 100644
50038--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50039+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50040@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50041
50042 int solo_g723_init(struct solo_dev *solo_dev)
50043 {
50044- static struct snd_device_ops ops = { NULL };
50045+ static struct snd_device_ops ops = { };
50046 struct snd_card *card;
50047 struct snd_kcontrol_new kctl;
50048 char name[32];
50049diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50050index 7f2f247..d999137 100644
50051--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50052+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50053@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50054
50055 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50056 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50057- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50058+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50059 if (p2m_id < 0)
50060 p2m_id = -p2m_id;
50061 }
50062diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50063index 8964f8b..36eb087 100644
50064--- a/drivers/staging/media/solo6x10/solo6x10.h
50065+++ b/drivers/staging/media/solo6x10/solo6x10.h
50066@@ -237,7 +237,7 @@ struct solo_dev {
50067
50068 /* P2M DMA Engine */
50069 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50070- atomic_t p2m_count;
50071+ atomic_unchecked_t p2m_count;
50072 int p2m_jiffies;
50073 unsigned int p2m_timeouts;
50074
50075diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50076index a0f4868..139f1fb 100644
50077--- a/drivers/staging/octeon/ethernet-rx.c
50078+++ b/drivers/staging/octeon/ethernet-rx.c
50079@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50080 /* Increment RX stats for virtual ports */
50081 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50082 #ifdef CONFIG_64BIT
50083- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50084- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50085+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50086+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50087 #else
50088- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50089- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50090+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50091+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50092 #endif
50093 }
50094 netif_receive_skb(skb);
50095@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50096 dev->name);
50097 */
50098 #ifdef CONFIG_64BIT
50099- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50100+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50101 #else
50102- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50103+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50104 #endif
50105 dev_kfree_skb_irq(skb);
50106 }
50107diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50108index 089dc4b..c9a687e 100644
50109--- a/drivers/staging/octeon/ethernet.c
50110+++ b/drivers/staging/octeon/ethernet.c
50111@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50112 * since the RX tasklet also increments it.
50113 */
50114 #ifdef CONFIG_64BIT
50115- atomic64_add(rx_status.dropped_packets,
50116- (atomic64_t *)&priv->stats.rx_dropped);
50117+ atomic64_add_unchecked(rx_status.dropped_packets,
50118+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50119 #else
50120- atomic_add(rx_status.dropped_packets,
50121- (atomic_t *)&priv->stats.rx_dropped);
50122+ atomic_add_unchecked(rx_status.dropped_packets,
50123+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50124 #endif
50125 }
50126
50127diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50128index c274b34..f84de76 100644
50129--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50130+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50131@@ -271,7 +271,7 @@ struct hal_ops {
50132 s32 (*c2h_handler)(struct adapter *padapter,
50133 struct c2h_evt_hdr *c2h_evt);
50134 c2h_id_filter c2h_id_filter_ccx;
50135-};
50136+} __no_const;
50137
50138 enum rt_eeprom_type {
50139 EEPROM_93C46,
50140diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50141index 3d1dfcc..ff5620a 100644
50142--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50143+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50144@@ -126,7 +126,7 @@ struct _io_ops {
50145 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50146 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50147 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50148-};
50149+} __no_const;
50150
50151 struct io_req {
50152 struct list_head list;
50153diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50154index dc23395..cf7e9b1 100644
50155--- a/drivers/staging/rtl8712/rtl871x_io.h
50156+++ b/drivers/staging/rtl8712/rtl871x_io.h
50157@@ -108,7 +108,7 @@ struct _io_ops {
50158 u8 *pmem);
50159 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50160 u8 *pmem);
50161-};
50162+} __no_const;
50163
50164 struct io_req {
50165 struct list_head list;
50166diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50167index 1f5088b..0e59820 100644
50168--- a/drivers/staging/sbe-2t3e3/netdev.c
50169+++ b/drivers/staging/sbe-2t3e3/netdev.c
50170@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50171 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50172
50173 if (rlen)
50174- if (copy_to_user(data, &resp, rlen))
50175+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50176 return -EFAULT;
50177
50178 return 0;
50179diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50180index a863a98..d272795 100644
50181--- a/drivers/staging/usbip/vhci.h
50182+++ b/drivers/staging/usbip/vhci.h
50183@@ -83,7 +83,7 @@ struct vhci_hcd {
50184 unsigned resuming:1;
50185 unsigned long re_timeout;
50186
50187- atomic_t seqnum;
50188+ atomic_unchecked_t seqnum;
50189
50190 /*
50191 * NOTE:
50192diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50193index 72391ef..7c6717a 100644
50194--- a/drivers/staging/usbip/vhci_hcd.c
50195+++ b/drivers/staging/usbip/vhci_hcd.c
50196@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50197
50198 spin_lock(&vdev->priv_lock);
50199
50200- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50201+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50202 if (priv->seqnum == 0xffff)
50203 dev_info(&urb->dev->dev, "seqnum max\n");
50204
50205@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50206 return -ENOMEM;
50207 }
50208
50209- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50210+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50211 if (unlink->seqnum == 0xffff)
50212 pr_info("seqnum max\n");
50213
50214@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50215 vdev->rhport = rhport;
50216 }
50217
50218- atomic_set(&vhci->seqnum, 0);
50219+ atomic_set_unchecked(&vhci->seqnum, 0);
50220 spin_lock_init(&vhci->lock);
50221
50222 hcd->power_budget = 0; /* no limit */
50223diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50224index d07fcb5..358e1e1 100644
50225--- a/drivers/staging/usbip/vhci_rx.c
50226+++ b/drivers/staging/usbip/vhci_rx.c
50227@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50228 if (!urb) {
50229 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50230 pr_info("max seqnum %d\n",
50231- atomic_read(&the_controller->seqnum));
50232+ atomic_read_unchecked(&the_controller->seqnum));
50233 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50234 return;
50235 }
50236diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50237index 6eecd53..29317c6 100644
50238--- a/drivers/staging/vt6655/hostap.c
50239+++ b/drivers/staging/vt6655/hostap.c
50240@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50241 *
50242 */
50243
50244+static net_device_ops_no_const apdev_netdev_ops;
50245+
50246 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50247 {
50248 PSDevice apdev_priv;
50249 struct net_device *dev = pDevice->dev;
50250 int ret;
50251- const struct net_device_ops apdev_netdev_ops = {
50252- .ndo_start_xmit = pDevice->tx_80211,
50253- };
50254
50255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50256
50257@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50258 *apdev_priv = *pDevice;
50259 eth_hw_addr_inherit(pDevice->apdev, dev);
50260
50261+ /* only half broken now */
50262+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50263 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50264
50265 pDevice->apdev->type = ARPHRD_IEEE80211;
50266diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50267index 67ba48b..24e602f 100644
50268--- a/drivers/staging/vt6656/hostap.c
50269+++ b/drivers/staging/vt6656/hostap.c
50270@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50271 *
50272 */
50273
50274+static net_device_ops_no_const apdev_netdev_ops;
50275+
50276 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50277 {
50278 struct vnt_private *apdev_priv;
50279 struct net_device *dev = pDevice->dev;
50280 int ret;
50281- const struct net_device_ops apdev_netdev_ops = {
50282- .ndo_start_xmit = pDevice->tx_80211,
50283- };
50284
50285 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50286
50287@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50288 *apdev_priv = *pDevice;
50289 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50290
50291+ /* only half broken now */
50292+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50293 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50294
50295 pDevice->apdev->type = ARPHRD_IEEE80211;
50296diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50297index 24884ca..26c8220 100644
50298--- a/drivers/target/sbp/sbp_target.c
50299+++ b/drivers/target/sbp/sbp_target.c
50300@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50301
50302 #define SESSION_MAINTENANCE_INTERVAL HZ
50303
50304-static atomic_t login_id = ATOMIC_INIT(0);
50305+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50306
50307 static void session_maintenance_work(struct work_struct *);
50308 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50309@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50310 login->lun = se_lun;
50311 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50312 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50313- login->login_id = atomic_inc_return(&login_id);
50314+ login->login_id = atomic_inc_return_unchecked(&login_id);
50315
50316 login->tgt_agt = sbp_target_agent_register(login);
50317 if (IS_ERR(login->tgt_agt)) {
50318diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50319index 65001e1..2ebfbb9 100644
50320--- a/drivers/target/target_core_device.c
50321+++ b/drivers/target/target_core_device.c
50322@@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50323 spin_lock_init(&dev->se_tmr_lock);
50324 spin_lock_init(&dev->qf_cmd_lock);
50325 sema_init(&dev->caw_sem, 1);
50326- atomic_set(&dev->dev_ordered_id, 0);
50327+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50328 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50329 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50330 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50331diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50332index 2956250..b10f722 100644
50333--- a/drivers/target/target_core_transport.c
50334+++ b/drivers/target/target_core_transport.c
50335@@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50336 * Used to determine when ORDERED commands should go from
50337 * Dormant to Active status.
50338 */
50339- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50340+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50341 smp_mb__after_atomic_inc();
50342 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50343 cmd->se_ordered_id, cmd->sam_task_attr,
50344diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50345index 04b1be7..5eff86d 100644
50346--- a/drivers/thermal/of-thermal.c
50347+++ b/drivers/thermal/of-thermal.c
50348@@ -30,6 +30,7 @@
50349 #include <linux/err.h>
50350 #include <linux/export.h>
50351 #include <linux/string.h>
50352+#include <linux/mm.h>
50353
50354 #include "thermal_core.h"
50355
50356@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50357 tz->get_trend = get_trend;
50358 tz->sensor_data = data;
50359
50360- tzd->ops->get_temp = of_thermal_get_temp;
50361- tzd->ops->get_trend = of_thermal_get_trend;
50362+ pax_open_kernel();
50363+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50364+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50365+ pax_close_kernel();
50366 mutex_unlock(&tzd->lock);
50367
50368 return tzd;
50369@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50370 return;
50371
50372 mutex_lock(&tzd->lock);
50373- tzd->ops->get_temp = NULL;
50374- tzd->ops->get_trend = NULL;
50375+ pax_open_kernel();
50376+ *(void **)&tzd->ops->get_temp = NULL;
50377+ *(void **)&tzd->ops->get_trend = NULL;
50378+ pax_close_kernel();
50379
50380 tz->get_temp = NULL;
50381 tz->get_trend = NULL;
50382diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50383index a57bb5a..1f727d33 100644
50384--- a/drivers/tty/cyclades.c
50385+++ b/drivers/tty/cyclades.c
50386@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50387 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50388 info->port.count);
50389 #endif
50390- info->port.count++;
50391+ atomic_inc(&info->port.count);
50392 #ifdef CY_DEBUG_COUNT
50393 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50394- current->pid, info->port.count);
50395+ current->pid, atomic_read(&info->port.count));
50396 #endif
50397
50398 /*
50399@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50400 for (j = 0; j < cy_card[i].nports; j++) {
50401 info = &cy_card[i].ports[j];
50402
50403- if (info->port.count) {
50404+ if (atomic_read(&info->port.count)) {
50405 /* XXX is the ldisc num worth this? */
50406 struct tty_struct *tty;
50407 struct tty_ldisc *ld;
50408diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50409index 94f9e3a..4c8afa8 100644
50410--- a/drivers/tty/hvc/hvc_console.c
50411+++ b/drivers/tty/hvc/hvc_console.c
50412@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50413
50414 spin_lock_irqsave(&hp->port.lock, flags);
50415 /* Check and then increment for fast path open. */
50416- if (hp->port.count++ > 0) {
50417+ if (atomic_inc_return(&hp->port.count) > 1) {
50418 spin_unlock_irqrestore(&hp->port.lock, flags);
50419 hvc_kick();
50420 return 0;
50421@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50422
50423 spin_lock_irqsave(&hp->port.lock, flags);
50424
50425- if (--hp->port.count == 0) {
50426+ if (atomic_dec_return(&hp->port.count) == 0) {
50427 spin_unlock_irqrestore(&hp->port.lock, flags);
50428 /* We are done with the tty pointer now. */
50429 tty_port_tty_set(&hp->port, NULL);
50430@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50431 */
50432 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50433 } else {
50434- if (hp->port.count < 0)
50435+ if (atomic_read(&hp->port.count) < 0)
50436 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50437- hp->vtermno, hp->port.count);
50438+ hp->vtermno, atomic_read(&hp->port.count));
50439 spin_unlock_irqrestore(&hp->port.lock, flags);
50440 }
50441 }
50442@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50443 * open->hangup case this can be called after the final close so prevent
50444 * that from happening for now.
50445 */
50446- if (hp->port.count <= 0) {
50447+ if (atomic_read(&hp->port.count) <= 0) {
50448 spin_unlock_irqrestore(&hp->port.lock, flags);
50449 return;
50450 }
50451
50452- hp->port.count = 0;
50453+ atomic_set(&hp->port.count, 0);
50454 spin_unlock_irqrestore(&hp->port.lock, flags);
50455 tty_port_tty_set(&hp->port, NULL);
50456
50457@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50458 return -EPIPE;
50459
50460 /* FIXME what's this (unprotected) check for? */
50461- if (hp->port.count <= 0)
50462+ if (atomic_read(&hp->port.count) <= 0)
50463 return -EIO;
50464
50465 spin_lock_irqsave(&hp->lock, flags);
50466diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50467index 81e939e..95ead10 100644
50468--- a/drivers/tty/hvc/hvcs.c
50469+++ b/drivers/tty/hvc/hvcs.c
50470@@ -83,6 +83,7 @@
50471 #include <asm/hvcserver.h>
50472 #include <asm/uaccess.h>
50473 #include <asm/vio.h>
50474+#include <asm/local.h>
50475
50476 /*
50477 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50478@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50479
50480 spin_lock_irqsave(&hvcsd->lock, flags);
50481
50482- if (hvcsd->port.count > 0) {
50483+ if (atomic_read(&hvcsd->port.count) > 0) {
50484 spin_unlock_irqrestore(&hvcsd->lock, flags);
50485 printk(KERN_INFO "HVCS: vterm state unchanged. "
50486 "The hvcs device node is still in use.\n");
50487@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50488 }
50489 }
50490
50491- hvcsd->port.count = 0;
50492+ atomic_set(&hvcsd->port.count, 0);
50493 hvcsd->port.tty = tty;
50494 tty->driver_data = hvcsd;
50495
50496@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50497 unsigned long flags;
50498
50499 spin_lock_irqsave(&hvcsd->lock, flags);
50500- hvcsd->port.count++;
50501+ atomic_inc(&hvcsd->port.count);
50502 hvcsd->todo_mask |= HVCS_SCHED_READ;
50503 spin_unlock_irqrestore(&hvcsd->lock, flags);
50504
50505@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50506 hvcsd = tty->driver_data;
50507
50508 spin_lock_irqsave(&hvcsd->lock, flags);
50509- if (--hvcsd->port.count == 0) {
50510+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50511
50512 vio_disable_interrupts(hvcsd->vdev);
50513
50514@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50515
50516 free_irq(irq, hvcsd);
50517 return;
50518- } else if (hvcsd->port.count < 0) {
50519+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50520 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50521 " is missmanaged.\n",
50522- hvcsd->vdev->unit_address, hvcsd->port.count);
50523+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50524 }
50525
50526 spin_unlock_irqrestore(&hvcsd->lock, flags);
50527@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50528
50529 spin_lock_irqsave(&hvcsd->lock, flags);
50530 /* Preserve this so that we know how many kref refs to put */
50531- temp_open_count = hvcsd->port.count;
50532+ temp_open_count = atomic_read(&hvcsd->port.count);
50533
50534 /*
50535 * Don't kref put inside the spinlock because the destruction
50536@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50537 tty->driver_data = NULL;
50538 hvcsd->port.tty = NULL;
50539
50540- hvcsd->port.count = 0;
50541+ atomic_set(&hvcsd->port.count, 0);
50542
50543 /* This will drop any buffered data on the floor which is OK in a hangup
50544 * scenario. */
50545@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50546 * the middle of a write operation? This is a crummy place to do this
50547 * but we want to keep it all in the spinlock.
50548 */
50549- if (hvcsd->port.count <= 0) {
50550+ if (atomic_read(&hvcsd->port.count) <= 0) {
50551 spin_unlock_irqrestore(&hvcsd->lock, flags);
50552 return -ENODEV;
50553 }
50554@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50555 {
50556 struct hvcs_struct *hvcsd = tty->driver_data;
50557
50558- if (!hvcsd || hvcsd->port.count <= 0)
50559+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50560 return 0;
50561
50562 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50563diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50564index 4190199..06d5bfa 100644
50565--- a/drivers/tty/hvc/hvsi.c
50566+++ b/drivers/tty/hvc/hvsi.c
50567@@ -85,7 +85,7 @@ struct hvsi_struct {
50568 int n_outbuf;
50569 uint32_t vtermno;
50570 uint32_t virq;
50571- atomic_t seqno; /* HVSI packet sequence number */
50572+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50573 uint16_t mctrl;
50574 uint8_t state; /* HVSI protocol state */
50575 uint8_t flags;
50576@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50577
50578 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50579 packet.hdr.len = sizeof(struct hvsi_query_response);
50580- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50581+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50582 packet.verb = VSV_SEND_VERSION_NUMBER;
50583 packet.u.version = HVSI_VERSION;
50584 packet.query_seqno = query_seqno+1;
50585@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50586
50587 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50588 packet.hdr.len = sizeof(struct hvsi_query);
50589- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50590+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50591 packet.verb = verb;
50592
50593 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50594@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50595 int wrote;
50596
50597 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50598- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50599+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50600 packet.hdr.len = sizeof(struct hvsi_control);
50601 packet.verb = VSV_SET_MODEM_CTL;
50602 packet.mask = HVSI_TSDTR;
50603@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50604 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50605
50606 packet.hdr.type = VS_DATA_PACKET_HEADER;
50607- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50608+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50609 packet.hdr.len = count + sizeof(struct hvsi_header);
50610 memcpy(&packet.data, buf, count);
50611
50612@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50613 struct hvsi_control packet __ALIGNED__;
50614
50615 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50616- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50617+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50618 packet.hdr.len = 6;
50619 packet.verb = VSV_CLOSE_PROTOCOL;
50620
50621@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50622
50623 tty_port_tty_set(&hp->port, tty);
50624 spin_lock_irqsave(&hp->lock, flags);
50625- hp->port.count++;
50626+ atomic_inc(&hp->port.count);
50627 atomic_set(&hp->seqno, 0);
50628 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50629 spin_unlock_irqrestore(&hp->lock, flags);
50630@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50631
50632 spin_lock_irqsave(&hp->lock, flags);
50633
50634- if (--hp->port.count == 0) {
50635+ if (atomic_dec_return(&hp->port.count) == 0) {
50636 tty_port_tty_set(&hp->port, NULL);
50637 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50638
50639@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50640
50641 spin_lock_irqsave(&hp->lock, flags);
50642 }
50643- } else if (hp->port.count < 0)
50644+ } else if (atomic_read(&hp->port.count) < 0)
50645 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50646- hp - hvsi_ports, hp->port.count);
50647+ hp - hvsi_ports, atomic_read(&hp->port.count));
50648
50649 spin_unlock_irqrestore(&hp->lock, flags);
50650 }
50651@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50652 tty_port_tty_set(&hp->port, NULL);
50653
50654 spin_lock_irqsave(&hp->lock, flags);
50655- hp->port.count = 0;
50656+ atomic_set(&hp->port.count, 0);
50657 hp->n_outbuf = 0;
50658 spin_unlock_irqrestore(&hp->lock, flags);
50659 }
50660diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50661index 7ae6c29..05c6dba 100644
50662--- a/drivers/tty/hvc/hvsi_lib.c
50663+++ b/drivers/tty/hvc/hvsi_lib.c
50664@@ -8,7 +8,7 @@
50665
50666 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50667 {
50668- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50669+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50670
50671 /* Assumes that always succeeds, works in practice */
50672 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50673@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50674
50675 /* Reset state */
50676 pv->established = 0;
50677- atomic_set(&pv->seqno, 0);
50678+ atomic_set_unchecked(&pv->seqno, 0);
50679
50680 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50681
50682diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50683index 17ee3bf..8d2520d 100644
50684--- a/drivers/tty/ipwireless/tty.c
50685+++ b/drivers/tty/ipwireless/tty.c
50686@@ -28,6 +28,7 @@
50687 #include <linux/tty_driver.h>
50688 #include <linux/tty_flip.h>
50689 #include <linux/uaccess.h>
50690+#include <asm/local.h>
50691
50692 #include "tty.h"
50693 #include "network.h"
50694@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50695 mutex_unlock(&tty->ipw_tty_mutex);
50696 return -ENODEV;
50697 }
50698- if (tty->port.count == 0)
50699+ if (atomic_read(&tty->port.count) == 0)
50700 tty->tx_bytes_queued = 0;
50701
50702- tty->port.count++;
50703+ atomic_inc(&tty->port.count);
50704
50705 tty->port.tty = linux_tty;
50706 linux_tty->driver_data = tty;
50707@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50708
50709 static void do_ipw_close(struct ipw_tty *tty)
50710 {
50711- tty->port.count--;
50712-
50713- if (tty->port.count == 0) {
50714+ if (atomic_dec_return(&tty->port.count) == 0) {
50715 struct tty_struct *linux_tty = tty->port.tty;
50716
50717 if (linux_tty != NULL) {
50718@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50719 return;
50720
50721 mutex_lock(&tty->ipw_tty_mutex);
50722- if (tty->port.count == 0) {
50723+ if (atomic_read(&tty->port.count) == 0) {
50724 mutex_unlock(&tty->ipw_tty_mutex);
50725 return;
50726 }
50727@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50728
50729 mutex_lock(&tty->ipw_tty_mutex);
50730
50731- if (!tty->port.count) {
50732+ if (!atomic_read(&tty->port.count)) {
50733 mutex_unlock(&tty->ipw_tty_mutex);
50734 return;
50735 }
50736@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50737 return -ENODEV;
50738
50739 mutex_lock(&tty->ipw_tty_mutex);
50740- if (!tty->port.count) {
50741+ if (!atomic_read(&tty->port.count)) {
50742 mutex_unlock(&tty->ipw_tty_mutex);
50743 return -EINVAL;
50744 }
50745@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50746 if (!tty)
50747 return -ENODEV;
50748
50749- if (!tty->port.count)
50750+ if (!atomic_read(&tty->port.count))
50751 return -EINVAL;
50752
50753 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50754@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50755 if (!tty)
50756 return 0;
50757
50758- if (!tty->port.count)
50759+ if (!atomic_read(&tty->port.count))
50760 return 0;
50761
50762 return tty->tx_bytes_queued;
50763@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50764 if (!tty)
50765 return -ENODEV;
50766
50767- if (!tty->port.count)
50768+ if (!atomic_read(&tty->port.count))
50769 return -EINVAL;
50770
50771 return get_control_lines(tty);
50772@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50773 if (!tty)
50774 return -ENODEV;
50775
50776- if (!tty->port.count)
50777+ if (!atomic_read(&tty->port.count))
50778 return -EINVAL;
50779
50780 return set_control_lines(tty, set, clear);
50781@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50782 if (!tty)
50783 return -ENODEV;
50784
50785- if (!tty->port.count)
50786+ if (!atomic_read(&tty->port.count))
50787 return -EINVAL;
50788
50789 /* FIXME: Exactly how is the tty object locked here .. */
50790@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50791 * are gone */
50792 mutex_lock(&ttyj->ipw_tty_mutex);
50793 }
50794- while (ttyj->port.count)
50795+ while (atomic_read(&ttyj->port.count))
50796 do_ipw_close(ttyj);
50797 ipwireless_disassociate_network_ttys(network,
50798 ttyj->channel_idx);
50799diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50800index 1deaca4..c8582d4 100644
50801--- a/drivers/tty/moxa.c
50802+++ b/drivers/tty/moxa.c
50803@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50804 }
50805
50806 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50807- ch->port.count++;
50808+ atomic_inc(&ch->port.count);
50809 tty->driver_data = ch;
50810 tty_port_tty_set(&ch->port, tty);
50811 mutex_lock(&ch->port.mutex);
50812diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50813index 2ebe47b..3205833 100644
50814--- a/drivers/tty/n_gsm.c
50815+++ b/drivers/tty/n_gsm.c
50816@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50817 spin_lock_init(&dlci->lock);
50818 mutex_init(&dlci->mutex);
50819 dlci->fifo = &dlci->_fifo;
50820- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50821+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50822 kfree(dlci);
50823 return NULL;
50824 }
50825@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50826 struct gsm_dlci *dlci = tty->driver_data;
50827 struct tty_port *port = &dlci->port;
50828
50829- port->count++;
50830+ atomic_inc(&port->count);
50831 tty_port_tty_set(port, tty);
50832
50833 dlci->modem_rx = 0;
50834diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50835index d15624c..bd628c6 100644
50836--- a/drivers/tty/n_tty.c
50837+++ b/drivers/tty/n_tty.c
50838@@ -115,7 +115,7 @@ struct n_tty_data {
50839 int minimum_to_wake;
50840
50841 /* consumer-published */
50842- size_t read_tail;
50843+ size_t read_tail __intentional_overflow(-1);
50844 size_t line_start;
50845
50846 /* protected by output lock */
50847@@ -2356,10 +2356,18 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
50848 if (tty->ops->flush_chars)
50849 tty->ops->flush_chars(tty);
50850 } else {
50851+ struct n_tty_data *ldata = tty->disc_data;
50852+ bool lock;
50853+
50854+ lock = L_ECHO(tty) || (ldata->icanon & L_ECHONL(tty));
50855+ if (lock)
50856+ mutex_lock(&ldata->output_lock);
50857 while (nr > 0) {
50858 c = tty->ops->write(tty, b, nr);
50859 if (c < 0) {
50860 retval = c;
50861+ if (lock)
50862+ mutex_unlock(&ldata->output_lock);
50863 goto break_out;
50864 }
50865 if (!c)
50866@@ -2367,6 +2375,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
50867 b += c;
50868 nr -= c;
50869 }
50870+ if (lock)
50871+ mutex_unlock(&ldata->output_lock);
50872 }
50873 if (!nr)
50874 break;
50875@@ -2515,6 +2525,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50876 {
50877 *ops = tty_ldisc_N_TTY;
50878 ops->owner = NULL;
50879- ops->refcount = ops->flags = 0;
50880+ atomic_set(&ops->refcount, 0);
50881+ ops->flags = 0;
50882 }
50883 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50884diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50885index 25c9bc7..24077b7 100644
50886--- a/drivers/tty/pty.c
50887+++ b/drivers/tty/pty.c
50888@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50889 panic("Couldn't register Unix98 pts driver");
50890
50891 /* Now create the /dev/ptmx special device */
50892+ pax_open_kernel();
50893 tty_default_fops(&ptmx_fops);
50894- ptmx_fops.open = ptmx_open;
50895+ *(void **)&ptmx_fops.open = ptmx_open;
50896+ pax_close_kernel();
50897
50898 cdev_init(&ptmx_cdev, &ptmx_fops);
50899 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50900diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50901index 383c4c7..d408e21 100644
50902--- a/drivers/tty/rocket.c
50903+++ b/drivers/tty/rocket.c
50904@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50905 tty->driver_data = info;
50906 tty_port_tty_set(port, tty);
50907
50908- if (port->count++ == 0) {
50909+ if (atomic_inc_return(&port->count) == 1) {
50910 atomic_inc(&rp_num_ports_open);
50911
50912 #ifdef ROCKET_DEBUG_OPEN
50913@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50914 #endif
50915 }
50916 #ifdef ROCKET_DEBUG_OPEN
50917- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50918+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50919 #endif
50920
50921 /*
50922@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50923 spin_unlock_irqrestore(&info->port.lock, flags);
50924 return;
50925 }
50926- if (info->port.count)
50927+ if (atomic_read(&info->port.count))
50928 atomic_dec(&rp_num_ports_open);
50929 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50930 spin_unlock_irqrestore(&info->port.lock, flags);
50931diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50932index 1274499..f541382 100644
50933--- a/drivers/tty/serial/ioc4_serial.c
50934+++ b/drivers/tty/serial/ioc4_serial.c
50935@@ -437,7 +437,7 @@ struct ioc4_soft {
50936 } is_intr_info[MAX_IOC4_INTR_ENTS];
50937
50938 /* Number of entries active in the above array */
50939- atomic_t is_num_intrs;
50940+ atomic_unchecked_t is_num_intrs;
50941 } is_intr_type[IOC4_NUM_INTR_TYPES];
50942
50943 /* is_ir_lock must be held while
50944@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50945 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50946 || (type == IOC4_OTHER_INTR_TYPE)));
50947
50948- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50949+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50950 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50951
50952 /* Save off the lower level interrupt handler */
50953@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50954
50955 soft = arg;
50956 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50957- num_intrs = (int)atomic_read(
50958+ num_intrs = (int)atomic_read_unchecked(
50959 &soft->is_intr_type[intr_type].is_num_intrs);
50960
50961 this_mir = this_ir = pending_intrs(soft, intr_type);
50962diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50963index a260cde..6b2b5ce 100644
50964--- a/drivers/tty/serial/kgdboc.c
50965+++ b/drivers/tty/serial/kgdboc.c
50966@@ -24,8 +24,9 @@
50967 #define MAX_CONFIG_LEN 40
50968
50969 static struct kgdb_io kgdboc_io_ops;
50970+static struct kgdb_io kgdboc_io_ops_console;
50971
50972-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50973+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50974 static int configured = -1;
50975
50976 static char config[MAX_CONFIG_LEN];
50977@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50978 kgdboc_unregister_kbd();
50979 if (configured == 1)
50980 kgdb_unregister_io_module(&kgdboc_io_ops);
50981+ else if (configured == 2)
50982+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50983 }
50984
50985 static int configure_kgdboc(void)
50986@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50987 int err;
50988 char *cptr = config;
50989 struct console *cons;
50990+ int is_console = 0;
50991
50992 err = kgdboc_option_setup(config);
50993 if (err || !strlen(config) || isspace(config[0]))
50994 goto noconfig;
50995
50996 err = -ENODEV;
50997- kgdboc_io_ops.is_console = 0;
50998 kgdb_tty_driver = NULL;
50999
51000 kgdboc_use_kms = 0;
51001@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51002 int idx;
51003 if (cons->device && cons->device(cons, &idx) == p &&
51004 idx == tty_line) {
51005- kgdboc_io_ops.is_console = 1;
51006+ is_console = 1;
51007 break;
51008 }
51009 cons = cons->next;
51010@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51011 kgdb_tty_line = tty_line;
51012
51013 do_register:
51014- err = kgdb_register_io_module(&kgdboc_io_ops);
51015+ if (is_console) {
51016+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51017+ configured = 2;
51018+ } else {
51019+ err = kgdb_register_io_module(&kgdboc_io_ops);
51020+ configured = 1;
51021+ }
51022 if (err)
51023 goto noconfig;
51024
51025@@ -205,8 +214,6 @@ do_register:
51026 if (err)
51027 goto nmi_con_failed;
51028
51029- configured = 1;
51030-
51031 return 0;
51032
51033 nmi_con_failed:
51034@@ -223,7 +230,7 @@ noconfig:
51035 static int __init init_kgdboc(void)
51036 {
51037 /* Already configured? */
51038- if (configured == 1)
51039+ if (configured >= 1)
51040 return 0;
51041
51042 return configure_kgdboc();
51043@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51044 if (config[len - 1] == '\n')
51045 config[len - 1] = '\0';
51046
51047- if (configured == 1)
51048+ if (configured >= 1)
51049 cleanup_kgdboc();
51050
51051 /* Go and configure with the new params. */
51052@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51053 .post_exception = kgdboc_post_exp_handler,
51054 };
51055
51056+static struct kgdb_io kgdboc_io_ops_console = {
51057+ .name = "kgdboc",
51058+ .read_char = kgdboc_get_char,
51059+ .write_char = kgdboc_put_char,
51060+ .pre_exception = kgdboc_pre_exp_handler,
51061+ .post_exception = kgdboc_post_exp_handler,
51062+ .is_console = 1
51063+};
51064+
51065 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51066 /* This is only available if kgdboc is a built in for early debugging */
51067 static int __init kgdboc_early_init(char *opt)
51068diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51069index b5d779c..3622cfe 100644
51070--- a/drivers/tty/serial/msm_serial.c
51071+++ b/drivers/tty/serial/msm_serial.c
51072@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
51073 .cons = MSM_CONSOLE,
51074 };
51075
51076-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51077+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51078
51079 static const struct of_device_id msm_uartdm_table[] = {
51080 { .compatible = "qcom,msm-uartdm" },
51081@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51082 int irq;
51083
51084 if (pdev->id == -1)
51085- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51086+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51087
51088 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51089 return -ENXIO;
51090diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51091index 9cd706d..6ff2de7 100644
51092--- a/drivers/tty/serial/samsung.c
51093+++ b/drivers/tty/serial/samsung.c
51094@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51095 }
51096 }
51097
51098+static int s3c64xx_serial_startup(struct uart_port *port);
51099 static int s3c24xx_serial_startup(struct uart_port *port)
51100 {
51101 struct s3c24xx_uart_port *ourport = to_ourport(port);
51102 int ret;
51103
51104+ /* Startup sequence is different for s3c64xx and higher SoC's */
51105+ if (s3c24xx_serial_has_interrupt_mask(port))
51106+ return s3c64xx_serial_startup(port);
51107+
51108 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51109 port->mapbase, port->membase);
51110
51111@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51112 /* setup info for port */
51113 port->dev = &platdev->dev;
51114
51115- /* Startup sequence is different for s3c64xx and higher SoC's */
51116- if (s3c24xx_serial_has_interrupt_mask(port))
51117- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51118-
51119 port->uartclk = 1;
51120
51121 if (cfg->uart_flags & UPF_CONS_FLOW) {
51122diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51123index ece2049..fba2524 100644
51124--- a/drivers/tty/serial/serial_core.c
51125+++ b/drivers/tty/serial/serial_core.c
51126@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51127 uart_flush_buffer(tty);
51128 uart_shutdown(tty, state);
51129 spin_lock_irqsave(&port->lock, flags);
51130- port->count = 0;
51131+ atomic_set(&port->count, 0);
51132 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51133 spin_unlock_irqrestore(&port->lock, flags);
51134 tty_port_tty_set(port, NULL);
51135@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51136 goto end;
51137 }
51138
51139- port->count++;
51140+ atomic_inc(&port->count);
51141 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51142 retval = -ENXIO;
51143 goto err_dec_count;
51144@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51145 /*
51146 * Make sure the device is in D0 state.
51147 */
51148- if (port->count == 1)
51149+ if (atomic_read(&port->count) == 1)
51150 uart_change_pm(state, UART_PM_STATE_ON);
51151
51152 /*
51153@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51154 end:
51155 return retval;
51156 err_dec_count:
51157- port->count--;
51158+ atomic_inc(&port->count);
51159 mutex_unlock(&port->mutex);
51160 goto end;
51161 }
51162diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51163index 5ae14b4..2c1288f 100644
51164--- a/drivers/tty/synclink.c
51165+++ b/drivers/tty/synclink.c
51166@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51167
51168 if (debug_level >= DEBUG_LEVEL_INFO)
51169 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51170- __FILE__,__LINE__, info->device_name, info->port.count);
51171+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51172
51173 if (tty_port_close_start(&info->port, tty, filp) == 0)
51174 goto cleanup;
51175@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51176 cleanup:
51177 if (debug_level >= DEBUG_LEVEL_INFO)
51178 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51179- tty->driver->name, info->port.count);
51180+ tty->driver->name, atomic_read(&info->port.count));
51181
51182 } /* end of mgsl_close() */
51183
51184@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51185
51186 mgsl_flush_buffer(tty);
51187 shutdown(info);
51188-
51189- info->port.count = 0;
51190+
51191+ atomic_set(&info->port.count, 0);
51192 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51193 info->port.tty = NULL;
51194
51195@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51196
51197 if (debug_level >= DEBUG_LEVEL_INFO)
51198 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51199- __FILE__,__LINE__, tty->driver->name, port->count );
51200+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51201
51202 spin_lock_irqsave(&info->irq_spinlock, flags);
51203 if (!tty_hung_up_p(filp)) {
51204 extra_count = true;
51205- port->count--;
51206+ atomic_dec(&port->count);
51207 }
51208 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51209 port->blocked_open++;
51210@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51211
51212 if (debug_level >= DEBUG_LEVEL_INFO)
51213 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51214- __FILE__,__LINE__, tty->driver->name, port->count );
51215+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51216
51217 tty_unlock(tty);
51218 schedule();
51219@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51220
51221 /* FIXME: Racy on hangup during close wait */
51222 if (extra_count)
51223- port->count++;
51224+ atomic_inc(&port->count);
51225 port->blocked_open--;
51226
51227 if (debug_level >= DEBUG_LEVEL_INFO)
51228 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51229- __FILE__,__LINE__, tty->driver->name, port->count );
51230+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51231
51232 if (!retval)
51233 port->flags |= ASYNC_NORMAL_ACTIVE;
51234@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51235
51236 if (debug_level >= DEBUG_LEVEL_INFO)
51237 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51238- __FILE__,__LINE__,tty->driver->name, info->port.count);
51239+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51240
51241 /* If port is closing, signal caller to try again */
51242 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51243@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51244 spin_unlock_irqrestore(&info->netlock, flags);
51245 goto cleanup;
51246 }
51247- info->port.count++;
51248+ atomic_inc(&info->port.count);
51249 spin_unlock_irqrestore(&info->netlock, flags);
51250
51251- if (info->port.count == 1) {
51252+ if (atomic_read(&info->port.count) == 1) {
51253 /* 1st open on this device, init hardware */
51254 retval = startup(info);
51255 if (retval < 0)
51256@@ -3446,8 +3446,8 @@ cleanup:
51257 if (retval) {
51258 if (tty->count == 1)
51259 info->port.tty = NULL; /* tty layer will release tty struct */
51260- if(info->port.count)
51261- info->port.count--;
51262+ if (atomic_read(&info->port.count))
51263+ atomic_dec(&info->port.count);
51264 }
51265
51266 return retval;
51267@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51268 unsigned short new_crctype;
51269
51270 /* return error if TTY interface open */
51271- if (info->port.count)
51272+ if (atomic_read(&info->port.count))
51273 return -EBUSY;
51274
51275 switch (encoding)
51276@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51277
51278 /* arbitrate between network and tty opens */
51279 spin_lock_irqsave(&info->netlock, flags);
51280- if (info->port.count != 0 || info->netcount != 0) {
51281+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51282 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51283 spin_unlock_irqrestore(&info->netlock, flags);
51284 return -EBUSY;
51285@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51286 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51287
51288 /* return error if TTY interface open */
51289- if (info->port.count)
51290+ if (atomic_read(&info->port.count))
51291 return -EBUSY;
51292
51293 if (cmd != SIOCWANDEV)
51294diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51295index c359a91..959fc26 100644
51296--- a/drivers/tty/synclink_gt.c
51297+++ b/drivers/tty/synclink_gt.c
51298@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51299 tty->driver_data = info;
51300 info->port.tty = tty;
51301
51302- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51303+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51304
51305 /* If port is closing, signal caller to try again */
51306 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51307@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51308 mutex_unlock(&info->port.mutex);
51309 goto cleanup;
51310 }
51311- info->port.count++;
51312+ atomic_inc(&info->port.count);
51313 spin_unlock_irqrestore(&info->netlock, flags);
51314
51315- if (info->port.count == 1) {
51316+ if (atomic_read(&info->port.count) == 1) {
51317 /* 1st open on this device, init hardware */
51318 retval = startup(info);
51319 if (retval < 0) {
51320@@ -715,8 +715,8 @@ cleanup:
51321 if (retval) {
51322 if (tty->count == 1)
51323 info->port.tty = NULL; /* tty layer will release tty struct */
51324- if(info->port.count)
51325- info->port.count--;
51326+ if(atomic_read(&info->port.count))
51327+ atomic_dec(&info->port.count);
51328 }
51329
51330 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51331@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51332
51333 if (sanity_check(info, tty->name, "close"))
51334 return;
51335- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51336+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51337
51338 if (tty_port_close_start(&info->port, tty, filp) == 0)
51339 goto cleanup;
51340@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51341 tty_port_close_end(&info->port, tty);
51342 info->port.tty = NULL;
51343 cleanup:
51344- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51345+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51346 }
51347
51348 static void hangup(struct tty_struct *tty)
51349@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51350 shutdown(info);
51351
51352 spin_lock_irqsave(&info->port.lock, flags);
51353- info->port.count = 0;
51354+ atomic_set(&info->port.count, 0);
51355 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51356 info->port.tty = NULL;
51357 spin_unlock_irqrestore(&info->port.lock, flags);
51358@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51359 unsigned short new_crctype;
51360
51361 /* return error if TTY interface open */
51362- if (info->port.count)
51363+ if (atomic_read(&info->port.count))
51364 return -EBUSY;
51365
51366 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51367@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51368
51369 /* arbitrate between network and tty opens */
51370 spin_lock_irqsave(&info->netlock, flags);
51371- if (info->port.count != 0 || info->netcount != 0) {
51372+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51373 DBGINFO(("%s hdlc_open busy\n", dev->name));
51374 spin_unlock_irqrestore(&info->netlock, flags);
51375 return -EBUSY;
51376@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51377 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51378
51379 /* return error if TTY interface open */
51380- if (info->port.count)
51381+ if (atomic_read(&info->port.count))
51382 return -EBUSY;
51383
51384 if (cmd != SIOCWANDEV)
51385@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51386 if (port == NULL)
51387 continue;
51388 spin_lock(&port->lock);
51389- if ((port->port.count || port->netcount) &&
51390+ if ((atomic_read(&port->port.count) || port->netcount) &&
51391 port->pending_bh && !port->bh_running &&
51392 !port->bh_requested) {
51393 DBGISR(("%s bh queued\n", port->device_name));
51394@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51395 spin_lock_irqsave(&info->lock, flags);
51396 if (!tty_hung_up_p(filp)) {
51397 extra_count = true;
51398- port->count--;
51399+ atomic_dec(&port->count);
51400 }
51401 spin_unlock_irqrestore(&info->lock, flags);
51402 port->blocked_open++;
51403@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51404 remove_wait_queue(&port->open_wait, &wait);
51405
51406 if (extra_count)
51407- port->count++;
51408+ atomic_inc(&port->count);
51409 port->blocked_open--;
51410
51411 if (!retval)
51412diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51413index 144202e..4ccb07d 100644
51414--- a/drivers/tty/synclinkmp.c
51415+++ b/drivers/tty/synclinkmp.c
51416@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51417
51418 if (debug_level >= DEBUG_LEVEL_INFO)
51419 printk("%s(%d):%s open(), old ref count = %d\n",
51420- __FILE__,__LINE__,tty->driver->name, info->port.count);
51421+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51422
51423 /* If port is closing, signal caller to try again */
51424 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51425@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51426 spin_unlock_irqrestore(&info->netlock, flags);
51427 goto cleanup;
51428 }
51429- info->port.count++;
51430+ atomic_inc(&info->port.count);
51431 spin_unlock_irqrestore(&info->netlock, flags);
51432
51433- if (info->port.count == 1) {
51434+ if (atomic_read(&info->port.count) == 1) {
51435 /* 1st open on this device, init hardware */
51436 retval = startup(info);
51437 if (retval < 0)
51438@@ -796,8 +796,8 @@ cleanup:
51439 if (retval) {
51440 if (tty->count == 1)
51441 info->port.tty = NULL; /* tty layer will release tty struct */
51442- if(info->port.count)
51443- info->port.count--;
51444+ if(atomic_read(&info->port.count))
51445+ atomic_dec(&info->port.count);
51446 }
51447
51448 return retval;
51449@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51450
51451 if (debug_level >= DEBUG_LEVEL_INFO)
51452 printk("%s(%d):%s close() entry, count=%d\n",
51453- __FILE__,__LINE__, info->device_name, info->port.count);
51454+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51455
51456 if (tty_port_close_start(&info->port, tty, filp) == 0)
51457 goto cleanup;
51458@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51459 cleanup:
51460 if (debug_level >= DEBUG_LEVEL_INFO)
51461 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51462- tty->driver->name, info->port.count);
51463+ tty->driver->name, atomic_read(&info->port.count));
51464 }
51465
51466 /* Called by tty_hangup() when a hangup is signaled.
51467@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51468 shutdown(info);
51469
51470 spin_lock_irqsave(&info->port.lock, flags);
51471- info->port.count = 0;
51472+ atomic_set(&info->port.count, 0);
51473 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51474 info->port.tty = NULL;
51475 spin_unlock_irqrestore(&info->port.lock, flags);
51476@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51477 unsigned short new_crctype;
51478
51479 /* return error if TTY interface open */
51480- if (info->port.count)
51481+ if (atomic_read(&info->port.count))
51482 return -EBUSY;
51483
51484 switch (encoding)
51485@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51486
51487 /* arbitrate between network and tty opens */
51488 spin_lock_irqsave(&info->netlock, flags);
51489- if (info->port.count != 0 || info->netcount != 0) {
51490+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51491 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51492 spin_unlock_irqrestore(&info->netlock, flags);
51493 return -EBUSY;
51494@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51495 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51496
51497 /* return error if TTY interface open */
51498- if (info->port.count)
51499+ if (atomic_read(&info->port.count))
51500 return -EBUSY;
51501
51502 if (cmd != SIOCWANDEV)
51503@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51504 * do not request bottom half processing if the
51505 * device is not open in a normal mode.
51506 */
51507- if ( port && (port->port.count || port->netcount) &&
51508+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51509 port->pending_bh && !port->bh_running &&
51510 !port->bh_requested ) {
51511 if ( debug_level >= DEBUG_LEVEL_ISR )
51512@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51513
51514 if (debug_level >= DEBUG_LEVEL_INFO)
51515 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51516- __FILE__,__LINE__, tty->driver->name, port->count );
51517+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51518
51519 spin_lock_irqsave(&info->lock, flags);
51520 if (!tty_hung_up_p(filp)) {
51521 extra_count = true;
51522- port->count--;
51523+ atomic_dec(&port->count);
51524 }
51525 spin_unlock_irqrestore(&info->lock, flags);
51526 port->blocked_open++;
51527@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51528
51529 if (debug_level >= DEBUG_LEVEL_INFO)
51530 printk("%s(%d):%s block_til_ready() count=%d\n",
51531- __FILE__,__LINE__, tty->driver->name, port->count );
51532+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51533
51534 tty_unlock(tty);
51535 schedule();
51536@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51537 remove_wait_queue(&port->open_wait, &wait);
51538
51539 if (extra_count)
51540- port->count++;
51541+ atomic_inc(&port->count);
51542 port->blocked_open--;
51543
51544 if (debug_level >= DEBUG_LEVEL_INFO)
51545 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51546- __FILE__,__LINE__, tty->driver->name, port->count );
51547+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51548
51549 if (!retval)
51550 port->flags |= ASYNC_NORMAL_ACTIVE;
51551diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51552index ce396ec..04a37be 100644
51553--- a/drivers/tty/sysrq.c
51554+++ b/drivers/tty/sysrq.c
51555@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51556 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51557 size_t count, loff_t *ppos)
51558 {
51559- if (count) {
51560+ if (count && capable(CAP_SYS_ADMIN)) {
51561 char c;
51562
51563 if (get_user(c, buf))
51564diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51565index d3448a9..28e8db0 100644
51566--- a/drivers/tty/tty_io.c
51567+++ b/drivers/tty/tty_io.c
51568@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51569
51570 void tty_default_fops(struct file_operations *fops)
51571 {
51572- *fops = tty_fops;
51573+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51574 }
51575
51576 /*
51577diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51578index 2d822aa..a566234 100644
51579--- a/drivers/tty/tty_ldisc.c
51580+++ b/drivers/tty/tty_ldisc.c
51581@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51582 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51583 tty_ldiscs[disc] = new_ldisc;
51584 new_ldisc->num = disc;
51585- new_ldisc->refcount = 0;
51586+ atomic_set(&new_ldisc->refcount, 0);
51587 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51588
51589 return ret;
51590@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51591 return -EINVAL;
51592
51593 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51594- if (tty_ldiscs[disc]->refcount)
51595+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51596 ret = -EBUSY;
51597 else
51598 tty_ldiscs[disc] = NULL;
51599@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51600 if (ldops) {
51601 ret = ERR_PTR(-EAGAIN);
51602 if (try_module_get(ldops->owner)) {
51603- ldops->refcount++;
51604+ atomic_inc(&ldops->refcount);
51605 ret = ldops;
51606 }
51607 }
51608@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51609 unsigned long flags;
51610
51611 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51612- ldops->refcount--;
51613+ atomic_dec(&ldops->refcount);
51614 module_put(ldops->owner);
51615 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51616 }
51617diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51618index 3f746c8..2f2fcaa 100644
51619--- a/drivers/tty/tty_port.c
51620+++ b/drivers/tty/tty_port.c
51621@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51622 unsigned long flags;
51623
51624 spin_lock_irqsave(&port->lock, flags);
51625- port->count = 0;
51626+ atomic_set(&port->count, 0);
51627 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51628 tty = port->tty;
51629 if (tty)
51630@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51631 /* The port lock protects the port counts */
51632 spin_lock_irqsave(&port->lock, flags);
51633 if (!tty_hung_up_p(filp))
51634- port->count--;
51635+ atomic_dec(&port->count);
51636 port->blocked_open++;
51637 spin_unlock_irqrestore(&port->lock, flags);
51638
51639@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51640 we must not mess that up further */
51641 spin_lock_irqsave(&port->lock, flags);
51642 if (!tty_hung_up_p(filp))
51643- port->count++;
51644+ atomic_inc(&port->count);
51645 port->blocked_open--;
51646 if (retval == 0)
51647 port->flags |= ASYNC_NORMAL_ACTIVE;
51648@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51649 return 0;
51650 }
51651
51652- if (tty->count == 1 && port->count != 1) {
51653+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51654 printk(KERN_WARNING
51655 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51656- port->count);
51657- port->count = 1;
51658+ atomic_read(&port->count));
51659+ atomic_set(&port->count, 1);
51660 }
51661- if (--port->count < 0) {
51662+ if (atomic_dec_return(&port->count) < 0) {
51663 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51664- port->count);
51665- port->count = 0;
51666+ atomic_read(&port->count));
51667+ atomic_set(&port->count, 0);
51668 }
51669
51670- if (port->count) {
51671+ if (atomic_read(&port->count)) {
51672 spin_unlock_irqrestore(&port->lock, flags);
51673 return 0;
51674 }
51675@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51676 {
51677 spin_lock_irq(&port->lock);
51678 if (!tty_hung_up_p(filp))
51679- ++port->count;
51680+ atomic_inc(&port->count);
51681 spin_unlock_irq(&port->lock);
51682 tty_port_tty_set(port, tty);
51683
51684diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51685index d0e3a44..5f8b754 100644
51686--- a/drivers/tty/vt/keyboard.c
51687+++ b/drivers/tty/vt/keyboard.c
51688@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51689 kbd->kbdmode == VC_OFF) &&
51690 value != KVAL(K_SAK))
51691 return; /* SAK is allowed even in raw mode */
51692+
51693+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51694+ {
51695+ void *func = fn_handler[value];
51696+ if (func == fn_show_state || func == fn_show_ptregs ||
51697+ func == fn_show_mem)
51698+ return;
51699+ }
51700+#endif
51701+
51702 fn_handler[value](vc);
51703 }
51704
51705@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51706 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51707 return -EFAULT;
51708
51709- if (!capable(CAP_SYS_TTY_CONFIG))
51710- perm = 0;
51711-
51712 switch (cmd) {
51713 case KDGKBENT:
51714 /* Ensure another thread doesn't free it under us */
51715@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51716 spin_unlock_irqrestore(&kbd_event_lock, flags);
51717 return put_user(val, &user_kbe->kb_value);
51718 case KDSKBENT:
51719+ if (!capable(CAP_SYS_TTY_CONFIG))
51720+ perm = 0;
51721+
51722 if (!perm)
51723 return -EPERM;
51724 if (!i && v == K_NOSUCHMAP) {
51725@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51726 int i, j, k;
51727 int ret;
51728
51729- if (!capable(CAP_SYS_TTY_CONFIG))
51730- perm = 0;
51731-
51732 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51733 if (!kbs) {
51734 ret = -ENOMEM;
51735@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51736 kfree(kbs);
51737 return ((p && *p) ? -EOVERFLOW : 0);
51738 case KDSKBSENT:
51739+ if (!capable(CAP_SYS_TTY_CONFIG))
51740+ perm = 0;
51741+
51742 if (!perm) {
51743 ret = -EPERM;
51744 goto reterr;
51745diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51746index a673e5b..36e5d32 100644
51747--- a/drivers/uio/uio.c
51748+++ b/drivers/uio/uio.c
51749@@ -25,6 +25,7 @@
51750 #include <linux/kobject.h>
51751 #include <linux/cdev.h>
51752 #include <linux/uio_driver.h>
51753+#include <asm/local.h>
51754
51755 #define UIO_MAX_DEVICES (1U << MINORBITS)
51756
51757@@ -32,7 +33,7 @@ struct uio_device {
51758 struct module *owner;
51759 struct device *dev;
51760 int minor;
51761- atomic_t event;
51762+ atomic_unchecked_t event;
51763 struct fasync_struct *async_queue;
51764 wait_queue_head_t wait;
51765 struct uio_info *info;
51766@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51767 struct device_attribute *attr, char *buf)
51768 {
51769 struct uio_device *idev = dev_get_drvdata(dev);
51770- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51771+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51772 }
51773 static DEVICE_ATTR_RO(event);
51774
51775@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51776 {
51777 struct uio_device *idev = info->uio_dev;
51778
51779- atomic_inc(&idev->event);
51780+ atomic_inc_unchecked(&idev->event);
51781 wake_up_interruptible(&idev->wait);
51782 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51783 }
51784@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51785 }
51786
51787 listener->dev = idev;
51788- listener->event_count = atomic_read(&idev->event);
51789+ listener->event_count = atomic_read_unchecked(&idev->event);
51790 filep->private_data = listener;
51791
51792 if (idev->info->open) {
51793@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51794 return -EIO;
51795
51796 poll_wait(filep, &idev->wait, wait);
51797- if (listener->event_count != atomic_read(&idev->event))
51798+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51799 return POLLIN | POLLRDNORM;
51800 return 0;
51801 }
51802@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51803 do {
51804 set_current_state(TASK_INTERRUPTIBLE);
51805
51806- event_count = atomic_read(&idev->event);
51807+ event_count = atomic_read_unchecked(&idev->event);
51808 if (event_count != listener->event_count) {
51809 if (copy_to_user(buf, &event_count, count))
51810 retval = -EFAULT;
51811@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51812 static int uio_find_mem_index(struct vm_area_struct *vma)
51813 {
51814 struct uio_device *idev = vma->vm_private_data;
51815+ unsigned long size;
51816
51817 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51818- if (idev->info->mem[vma->vm_pgoff].size == 0)
51819+ size = idev->info->mem[vma->vm_pgoff].size;
51820+ if (size == 0)
51821+ return -1;
51822+ if (vma->vm_end - vma->vm_start > size)
51823 return -1;
51824 return (int)vma->vm_pgoff;
51825 }
51826@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51827 idev->owner = owner;
51828 idev->info = info;
51829 init_waitqueue_head(&idev->wait);
51830- atomic_set(&idev->event, 0);
51831+ atomic_set_unchecked(&idev->event, 0);
51832
51833 ret = uio_get_minor(idev);
51834 if (ret)
51835diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51836index 813d4d3..a71934f 100644
51837--- a/drivers/usb/atm/cxacru.c
51838+++ b/drivers/usb/atm/cxacru.c
51839@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51840 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51841 if (ret < 2)
51842 return -EINVAL;
51843- if (index < 0 || index > 0x7f)
51844+ if (index > 0x7f)
51845 return -EINVAL;
51846 pos += tmp;
51847
51848diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51849index dada014..1d0d517 100644
51850--- a/drivers/usb/atm/usbatm.c
51851+++ b/drivers/usb/atm/usbatm.c
51852@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51853 if (printk_ratelimit())
51854 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51855 __func__, vpi, vci);
51856- atomic_inc(&vcc->stats->rx_err);
51857+ atomic_inc_unchecked(&vcc->stats->rx_err);
51858 return;
51859 }
51860
51861@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51862 if (length > ATM_MAX_AAL5_PDU) {
51863 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51864 __func__, length, vcc);
51865- atomic_inc(&vcc->stats->rx_err);
51866+ atomic_inc_unchecked(&vcc->stats->rx_err);
51867 goto out;
51868 }
51869
51870@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51871 if (sarb->len < pdu_length) {
51872 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51873 __func__, pdu_length, sarb->len, vcc);
51874- atomic_inc(&vcc->stats->rx_err);
51875+ atomic_inc_unchecked(&vcc->stats->rx_err);
51876 goto out;
51877 }
51878
51879 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51880 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51881 __func__, vcc);
51882- atomic_inc(&vcc->stats->rx_err);
51883+ atomic_inc_unchecked(&vcc->stats->rx_err);
51884 goto out;
51885 }
51886
51887@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51888 if (printk_ratelimit())
51889 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51890 __func__, length);
51891- atomic_inc(&vcc->stats->rx_drop);
51892+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51893 goto out;
51894 }
51895
51896@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51897
51898 vcc->push(vcc, skb);
51899
51900- atomic_inc(&vcc->stats->rx);
51901+ atomic_inc_unchecked(&vcc->stats->rx);
51902 out:
51903 skb_trim(sarb, 0);
51904 }
51905@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51906 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51907
51908 usbatm_pop(vcc, skb);
51909- atomic_inc(&vcc->stats->tx);
51910+ atomic_inc_unchecked(&vcc->stats->tx);
51911
51912 skb = skb_dequeue(&instance->sndqueue);
51913 }
51914@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51915 if (!left--)
51916 return sprintf(page,
51917 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51918- atomic_read(&atm_dev->stats.aal5.tx),
51919- atomic_read(&atm_dev->stats.aal5.tx_err),
51920- atomic_read(&atm_dev->stats.aal5.rx),
51921- atomic_read(&atm_dev->stats.aal5.rx_err),
51922- atomic_read(&atm_dev->stats.aal5.rx_drop));
51923+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51924+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51925+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51926+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51927+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51928
51929 if (!left--) {
51930 if (instance->disconnected)
51931diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51932index 2a3bbdf..91d72cf 100644
51933--- a/drivers/usb/core/devices.c
51934+++ b/drivers/usb/core/devices.c
51935@@ -126,7 +126,7 @@ static const char format_endpt[] =
51936 * time it gets called.
51937 */
51938 static struct device_connect_event {
51939- atomic_t count;
51940+ atomic_unchecked_t count;
51941 wait_queue_head_t wait;
51942 } device_event = {
51943 .count = ATOMIC_INIT(1),
51944@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51945
51946 void usbfs_conn_disc_event(void)
51947 {
51948- atomic_add(2, &device_event.count);
51949+ atomic_add_unchecked(2, &device_event.count);
51950 wake_up(&device_event.wait);
51951 }
51952
51953@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51954
51955 poll_wait(file, &device_event.wait, wait);
51956
51957- event_count = atomic_read(&device_event.count);
51958+ event_count = atomic_read_unchecked(&device_event.count);
51959 if (file->f_version != event_count) {
51960 file->f_version = event_count;
51961 return POLLIN | POLLRDNORM;
51962diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51963index 90e18f6..5eeda46 100644
51964--- a/drivers/usb/core/devio.c
51965+++ b/drivers/usb/core/devio.c
51966@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51967 struct dev_state *ps = file->private_data;
51968 struct usb_device *dev = ps->dev;
51969 ssize_t ret = 0;
51970- unsigned len;
51971+ size_t len;
51972 loff_t pos;
51973 int i;
51974
51975@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51976 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51977 struct usb_config_descriptor *config =
51978 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51979- unsigned int length = le16_to_cpu(config->wTotalLength);
51980+ size_t length = le16_to_cpu(config->wTotalLength);
51981
51982 if (*ppos < pos + length) {
51983
51984 /* The descriptor may claim to be longer than it
51985 * really is. Here is the actual allocated length. */
51986- unsigned alloclen =
51987+ size_t alloclen =
51988 le16_to_cpu(dev->config[i].desc.wTotalLength);
51989
51990- len = length - (*ppos - pos);
51991+ len = length + pos - *ppos;
51992 if (len > nbytes)
51993 len = nbytes;
51994
51995 /* Simply don't write (skip over) unallocated parts */
51996 if (alloclen > (*ppos - pos)) {
51997- alloclen -= (*ppos - pos);
51998+ alloclen = alloclen + pos - *ppos;
51999 if (copy_to_user(buf,
52000 dev->rawdescriptors[i] + (*ppos - pos),
52001 min(len, alloclen))) {
52002diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52003index 2518c32..1c201bb 100644
52004--- a/drivers/usb/core/hcd.c
52005+++ b/drivers/usb/core/hcd.c
52006@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52007 */
52008 usb_get_urb(urb);
52009 atomic_inc(&urb->use_count);
52010- atomic_inc(&urb->dev->urbnum);
52011+ atomic_inc_unchecked(&urb->dev->urbnum);
52012 usbmon_urb_submit(&hcd->self, urb);
52013
52014 /* NOTE requirements on root-hub callers (usbfs and the hub
52015@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52016 urb->hcpriv = NULL;
52017 INIT_LIST_HEAD(&urb->urb_list);
52018 atomic_dec(&urb->use_count);
52019- atomic_dec(&urb->dev->urbnum);
52020+ atomic_dec_unchecked(&urb->dev->urbnum);
52021 if (atomic_read(&urb->reject))
52022 wake_up(&usb_kill_urb_queue);
52023 usb_put_urb(urb);
52024diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52025index d498d03..e26f959 100644
52026--- a/drivers/usb/core/hub.c
52027+++ b/drivers/usb/core/hub.c
52028@@ -27,6 +27,7 @@
52029 #include <linux/freezer.h>
52030 #include <linux/random.h>
52031 #include <linux/pm_qos.h>
52032+#include <linux/grsecurity.h>
52033
52034 #include <asm/uaccess.h>
52035 #include <asm/byteorder.h>
52036@@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52037 goto done;
52038 return;
52039 }
52040+
52041+ if (gr_handle_new_usb())
52042+ goto done;
52043+
52044 if (hub_is_superspeed(hub->hdev))
52045 unit_load = 150;
52046 else
52047diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52048index f829a1a..e6c334a 100644
52049--- a/drivers/usb/core/message.c
52050+++ b/drivers/usb/core/message.c
52051@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52052 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52053 * error number.
52054 */
52055-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52056+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52057 __u8 requesttype, __u16 value, __u16 index, void *data,
52058 __u16 size, int timeout)
52059 {
52060@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52061 * If successful, 0. Otherwise a negative error number. The number of actual
52062 * bytes transferred will be stored in the @actual_length paramater.
52063 */
52064-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52065+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52066 void *data, int len, int *actual_length, int timeout)
52067 {
52068 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52069@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52070 * bytes transferred will be stored in the @actual_length parameter.
52071 *
52072 */
52073-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52074+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52075 void *data, int len, int *actual_length, int timeout)
52076 {
52077 struct urb *urb;
52078diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52079index 1236c60..d47a51c 100644
52080--- a/drivers/usb/core/sysfs.c
52081+++ b/drivers/usb/core/sysfs.c
52082@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52083 struct usb_device *udev;
52084
52085 udev = to_usb_device(dev);
52086- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52087+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52088 }
52089 static DEVICE_ATTR_RO(urbnum);
52090
52091diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52092index 4d11449..f4ccabf 100644
52093--- a/drivers/usb/core/usb.c
52094+++ b/drivers/usb/core/usb.c
52095@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52096 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52097 dev->state = USB_STATE_ATTACHED;
52098 dev->lpm_disable_count = 1;
52099- atomic_set(&dev->urbnum, 0);
52100+ atomic_set_unchecked(&dev->urbnum, 0);
52101
52102 INIT_LIST_HEAD(&dev->ep0.urb_list);
52103 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52104diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52105index 2da0a5a..4870e09 100644
52106--- a/drivers/usb/dwc3/gadget.c
52107+++ b/drivers/usb/dwc3/gadget.c
52108@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52109 if (!usb_endpoint_xfer_isoc(desc))
52110 return 0;
52111
52112- memset(&trb_link, 0, sizeof(trb_link));
52113-
52114 /* Link TRB for ISOC. The HWO bit is never reset */
52115 trb_st_hw = &dep->trb_pool[0];
52116
52117diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52118index 8cfc319..4868255 100644
52119--- a/drivers/usb/early/ehci-dbgp.c
52120+++ b/drivers/usb/early/ehci-dbgp.c
52121@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52122
52123 #ifdef CONFIG_KGDB
52124 static struct kgdb_io kgdbdbgp_io_ops;
52125-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52126+static struct kgdb_io kgdbdbgp_io_ops_console;
52127+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52128 #else
52129 #define dbgp_kgdb_mode (0)
52130 #endif
52131@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52132 .write_char = kgdbdbgp_write_char,
52133 };
52134
52135+static struct kgdb_io kgdbdbgp_io_ops_console = {
52136+ .name = "kgdbdbgp",
52137+ .read_char = kgdbdbgp_read_char,
52138+ .write_char = kgdbdbgp_write_char,
52139+ .is_console = 1
52140+};
52141+
52142 static int kgdbdbgp_wait_time;
52143
52144 static int __init kgdbdbgp_parse_config(char *str)
52145@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52146 ptr++;
52147 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52148 }
52149- kgdb_register_io_module(&kgdbdbgp_io_ops);
52150- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52151+ if (early_dbgp_console.index != -1)
52152+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52153+ else
52154+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52155
52156 return 0;
52157 }
52158diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52159index 2b4c82d..06a8ee6 100644
52160--- a/drivers/usb/gadget/f_uac1.c
52161+++ b/drivers/usb/gadget/f_uac1.c
52162@@ -13,6 +13,7 @@
52163 #include <linux/kernel.h>
52164 #include <linux/device.h>
52165 #include <linux/atomic.h>
52166+#include <linux/module.h>
52167
52168 #include "u_uac1.h"
52169
52170diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52171index ad0aca8..8ff84865 100644
52172--- a/drivers/usb/gadget/u_serial.c
52173+++ b/drivers/usb/gadget/u_serial.c
52174@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52175 spin_lock_irq(&port->port_lock);
52176
52177 /* already open? Great. */
52178- if (port->port.count) {
52179+ if (atomic_read(&port->port.count)) {
52180 status = 0;
52181- port->port.count++;
52182+ atomic_inc(&port->port.count);
52183
52184 /* currently opening/closing? wait ... */
52185 } else if (port->openclose) {
52186@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52187 tty->driver_data = port;
52188 port->port.tty = tty;
52189
52190- port->port.count = 1;
52191+ atomic_set(&port->port.count, 1);
52192 port->openclose = false;
52193
52194 /* if connected, start the I/O stream */
52195@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52196
52197 spin_lock_irq(&port->port_lock);
52198
52199- if (port->port.count != 1) {
52200- if (port->port.count == 0)
52201+ if (atomic_read(&port->port.count) != 1) {
52202+ if (atomic_read(&port->port.count) == 0)
52203 WARN_ON(1);
52204 else
52205- --port->port.count;
52206+ atomic_dec(&port->port.count);
52207 goto exit;
52208 }
52209
52210@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52211 * and sleep if necessary
52212 */
52213 port->openclose = true;
52214- port->port.count = 0;
52215+ atomic_set(&port->port.count, 0);
52216
52217 gser = port->port_usb;
52218 if (gser && gser->disconnect)
52219@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52220 int cond;
52221
52222 spin_lock_irq(&port->port_lock);
52223- cond = (port->port.count == 0) && !port->openclose;
52224+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52225 spin_unlock_irq(&port->port_lock);
52226 return cond;
52227 }
52228@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52229 /* if it's already open, start I/O ... and notify the serial
52230 * protocol about open/close status (connect/disconnect).
52231 */
52232- if (port->port.count) {
52233+ if (atomic_read(&port->port.count)) {
52234 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52235 gs_start_io(port);
52236 if (gser->connect)
52237@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52238
52239 port->port_usb = NULL;
52240 gser->ioport = NULL;
52241- if (port->port.count > 0 || port->openclose) {
52242+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52243 wake_up_interruptible(&port->drain_wait);
52244 if (port->port.tty)
52245 tty_hangup(port->port.tty);
52246@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52247
52248 /* finally, free any unused/unusable I/O buffers */
52249 spin_lock_irqsave(&port->port_lock, flags);
52250- if (port->port.count == 0 && !port->openclose)
52251+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52252 gs_buf_free(&port->port_write_buf);
52253 gs_free_requests(gser->out, &port->read_pool, NULL);
52254 gs_free_requests(gser->out, &port->read_queue, NULL);
52255diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52256index 7a55fea..cc0ed4f 100644
52257--- a/drivers/usb/gadget/u_uac1.c
52258+++ b/drivers/usb/gadget/u_uac1.c
52259@@ -16,6 +16,7 @@
52260 #include <linux/ctype.h>
52261 #include <linux/random.h>
52262 #include <linux/syscalls.h>
52263+#include <linux/module.h>
52264
52265 #include "u_uac1.h"
52266
52267diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52268index 7ae0c4d..35521b7 100644
52269--- a/drivers/usb/host/ehci-hub.c
52270+++ b/drivers/usb/host/ehci-hub.c
52271@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52272 urb->transfer_flags = URB_DIR_IN;
52273 usb_get_urb(urb);
52274 atomic_inc(&urb->use_count);
52275- atomic_inc(&urb->dev->urbnum);
52276+ atomic_inc_unchecked(&urb->dev->urbnum);
52277 urb->setup_dma = dma_map_single(
52278 hcd->self.controller,
52279 urb->setup_packet,
52280@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52281 urb->status = -EINPROGRESS;
52282 usb_get_urb(urb);
52283 atomic_inc(&urb->use_count);
52284- atomic_inc(&urb->dev->urbnum);
52285+ atomic_inc_unchecked(&urb->dev->urbnum);
52286 retval = submit_single_step_set_feature(hcd, urb, 0);
52287 if (!retval && !wait_for_completion_timeout(&done,
52288 msecs_to_jiffies(2000))) {
52289diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52290index ba6a5d6..f88f7f3 100644
52291--- a/drivers/usb/misc/appledisplay.c
52292+++ b/drivers/usb/misc/appledisplay.c
52293@@ -83,7 +83,7 @@ struct appledisplay {
52294 spinlock_t lock;
52295 };
52296
52297-static atomic_t count_displays = ATOMIC_INIT(0);
52298+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52299 static struct workqueue_struct *wq;
52300
52301 static void appledisplay_complete(struct urb *urb)
52302@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52303
52304 /* Register backlight device */
52305 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52306- atomic_inc_return(&count_displays) - 1);
52307+ atomic_inc_return_unchecked(&count_displays) - 1);
52308 memset(&props, 0, sizeof(struct backlight_properties));
52309 props.type = BACKLIGHT_RAW;
52310 props.max_brightness = 0xff;
52311diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52312index 8d7fc48..01c4986 100644
52313--- a/drivers/usb/serial/console.c
52314+++ b/drivers/usb/serial/console.c
52315@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52316
52317 info->port = port;
52318
52319- ++port->port.count;
52320+ atomic_inc(&port->port.count);
52321 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52322 if (serial->type->set_termios) {
52323 /*
52324@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52325 }
52326 /* Now that any required fake tty operations are completed restore
52327 * the tty port count */
52328- --port->port.count;
52329+ atomic_dec(&port->port.count);
52330 /* The console is special in terms of closing the device so
52331 * indicate this port is now acting as a system console. */
52332 port->port.console = 1;
52333@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52334 free_tty:
52335 kfree(tty);
52336 reset_open_count:
52337- port->port.count = 0;
52338+ atomic_set(&port->port.count, 0);
52339 usb_autopm_put_interface(serial->interface);
52340 error_get_interface:
52341 usb_serial_put(serial);
52342@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52343 static void usb_console_write(struct console *co,
52344 const char *buf, unsigned count)
52345 {
52346- static struct usbcons_info *info = &usbcons_info;
52347+ struct usbcons_info *info = &usbcons_info;
52348 struct usb_serial_port *port = info->port;
52349 struct usb_serial *serial;
52350 int retval = -ENODEV;
52351diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52352index 75f70f0..d467e1a 100644
52353--- a/drivers/usb/storage/usb.h
52354+++ b/drivers/usb/storage/usb.h
52355@@ -63,7 +63,7 @@ struct us_unusual_dev {
52356 __u8 useProtocol;
52357 __u8 useTransport;
52358 int (*initFunction)(struct us_data *);
52359-};
52360+} __do_const;
52361
52362
52363 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52364diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52365index a2ef84b..aa7c2b8 100644
52366--- a/drivers/usb/wusbcore/wa-hc.h
52367+++ b/drivers/usb/wusbcore/wa-hc.h
52368@@ -225,7 +225,7 @@ struct wahc {
52369 spinlock_t xfer_list_lock;
52370 struct work_struct xfer_enqueue_work;
52371 struct work_struct xfer_error_work;
52372- atomic_t xfer_id_count;
52373+ atomic_unchecked_t xfer_id_count;
52374
52375 kernel_ulong_t quirks;
52376 };
52377@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52378 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52379 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52380 wa->dto_in_use = 0;
52381- atomic_set(&wa->xfer_id_count, 1);
52382+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52383 }
52384
52385 /**
52386diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52387index 3cd96e9..bd7c58d 100644
52388--- a/drivers/usb/wusbcore/wa-xfer.c
52389+++ b/drivers/usb/wusbcore/wa-xfer.c
52390@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52391 */
52392 static void wa_xfer_id_init(struct wa_xfer *xfer)
52393 {
52394- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52395+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52396 }
52397
52398 /* Return the xfer's ID. */
52399diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52400index 21271d8..45b55a0 100644
52401--- a/drivers/vfio/vfio.c
52402+++ b/drivers/vfio/vfio.c
52403@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52404 return 0;
52405
52406 /* TODO Prevent device auto probing */
52407- WARN("Device %s added to live group %d!\n", dev_name(dev),
52408+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52409 iommu_group_id(group->iommu_group));
52410
52411 return 0;
52412diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52413index 5174eba..451e6bc 100644
52414--- a/drivers/vhost/vringh.c
52415+++ b/drivers/vhost/vringh.c
52416@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52417 /* Userspace access helpers: in this case, addresses are really userspace. */
52418 static inline int getu16_user(u16 *val, const u16 *p)
52419 {
52420- return get_user(*val, (__force u16 __user *)p);
52421+ return get_user(*val, (u16 __force_user *)p);
52422 }
52423
52424 static inline int putu16_user(u16 *p, u16 val)
52425 {
52426- return put_user(val, (__force u16 __user *)p);
52427+ return put_user(val, (u16 __force_user *)p);
52428 }
52429
52430 static inline int copydesc_user(void *dst, const void *src, size_t len)
52431 {
52432- return copy_from_user(dst, (__force void __user *)src, len) ?
52433+ return copy_from_user(dst, (void __force_user *)src, len) ?
52434 -EFAULT : 0;
52435 }
52436
52437@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52438 const struct vring_used_elem *src,
52439 unsigned int num)
52440 {
52441- return copy_to_user((__force void __user *)dst, src,
52442+ return copy_to_user((void __force_user *)dst, src,
52443 sizeof(*dst) * num) ? -EFAULT : 0;
52444 }
52445
52446 static inline int xfer_from_user(void *src, void *dst, size_t len)
52447 {
52448- return copy_from_user(dst, (__force void __user *)src, len) ?
52449+ return copy_from_user(dst, (void __force_user *)src, len) ?
52450 -EFAULT : 0;
52451 }
52452
52453 static inline int xfer_to_user(void *dst, void *src, size_t len)
52454 {
52455- return copy_to_user((__force void __user *)dst, src, len) ?
52456+ return copy_to_user((void __force_user *)dst, src, len) ?
52457 -EFAULT : 0;
52458 }
52459
52460@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52461 vrh->last_used_idx = 0;
52462 vrh->vring.num = num;
52463 /* vring expects kernel addresses, but only used via accessors. */
52464- vrh->vring.desc = (__force struct vring_desc *)desc;
52465- vrh->vring.avail = (__force struct vring_avail *)avail;
52466- vrh->vring.used = (__force struct vring_used *)used;
52467+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52468+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52469+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52470 return 0;
52471 }
52472 EXPORT_SYMBOL(vringh_init_user);
52473@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52474
52475 static inline int putu16_kern(u16 *p, u16 val)
52476 {
52477- ACCESS_ONCE(*p) = val;
52478+ ACCESS_ONCE_RW(*p) = val;
52479 return 0;
52480 }
52481
52482diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52483index 1b0b233..6f34c2c 100644
52484--- a/drivers/video/arcfb.c
52485+++ b/drivers/video/arcfb.c
52486@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52487 return -ENOSPC;
52488
52489 err = 0;
52490- if ((count + p) > fbmemlength) {
52491+ if (count > (fbmemlength - p)) {
52492 count = fbmemlength - p;
52493 err = -ENOSPC;
52494 }
52495diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52496index 52108be..c7c110d 100644
52497--- a/drivers/video/aty/aty128fb.c
52498+++ b/drivers/video/aty/aty128fb.c
52499@@ -149,7 +149,7 @@ enum {
52500 };
52501
52502 /* Must match above enum */
52503-static char * const r128_family[] = {
52504+static const char * const r128_family[] = {
52505 "AGP",
52506 "PCI",
52507 "PRO AGP",
52508diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52509index 28fafbf..ae91651 100644
52510--- a/drivers/video/aty/atyfb_base.c
52511+++ b/drivers/video/aty/atyfb_base.c
52512@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52513 par->accel_flags = var->accel_flags; /* hack */
52514
52515 if (var->accel_flags) {
52516- info->fbops->fb_sync = atyfb_sync;
52517+ pax_open_kernel();
52518+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52519+ pax_close_kernel();
52520 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52521 } else {
52522- info->fbops->fb_sync = NULL;
52523+ pax_open_kernel();
52524+ *(void **)&info->fbops->fb_sync = NULL;
52525+ pax_close_kernel();
52526 info->flags |= FBINFO_HWACCEL_DISABLED;
52527 }
52528
52529diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52530index 95ec042..e6affdd 100644
52531--- a/drivers/video/aty/mach64_cursor.c
52532+++ b/drivers/video/aty/mach64_cursor.c
52533@@ -7,6 +7,7 @@
52534 #include <linux/string.h>
52535
52536 #include <asm/io.h>
52537+#include <asm/pgtable.h>
52538
52539 #ifdef __sparc__
52540 #include <asm/fbio.h>
52541@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52542 info->sprite.buf_align = 16; /* and 64 lines tall. */
52543 info->sprite.flags = FB_PIXMAP_IO;
52544
52545- info->fbops->fb_cursor = atyfb_cursor;
52546+ pax_open_kernel();
52547+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52548+ pax_close_kernel();
52549
52550 return 0;
52551 }
52552diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52553index 84a110a..96312c3 100644
52554--- a/drivers/video/backlight/kb3886_bl.c
52555+++ b/drivers/video/backlight/kb3886_bl.c
52556@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52557 static unsigned long kb3886bl_flags;
52558 #define KB3886BL_SUSPENDED 0x01
52559
52560-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52561+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52562 {
52563 .ident = "Sahara Touch-iT",
52564 .matches = {
52565diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52566index 900aa4e..6d49418 100644
52567--- a/drivers/video/fb_defio.c
52568+++ b/drivers/video/fb_defio.c
52569@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52570
52571 BUG_ON(!fbdefio);
52572 mutex_init(&fbdefio->lock);
52573- info->fbops->fb_mmap = fb_deferred_io_mmap;
52574+ pax_open_kernel();
52575+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52576+ pax_close_kernel();
52577 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52578 INIT_LIST_HEAD(&fbdefio->pagelist);
52579 if (fbdefio->delay == 0) /* set a default of 1 s */
52580@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52581 page->mapping = NULL;
52582 }
52583
52584- info->fbops->fb_mmap = NULL;
52585+ *(void **)&info->fbops->fb_mmap = NULL;
52586 mutex_destroy(&fbdefio->lock);
52587 }
52588 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52589diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52590index 7309ac7..be3c49c 100644
52591--- a/drivers/video/fbmem.c
52592+++ b/drivers/video/fbmem.c
52593@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52594 image->dx += image->width + 8;
52595 }
52596 } else if (rotate == FB_ROTATE_UD) {
52597- for (x = 0; x < num && image->dx >= 0; x++) {
52598+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52599 info->fbops->fb_imageblit(info, image);
52600 image->dx -= image->width + 8;
52601 }
52602@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52603 image->dy += image->height + 8;
52604 }
52605 } else if (rotate == FB_ROTATE_CCW) {
52606- for (x = 0; x < num && image->dy >= 0; x++) {
52607+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52608 info->fbops->fb_imageblit(info, image);
52609 image->dy -= image->height + 8;
52610 }
52611@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52612 return -EFAULT;
52613 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52614 return -EINVAL;
52615- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52616+ if (con2fb.framebuffer >= FB_MAX)
52617 return -EINVAL;
52618 if (!registered_fb[con2fb.framebuffer])
52619 request_module("fb%d", con2fb.framebuffer);
52620@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52621 __u32 data;
52622 int err;
52623
52624- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52625+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52626
52627 data = (__u32) (unsigned long) fix->smem_start;
52628 err |= put_user(data, &fix32->smem_start);
52629diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52630index 130708f..cdac1a9 100644
52631--- a/drivers/video/hyperv_fb.c
52632+++ b/drivers/video/hyperv_fb.c
52633@@ -233,7 +233,7 @@ static uint screen_fb_size;
52634 static inline int synthvid_send(struct hv_device *hdev,
52635 struct synthvid_msg *msg)
52636 {
52637- static atomic64_t request_id = ATOMIC64_INIT(0);
52638+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52639 int ret;
52640
52641 msg->pipe_hdr.type = PIPE_MSG_DATA;
52642@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52643
52644 ret = vmbus_sendpacket(hdev->channel, msg,
52645 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52646- atomic64_inc_return(&request_id),
52647+ atomic64_inc_return_unchecked(&request_id),
52648 VM_PKT_DATA_INBAND, 0);
52649
52650 if (ret)
52651diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52652index 7672d2e..b56437f 100644
52653--- a/drivers/video/i810/i810_accel.c
52654+++ b/drivers/video/i810/i810_accel.c
52655@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52656 }
52657 }
52658 printk("ringbuffer lockup!!!\n");
52659+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52660 i810_report_error(mmio);
52661 par->dev_flags |= LOCKUP;
52662 info->pixmap.scan_align = 1;
52663diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52664index 3c14e43..2630570 100644
52665--- a/drivers/video/logo/logo_linux_clut224.ppm
52666+++ b/drivers/video/logo/logo_linux_clut224.ppm
52667@@ -2,1603 +2,1123 @@ P3
52668 # Standard 224-color Linux logo
52669 80 80
52670 255
52671- 0 0 0 0 0 0 0 0 0 0 0 0
52672- 0 0 0 0 0 0 0 0 0 0 0 0
52673- 0 0 0 0 0 0 0 0 0 0 0 0
52674- 0 0 0 0 0 0 0 0 0 0 0 0
52675- 0 0 0 0 0 0 0 0 0 0 0 0
52676- 0 0 0 0 0 0 0 0 0 0 0 0
52677- 0 0 0 0 0 0 0 0 0 0 0 0
52678- 0 0 0 0 0 0 0 0 0 0 0 0
52679- 0 0 0 0 0 0 0 0 0 0 0 0
52680- 6 6 6 6 6 6 10 10 10 10 10 10
52681- 10 10 10 6 6 6 6 6 6 6 6 6
52682- 0 0 0 0 0 0 0 0 0 0 0 0
52683- 0 0 0 0 0 0 0 0 0 0 0 0
52684- 0 0 0 0 0 0 0 0 0 0 0 0
52685- 0 0 0 0 0 0 0 0 0 0 0 0
52686- 0 0 0 0 0 0 0 0 0 0 0 0
52687- 0 0 0 0 0 0 0 0 0 0 0 0
52688- 0 0 0 0 0 0 0 0 0 0 0 0
52689- 0 0 0 0 0 0 0 0 0 0 0 0
52690- 0 0 0 0 0 0 0 0 0 0 0 0
52691- 0 0 0 0 0 0 0 0 0 0 0 0
52692- 0 0 0 0 0 0 0 0 0 0 0 0
52693- 0 0 0 0 0 0 0 0 0 0 0 0
52694- 0 0 0 0 0 0 0 0 0 0 0 0
52695- 0 0 0 0 0 0 0 0 0 0 0 0
52696- 0 0 0 0 0 0 0 0 0 0 0 0
52697- 0 0 0 0 0 0 0 0 0 0 0 0
52698- 0 0 0 0 0 0 0 0 0 0 0 0
52699- 0 0 0 6 6 6 10 10 10 14 14 14
52700- 22 22 22 26 26 26 30 30 30 34 34 34
52701- 30 30 30 30 30 30 26 26 26 18 18 18
52702- 14 14 14 10 10 10 6 6 6 0 0 0
52703- 0 0 0 0 0 0 0 0 0 0 0 0
52704- 0 0 0 0 0 0 0 0 0 0 0 0
52705- 0 0 0 0 0 0 0 0 0 0 0 0
52706- 0 0 0 0 0 0 0 0 0 0 0 0
52707- 0 0 0 0 0 0 0 0 0 0 0 0
52708- 0 0 0 0 0 0 0 0 0 0 0 0
52709- 0 0 0 0 0 0 0 0 0 0 0 0
52710- 0 0 0 0 0 0 0 0 0 0 0 0
52711- 0 0 0 0 0 0 0 0 0 0 0 0
52712- 0 0 0 0 0 1 0 0 1 0 0 0
52713- 0 0 0 0 0 0 0 0 0 0 0 0
52714- 0 0 0 0 0 0 0 0 0 0 0 0
52715- 0 0 0 0 0 0 0 0 0 0 0 0
52716- 0 0 0 0 0 0 0 0 0 0 0 0
52717- 0 0 0 0 0 0 0 0 0 0 0 0
52718- 0 0 0 0 0 0 0 0 0 0 0 0
52719- 6 6 6 14 14 14 26 26 26 42 42 42
52720- 54 54 54 66 66 66 78 78 78 78 78 78
52721- 78 78 78 74 74 74 66 66 66 54 54 54
52722- 42 42 42 26 26 26 18 18 18 10 10 10
52723- 6 6 6 0 0 0 0 0 0 0 0 0
52724- 0 0 0 0 0 0 0 0 0 0 0 0
52725- 0 0 0 0 0 0 0 0 0 0 0 0
52726- 0 0 0 0 0 0 0 0 0 0 0 0
52727- 0 0 0 0 0 0 0 0 0 0 0 0
52728- 0 0 0 0 0 0 0 0 0 0 0 0
52729- 0 0 0 0 0 0 0 0 0 0 0 0
52730- 0 0 0 0 0 0 0 0 0 0 0 0
52731- 0 0 0 0 0 0 0 0 0 0 0 0
52732- 0 0 1 0 0 0 0 0 0 0 0 0
52733- 0 0 0 0 0 0 0 0 0 0 0 0
52734- 0 0 0 0 0 0 0 0 0 0 0 0
52735- 0 0 0 0 0 0 0 0 0 0 0 0
52736- 0 0 0 0 0 0 0 0 0 0 0 0
52737- 0 0 0 0 0 0 0 0 0 0 0 0
52738- 0 0 0 0 0 0 0 0 0 10 10 10
52739- 22 22 22 42 42 42 66 66 66 86 86 86
52740- 66 66 66 38 38 38 38 38 38 22 22 22
52741- 26 26 26 34 34 34 54 54 54 66 66 66
52742- 86 86 86 70 70 70 46 46 46 26 26 26
52743- 14 14 14 6 6 6 0 0 0 0 0 0
52744- 0 0 0 0 0 0 0 0 0 0 0 0
52745- 0 0 0 0 0 0 0 0 0 0 0 0
52746- 0 0 0 0 0 0 0 0 0 0 0 0
52747- 0 0 0 0 0 0 0 0 0 0 0 0
52748- 0 0 0 0 0 0 0 0 0 0 0 0
52749- 0 0 0 0 0 0 0 0 0 0 0 0
52750- 0 0 0 0 0 0 0 0 0 0 0 0
52751- 0 0 0 0 0 0 0 0 0 0 0 0
52752- 0 0 1 0 0 1 0 0 1 0 0 0
52753- 0 0 0 0 0 0 0 0 0 0 0 0
52754- 0 0 0 0 0 0 0 0 0 0 0 0
52755- 0 0 0 0 0 0 0 0 0 0 0 0
52756- 0 0 0 0 0 0 0 0 0 0 0 0
52757- 0 0 0 0 0 0 0 0 0 0 0 0
52758- 0 0 0 0 0 0 10 10 10 26 26 26
52759- 50 50 50 82 82 82 58 58 58 6 6 6
52760- 2 2 6 2 2 6 2 2 6 2 2 6
52761- 2 2 6 2 2 6 2 2 6 2 2 6
52762- 6 6 6 54 54 54 86 86 86 66 66 66
52763- 38 38 38 18 18 18 6 6 6 0 0 0
52764- 0 0 0 0 0 0 0 0 0 0 0 0
52765- 0 0 0 0 0 0 0 0 0 0 0 0
52766- 0 0 0 0 0 0 0 0 0 0 0 0
52767- 0 0 0 0 0 0 0 0 0 0 0 0
52768- 0 0 0 0 0 0 0 0 0 0 0 0
52769- 0 0 0 0 0 0 0 0 0 0 0 0
52770- 0 0 0 0 0 0 0 0 0 0 0 0
52771- 0 0 0 0 0 0 0 0 0 0 0 0
52772- 0 0 0 0 0 0 0 0 0 0 0 0
52773- 0 0 0 0 0 0 0 0 0 0 0 0
52774- 0 0 0 0 0 0 0 0 0 0 0 0
52775- 0 0 0 0 0 0 0 0 0 0 0 0
52776- 0 0 0 0 0 0 0 0 0 0 0 0
52777- 0 0 0 0 0 0 0 0 0 0 0 0
52778- 0 0 0 6 6 6 22 22 22 50 50 50
52779- 78 78 78 34 34 34 2 2 6 2 2 6
52780- 2 2 6 2 2 6 2 2 6 2 2 6
52781- 2 2 6 2 2 6 2 2 6 2 2 6
52782- 2 2 6 2 2 6 6 6 6 70 70 70
52783- 78 78 78 46 46 46 22 22 22 6 6 6
52784- 0 0 0 0 0 0 0 0 0 0 0 0
52785- 0 0 0 0 0 0 0 0 0 0 0 0
52786- 0 0 0 0 0 0 0 0 0 0 0 0
52787- 0 0 0 0 0 0 0 0 0 0 0 0
52788- 0 0 0 0 0 0 0 0 0 0 0 0
52789- 0 0 0 0 0 0 0 0 0 0 0 0
52790- 0 0 0 0 0 0 0 0 0 0 0 0
52791- 0 0 0 0 0 0 0 0 0 0 0 0
52792- 0 0 1 0 0 1 0 0 1 0 0 0
52793- 0 0 0 0 0 0 0 0 0 0 0 0
52794- 0 0 0 0 0 0 0 0 0 0 0 0
52795- 0 0 0 0 0 0 0 0 0 0 0 0
52796- 0 0 0 0 0 0 0 0 0 0 0 0
52797- 0 0 0 0 0 0 0 0 0 0 0 0
52798- 6 6 6 18 18 18 42 42 42 82 82 82
52799- 26 26 26 2 2 6 2 2 6 2 2 6
52800- 2 2 6 2 2 6 2 2 6 2 2 6
52801- 2 2 6 2 2 6 2 2 6 14 14 14
52802- 46 46 46 34 34 34 6 6 6 2 2 6
52803- 42 42 42 78 78 78 42 42 42 18 18 18
52804- 6 6 6 0 0 0 0 0 0 0 0 0
52805- 0 0 0 0 0 0 0 0 0 0 0 0
52806- 0 0 0 0 0 0 0 0 0 0 0 0
52807- 0 0 0 0 0 0 0 0 0 0 0 0
52808- 0 0 0 0 0 0 0 0 0 0 0 0
52809- 0 0 0 0 0 0 0 0 0 0 0 0
52810- 0 0 0 0 0 0 0 0 0 0 0 0
52811- 0 0 0 0 0 0 0 0 0 0 0 0
52812- 0 0 1 0 0 0 0 0 1 0 0 0
52813- 0 0 0 0 0 0 0 0 0 0 0 0
52814- 0 0 0 0 0 0 0 0 0 0 0 0
52815- 0 0 0 0 0 0 0 0 0 0 0 0
52816- 0 0 0 0 0 0 0 0 0 0 0 0
52817- 0 0 0 0 0 0 0 0 0 0 0 0
52818- 10 10 10 30 30 30 66 66 66 58 58 58
52819- 2 2 6 2 2 6 2 2 6 2 2 6
52820- 2 2 6 2 2 6 2 2 6 2 2 6
52821- 2 2 6 2 2 6 2 2 6 26 26 26
52822- 86 86 86 101 101 101 46 46 46 10 10 10
52823- 2 2 6 58 58 58 70 70 70 34 34 34
52824- 10 10 10 0 0 0 0 0 0 0 0 0
52825- 0 0 0 0 0 0 0 0 0 0 0 0
52826- 0 0 0 0 0 0 0 0 0 0 0 0
52827- 0 0 0 0 0 0 0 0 0 0 0 0
52828- 0 0 0 0 0 0 0 0 0 0 0 0
52829- 0 0 0 0 0 0 0 0 0 0 0 0
52830- 0 0 0 0 0 0 0 0 0 0 0 0
52831- 0 0 0 0 0 0 0 0 0 0 0 0
52832- 0 0 1 0 0 1 0 0 1 0 0 0
52833- 0 0 0 0 0 0 0 0 0 0 0 0
52834- 0 0 0 0 0 0 0 0 0 0 0 0
52835- 0 0 0 0 0 0 0 0 0 0 0 0
52836- 0 0 0 0 0 0 0 0 0 0 0 0
52837- 0 0 0 0 0 0 0 0 0 0 0 0
52838- 14 14 14 42 42 42 86 86 86 10 10 10
52839- 2 2 6 2 2 6 2 2 6 2 2 6
52840- 2 2 6 2 2 6 2 2 6 2 2 6
52841- 2 2 6 2 2 6 2 2 6 30 30 30
52842- 94 94 94 94 94 94 58 58 58 26 26 26
52843- 2 2 6 6 6 6 78 78 78 54 54 54
52844- 22 22 22 6 6 6 0 0 0 0 0 0
52845- 0 0 0 0 0 0 0 0 0 0 0 0
52846- 0 0 0 0 0 0 0 0 0 0 0 0
52847- 0 0 0 0 0 0 0 0 0 0 0 0
52848- 0 0 0 0 0 0 0 0 0 0 0 0
52849- 0 0 0 0 0 0 0 0 0 0 0 0
52850- 0 0 0 0 0 0 0 0 0 0 0 0
52851- 0 0 0 0 0 0 0 0 0 0 0 0
52852- 0 0 0 0 0 0 0 0 0 0 0 0
52853- 0 0 0 0 0 0 0 0 0 0 0 0
52854- 0 0 0 0 0 0 0 0 0 0 0 0
52855- 0 0 0 0 0 0 0 0 0 0 0 0
52856- 0 0 0 0 0 0 0 0 0 0 0 0
52857- 0 0 0 0 0 0 0 0 0 6 6 6
52858- 22 22 22 62 62 62 62 62 62 2 2 6
52859- 2 2 6 2 2 6 2 2 6 2 2 6
52860- 2 2 6 2 2 6 2 2 6 2 2 6
52861- 2 2 6 2 2 6 2 2 6 26 26 26
52862- 54 54 54 38 38 38 18 18 18 10 10 10
52863- 2 2 6 2 2 6 34 34 34 82 82 82
52864- 38 38 38 14 14 14 0 0 0 0 0 0
52865- 0 0 0 0 0 0 0 0 0 0 0 0
52866- 0 0 0 0 0 0 0 0 0 0 0 0
52867- 0 0 0 0 0 0 0 0 0 0 0 0
52868- 0 0 0 0 0 0 0 0 0 0 0 0
52869- 0 0 0 0 0 0 0 0 0 0 0 0
52870- 0 0 0 0 0 0 0 0 0 0 0 0
52871- 0 0 0 0 0 0 0 0 0 0 0 0
52872- 0 0 0 0 0 1 0 0 1 0 0 0
52873- 0 0 0 0 0 0 0 0 0 0 0 0
52874- 0 0 0 0 0 0 0 0 0 0 0 0
52875- 0 0 0 0 0 0 0 0 0 0 0 0
52876- 0 0 0 0 0 0 0 0 0 0 0 0
52877- 0 0 0 0 0 0 0 0 0 6 6 6
52878- 30 30 30 78 78 78 30 30 30 2 2 6
52879- 2 2 6 2 2 6 2 2 6 2 2 6
52880- 2 2 6 2 2 6 2 2 6 2 2 6
52881- 2 2 6 2 2 6 2 2 6 10 10 10
52882- 10 10 10 2 2 6 2 2 6 2 2 6
52883- 2 2 6 2 2 6 2 2 6 78 78 78
52884- 50 50 50 18 18 18 6 6 6 0 0 0
52885- 0 0 0 0 0 0 0 0 0 0 0 0
52886- 0 0 0 0 0 0 0 0 0 0 0 0
52887- 0 0 0 0 0 0 0 0 0 0 0 0
52888- 0 0 0 0 0 0 0 0 0 0 0 0
52889- 0 0 0 0 0 0 0 0 0 0 0 0
52890- 0 0 0 0 0 0 0 0 0 0 0 0
52891- 0 0 0 0 0 0 0 0 0 0 0 0
52892- 0 0 1 0 0 0 0 0 0 0 0 0
52893- 0 0 0 0 0 0 0 0 0 0 0 0
52894- 0 0 0 0 0 0 0 0 0 0 0 0
52895- 0 0 0 0 0 0 0 0 0 0 0 0
52896- 0 0 0 0 0 0 0 0 0 0 0 0
52897- 0 0 0 0 0 0 0 0 0 10 10 10
52898- 38 38 38 86 86 86 14 14 14 2 2 6
52899- 2 2 6 2 2 6 2 2 6 2 2 6
52900- 2 2 6 2 2 6 2 2 6 2 2 6
52901- 2 2 6 2 2 6 2 2 6 2 2 6
52902- 2 2 6 2 2 6 2 2 6 2 2 6
52903- 2 2 6 2 2 6 2 2 6 54 54 54
52904- 66 66 66 26 26 26 6 6 6 0 0 0
52905- 0 0 0 0 0 0 0 0 0 0 0 0
52906- 0 0 0 0 0 0 0 0 0 0 0 0
52907- 0 0 0 0 0 0 0 0 0 0 0 0
52908- 0 0 0 0 0 0 0 0 0 0 0 0
52909- 0 0 0 0 0 0 0 0 0 0 0 0
52910- 0 0 0 0 0 0 0 0 0 0 0 0
52911- 0 0 0 0 0 0 0 0 0 0 0 0
52912- 0 0 0 0 0 1 0 0 1 0 0 0
52913- 0 0 0 0 0 0 0 0 0 0 0 0
52914- 0 0 0 0 0 0 0 0 0 0 0 0
52915- 0 0 0 0 0 0 0 0 0 0 0 0
52916- 0 0 0 0 0 0 0 0 0 0 0 0
52917- 0 0 0 0 0 0 0 0 0 14 14 14
52918- 42 42 42 82 82 82 2 2 6 2 2 6
52919- 2 2 6 6 6 6 10 10 10 2 2 6
52920- 2 2 6 2 2 6 2 2 6 2 2 6
52921- 2 2 6 2 2 6 2 2 6 6 6 6
52922- 14 14 14 10 10 10 2 2 6 2 2 6
52923- 2 2 6 2 2 6 2 2 6 18 18 18
52924- 82 82 82 34 34 34 10 10 10 0 0 0
52925- 0 0 0 0 0 0 0 0 0 0 0 0
52926- 0 0 0 0 0 0 0 0 0 0 0 0
52927- 0 0 0 0 0 0 0 0 0 0 0 0
52928- 0 0 0 0 0 0 0 0 0 0 0 0
52929- 0 0 0 0 0 0 0 0 0 0 0 0
52930- 0 0 0 0 0 0 0 0 0 0 0 0
52931- 0 0 0 0 0 0 0 0 0 0 0 0
52932- 0 0 1 0 0 0 0 0 0 0 0 0
52933- 0 0 0 0 0 0 0 0 0 0 0 0
52934- 0 0 0 0 0 0 0 0 0 0 0 0
52935- 0 0 0 0 0 0 0 0 0 0 0 0
52936- 0 0 0 0 0 0 0 0 0 0 0 0
52937- 0 0 0 0 0 0 0 0 0 14 14 14
52938- 46 46 46 86 86 86 2 2 6 2 2 6
52939- 6 6 6 6 6 6 22 22 22 34 34 34
52940- 6 6 6 2 2 6 2 2 6 2 2 6
52941- 2 2 6 2 2 6 18 18 18 34 34 34
52942- 10 10 10 50 50 50 22 22 22 2 2 6
52943- 2 2 6 2 2 6 2 2 6 10 10 10
52944- 86 86 86 42 42 42 14 14 14 0 0 0
52945- 0 0 0 0 0 0 0 0 0 0 0 0
52946- 0 0 0 0 0 0 0 0 0 0 0 0
52947- 0 0 0 0 0 0 0 0 0 0 0 0
52948- 0 0 0 0 0 0 0 0 0 0 0 0
52949- 0 0 0 0 0 0 0 0 0 0 0 0
52950- 0 0 0 0 0 0 0 0 0 0 0 0
52951- 0 0 0 0 0 0 0 0 0 0 0 0
52952- 0 0 1 0 0 1 0 0 1 0 0 0
52953- 0 0 0 0 0 0 0 0 0 0 0 0
52954- 0 0 0 0 0 0 0 0 0 0 0 0
52955- 0 0 0 0 0 0 0 0 0 0 0 0
52956- 0 0 0 0 0 0 0 0 0 0 0 0
52957- 0 0 0 0 0 0 0 0 0 14 14 14
52958- 46 46 46 86 86 86 2 2 6 2 2 6
52959- 38 38 38 116 116 116 94 94 94 22 22 22
52960- 22 22 22 2 2 6 2 2 6 2 2 6
52961- 14 14 14 86 86 86 138 138 138 162 162 162
52962-154 154 154 38 38 38 26 26 26 6 6 6
52963- 2 2 6 2 2 6 2 2 6 2 2 6
52964- 86 86 86 46 46 46 14 14 14 0 0 0
52965- 0 0 0 0 0 0 0 0 0 0 0 0
52966- 0 0 0 0 0 0 0 0 0 0 0 0
52967- 0 0 0 0 0 0 0 0 0 0 0 0
52968- 0 0 0 0 0 0 0 0 0 0 0 0
52969- 0 0 0 0 0 0 0 0 0 0 0 0
52970- 0 0 0 0 0 0 0 0 0 0 0 0
52971- 0 0 0 0 0 0 0 0 0 0 0 0
52972- 0 0 0 0 0 0 0 0 0 0 0 0
52973- 0 0 0 0 0 0 0 0 0 0 0 0
52974- 0 0 0 0 0 0 0 0 0 0 0 0
52975- 0 0 0 0 0 0 0 0 0 0 0 0
52976- 0 0 0 0 0 0 0 0 0 0 0 0
52977- 0 0 0 0 0 0 0 0 0 14 14 14
52978- 46 46 46 86 86 86 2 2 6 14 14 14
52979-134 134 134 198 198 198 195 195 195 116 116 116
52980- 10 10 10 2 2 6 2 2 6 6 6 6
52981-101 98 89 187 187 187 210 210 210 218 218 218
52982-214 214 214 134 134 134 14 14 14 6 6 6
52983- 2 2 6 2 2 6 2 2 6 2 2 6
52984- 86 86 86 50 50 50 18 18 18 6 6 6
52985- 0 0 0 0 0 0 0 0 0 0 0 0
52986- 0 0 0 0 0 0 0 0 0 0 0 0
52987- 0 0 0 0 0 0 0 0 0 0 0 0
52988- 0 0 0 0 0 0 0 0 0 0 0 0
52989- 0 0 0 0 0 0 0 0 0 0 0 0
52990- 0 0 0 0 0 0 0 0 0 0 0 0
52991- 0 0 0 0 0 0 0 0 1 0 0 0
52992- 0 0 1 0 0 1 0 0 1 0 0 0
52993- 0 0 0 0 0 0 0 0 0 0 0 0
52994- 0 0 0 0 0 0 0 0 0 0 0 0
52995- 0 0 0 0 0 0 0 0 0 0 0 0
52996- 0 0 0 0 0 0 0 0 0 0 0 0
52997- 0 0 0 0 0 0 0 0 0 14 14 14
52998- 46 46 46 86 86 86 2 2 6 54 54 54
52999-218 218 218 195 195 195 226 226 226 246 246 246
53000- 58 58 58 2 2 6 2 2 6 30 30 30
53001-210 210 210 253 253 253 174 174 174 123 123 123
53002-221 221 221 234 234 234 74 74 74 2 2 6
53003- 2 2 6 2 2 6 2 2 6 2 2 6
53004- 70 70 70 58 58 58 22 22 22 6 6 6
53005- 0 0 0 0 0 0 0 0 0 0 0 0
53006- 0 0 0 0 0 0 0 0 0 0 0 0
53007- 0 0 0 0 0 0 0 0 0 0 0 0
53008- 0 0 0 0 0 0 0 0 0 0 0 0
53009- 0 0 0 0 0 0 0 0 0 0 0 0
53010- 0 0 0 0 0 0 0 0 0 0 0 0
53011- 0 0 0 0 0 0 0 0 0 0 0 0
53012- 0 0 0 0 0 0 0 0 0 0 0 0
53013- 0 0 0 0 0 0 0 0 0 0 0 0
53014- 0 0 0 0 0 0 0 0 0 0 0 0
53015- 0 0 0 0 0 0 0 0 0 0 0 0
53016- 0 0 0 0 0 0 0 0 0 0 0 0
53017- 0 0 0 0 0 0 0 0 0 14 14 14
53018- 46 46 46 82 82 82 2 2 6 106 106 106
53019-170 170 170 26 26 26 86 86 86 226 226 226
53020-123 123 123 10 10 10 14 14 14 46 46 46
53021-231 231 231 190 190 190 6 6 6 70 70 70
53022- 90 90 90 238 238 238 158 158 158 2 2 6
53023- 2 2 6 2 2 6 2 2 6 2 2 6
53024- 70 70 70 58 58 58 22 22 22 6 6 6
53025- 0 0 0 0 0 0 0 0 0 0 0 0
53026- 0 0 0 0 0 0 0 0 0 0 0 0
53027- 0 0 0 0 0 0 0 0 0 0 0 0
53028- 0 0 0 0 0 0 0 0 0 0 0 0
53029- 0 0 0 0 0 0 0 0 0 0 0 0
53030- 0 0 0 0 0 0 0 0 0 0 0 0
53031- 0 0 0 0 0 0 0 0 1 0 0 0
53032- 0 0 1 0 0 1 0 0 1 0 0 0
53033- 0 0 0 0 0 0 0 0 0 0 0 0
53034- 0 0 0 0 0 0 0 0 0 0 0 0
53035- 0 0 0 0 0 0 0 0 0 0 0 0
53036- 0 0 0 0 0 0 0 0 0 0 0 0
53037- 0 0 0 0 0 0 0 0 0 14 14 14
53038- 42 42 42 86 86 86 6 6 6 116 116 116
53039-106 106 106 6 6 6 70 70 70 149 149 149
53040-128 128 128 18 18 18 38 38 38 54 54 54
53041-221 221 221 106 106 106 2 2 6 14 14 14
53042- 46 46 46 190 190 190 198 198 198 2 2 6
53043- 2 2 6 2 2 6 2 2 6 2 2 6
53044- 74 74 74 62 62 62 22 22 22 6 6 6
53045- 0 0 0 0 0 0 0 0 0 0 0 0
53046- 0 0 0 0 0 0 0 0 0 0 0 0
53047- 0 0 0 0 0 0 0 0 0 0 0 0
53048- 0 0 0 0 0 0 0 0 0 0 0 0
53049- 0 0 0 0 0 0 0 0 0 0 0 0
53050- 0 0 0 0 0 0 0 0 0 0 0 0
53051- 0 0 0 0 0 0 0 0 1 0 0 0
53052- 0 0 1 0 0 0 0 0 1 0 0 0
53053- 0 0 0 0 0 0 0 0 0 0 0 0
53054- 0 0 0 0 0 0 0 0 0 0 0 0
53055- 0 0 0 0 0 0 0 0 0 0 0 0
53056- 0 0 0 0 0 0 0 0 0 0 0 0
53057- 0 0 0 0 0 0 0 0 0 14 14 14
53058- 42 42 42 94 94 94 14 14 14 101 101 101
53059-128 128 128 2 2 6 18 18 18 116 116 116
53060-118 98 46 121 92 8 121 92 8 98 78 10
53061-162 162 162 106 106 106 2 2 6 2 2 6
53062- 2 2 6 195 195 195 195 195 195 6 6 6
53063- 2 2 6 2 2 6 2 2 6 2 2 6
53064- 74 74 74 62 62 62 22 22 22 6 6 6
53065- 0 0 0 0 0 0 0 0 0 0 0 0
53066- 0 0 0 0 0 0 0 0 0 0 0 0
53067- 0 0 0 0 0 0 0 0 0 0 0 0
53068- 0 0 0 0 0 0 0 0 0 0 0 0
53069- 0 0 0 0 0 0 0 0 0 0 0 0
53070- 0 0 0 0 0 0 0 0 0 0 0 0
53071- 0 0 0 0 0 0 0 0 1 0 0 1
53072- 0 0 1 0 0 0 0 0 1 0 0 0
53073- 0 0 0 0 0 0 0 0 0 0 0 0
53074- 0 0 0 0 0 0 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 0 0 0
53076- 0 0 0 0 0 0 0 0 0 0 0 0
53077- 0 0 0 0 0 0 0 0 0 10 10 10
53078- 38 38 38 90 90 90 14 14 14 58 58 58
53079-210 210 210 26 26 26 54 38 6 154 114 10
53080-226 170 11 236 186 11 225 175 15 184 144 12
53081-215 174 15 175 146 61 37 26 9 2 2 6
53082- 70 70 70 246 246 246 138 138 138 2 2 6
53083- 2 2 6 2 2 6 2 2 6 2 2 6
53084- 70 70 70 66 66 66 26 26 26 6 6 6
53085- 0 0 0 0 0 0 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 0 0 0
53089- 0 0 0 0 0 0 0 0 0 0 0 0
53090- 0 0 0 0 0 0 0 0 0 0 0 0
53091- 0 0 0 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 0 0 0 0 0 0 0 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 0 0 0 0 0 0 0 0 0 0 0 0
53097- 0 0 0 0 0 0 0 0 0 10 10 10
53098- 38 38 38 86 86 86 14 14 14 10 10 10
53099-195 195 195 188 164 115 192 133 9 225 175 15
53100-239 182 13 234 190 10 232 195 16 232 200 30
53101-245 207 45 241 208 19 232 195 16 184 144 12
53102-218 194 134 211 206 186 42 42 42 2 2 6
53103- 2 2 6 2 2 6 2 2 6 2 2 6
53104- 50 50 50 74 74 74 30 30 30 6 6 6
53105- 0 0 0 0 0 0 0 0 0 0 0 0
53106- 0 0 0 0 0 0 0 0 0 0 0 0
53107- 0 0 0 0 0 0 0 0 0 0 0 0
53108- 0 0 0 0 0 0 0 0 0 0 0 0
53109- 0 0 0 0 0 0 0 0 0 0 0 0
53110- 0 0 0 0 0 0 0 0 0 0 0 0
53111- 0 0 0 0 0 0 0 0 0 0 0 0
53112- 0 0 0 0 0 0 0 0 0 0 0 0
53113- 0 0 0 0 0 0 0 0 0 0 0 0
53114- 0 0 0 0 0 0 0 0 0 0 0 0
53115- 0 0 0 0 0 0 0 0 0 0 0 0
53116- 0 0 0 0 0 0 0 0 0 0 0 0
53117- 0 0 0 0 0 0 0 0 0 10 10 10
53118- 34 34 34 86 86 86 14 14 14 2 2 6
53119-121 87 25 192 133 9 219 162 10 239 182 13
53120-236 186 11 232 195 16 241 208 19 244 214 54
53121-246 218 60 246 218 38 246 215 20 241 208 19
53122-241 208 19 226 184 13 121 87 25 2 2 6
53123- 2 2 6 2 2 6 2 2 6 2 2 6
53124- 50 50 50 82 82 82 34 34 34 10 10 10
53125- 0 0 0 0 0 0 0 0 0 0 0 0
53126- 0 0 0 0 0 0 0 0 0 0 0 0
53127- 0 0 0 0 0 0 0 0 0 0 0 0
53128- 0 0 0 0 0 0 0 0 0 0 0 0
53129- 0 0 0 0 0 0 0 0 0 0 0 0
53130- 0 0 0 0 0 0 0 0 0 0 0 0
53131- 0 0 0 0 0 0 0 0 0 0 0 0
53132- 0 0 0 0 0 0 0 0 0 0 0 0
53133- 0 0 0 0 0 0 0 0 0 0 0 0
53134- 0 0 0 0 0 0 0 0 0 0 0 0
53135- 0 0 0 0 0 0 0 0 0 0 0 0
53136- 0 0 0 0 0 0 0 0 0 0 0 0
53137- 0 0 0 0 0 0 0 0 0 10 10 10
53138- 34 34 34 82 82 82 30 30 30 61 42 6
53139-180 123 7 206 145 10 230 174 11 239 182 13
53140-234 190 10 238 202 15 241 208 19 246 218 74
53141-246 218 38 246 215 20 246 215 20 246 215 20
53142-226 184 13 215 174 15 184 144 12 6 6 6
53143- 2 2 6 2 2 6 2 2 6 2 2 6
53144- 26 26 26 94 94 94 42 42 42 14 14 14
53145- 0 0 0 0 0 0 0 0 0 0 0 0
53146- 0 0 0 0 0 0 0 0 0 0 0 0
53147- 0 0 0 0 0 0 0 0 0 0 0 0
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 0 0 0 0 0 0 0 0 0 0
53150- 0 0 0 0 0 0 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 0 0 0 0 0 0 0 0 0 0
53155- 0 0 0 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 0 0 0 0 0 0 0 0 0 10 10 10
53158- 30 30 30 78 78 78 50 50 50 104 69 6
53159-192 133 9 216 158 10 236 178 12 236 186 11
53160-232 195 16 241 208 19 244 214 54 245 215 43
53161-246 215 20 246 215 20 241 208 19 198 155 10
53162-200 144 11 216 158 10 156 118 10 2 2 6
53163- 2 2 6 2 2 6 2 2 6 2 2 6
53164- 6 6 6 90 90 90 54 54 54 18 18 18
53165- 6 6 6 0 0 0 0 0 0 0 0 0
53166- 0 0 0 0 0 0 0 0 0 0 0 0
53167- 0 0 0 0 0 0 0 0 0 0 0 0
53168- 0 0 0 0 0 0 0 0 0 0 0 0
53169- 0 0 0 0 0 0 0 0 0 0 0 0
53170- 0 0 0 0 0 0 0 0 0 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 0 0 0 0 0 0 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 10 10 10
53178- 30 30 30 78 78 78 46 46 46 22 22 22
53179-137 92 6 210 162 10 239 182 13 238 190 10
53180-238 202 15 241 208 19 246 215 20 246 215 20
53181-241 208 19 203 166 17 185 133 11 210 150 10
53182-216 158 10 210 150 10 102 78 10 2 2 6
53183- 6 6 6 54 54 54 14 14 14 2 2 6
53184- 2 2 6 62 62 62 74 74 74 30 30 30
53185- 10 10 10 0 0 0 0 0 0 0 0 0
53186- 0 0 0 0 0 0 0 0 0 0 0 0
53187- 0 0 0 0 0 0 0 0 0 0 0 0
53188- 0 0 0 0 0 0 0 0 0 0 0 0
53189- 0 0 0 0 0 0 0 0 0 0 0 0
53190- 0 0 0 0 0 0 0 0 0 0 0 0
53191- 0 0 0 0 0 0 0 0 0 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 0 0 0 0 0 0 0 0 0 0
53194- 0 0 0 0 0 0 0 0 0 0 0 0
53195- 0 0 0 0 0 0 0 0 0 0 0 0
53196- 0 0 0 0 0 0 0 0 0 0 0 0
53197- 0 0 0 0 0 0 0 0 0 10 10 10
53198- 34 34 34 78 78 78 50 50 50 6 6 6
53199- 94 70 30 139 102 15 190 146 13 226 184 13
53200-232 200 30 232 195 16 215 174 15 190 146 13
53201-168 122 10 192 133 9 210 150 10 213 154 11
53202-202 150 34 182 157 106 101 98 89 2 2 6
53203- 2 2 6 78 78 78 116 116 116 58 58 58
53204- 2 2 6 22 22 22 90 90 90 46 46 46
53205- 18 18 18 6 6 6 0 0 0 0 0 0
53206- 0 0 0 0 0 0 0 0 0 0 0 0
53207- 0 0 0 0 0 0 0 0 0 0 0 0
53208- 0 0 0 0 0 0 0 0 0 0 0 0
53209- 0 0 0 0 0 0 0 0 0 0 0 0
53210- 0 0 0 0 0 0 0 0 0 0 0 0
53211- 0 0 0 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 0 0 0 0 0 0 0 0 0 0
53215- 0 0 0 0 0 0 0 0 0 0 0 0
53216- 0 0 0 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 10 10 10
53218- 38 38 38 86 86 86 50 50 50 6 6 6
53219-128 128 128 174 154 114 156 107 11 168 122 10
53220-198 155 10 184 144 12 197 138 11 200 144 11
53221-206 145 10 206 145 10 197 138 11 188 164 115
53222-195 195 195 198 198 198 174 174 174 14 14 14
53223- 2 2 6 22 22 22 116 116 116 116 116 116
53224- 22 22 22 2 2 6 74 74 74 70 70 70
53225- 30 30 30 10 10 10 0 0 0 0 0 0
53226- 0 0 0 0 0 0 0 0 0 0 0 0
53227- 0 0 0 0 0 0 0 0 0 0 0 0
53228- 0 0 0 0 0 0 0 0 0 0 0 0
53229- 0 0 0 0 0 0 0 0 0 0 0 0
53230- 0 0 0 0 0 0 0 0 0 0 0 0
53231- 0 0 0 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 0 0 0 0 0 0 0 0 0 0
53235- 0 0 0 0 0 0 0 0 0 0 0 0
53236- 0 0 0 0 0 0 0 0 0 0 0 0
53237- 0 0 0 0 0 0 6 6 6 18 18 18
53238- 50 50 50 101 101 101 26 26 26 10 10 10
53239-138 138 138 190 190 190 174 154 114 156 107 11
53240-197 138 11 200 144 11 197 138 11 192 133 9
53241-180 123 7 190 142 34 190 178 144 187 187 187
53242-202 202 202 221 221 221 214 214 214 66 66 66
53243- 2 2 6 2 2 6 50 50 50 62 62 62
53244- 6 6 6 2 2 6 10 10 10 90 90 90
53245- 50 50 50 18 18 18 6 6 6 0 0 0
53246- 0 0 0 0 0 0 0 0 0 0 0 0
53247- 0 0 0 0 0 0 0 0 0 0 0 0
53248- 0 0 0 0 0 0 0 0 0 0 0 0
53249- 0 0 0 0 0 0 0 0 0 0 0 0
53250- 0 0 0 0 0 0 0 0 0 0 0 0
53251- 0 0 0 0 0 0 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 0 0 0
53255- 0 0 0 0 0 0 0 0 0 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 10 10 10 34 34 34
53258- 74 74 74 74 74 74 2 2 6 6 6 6
53259-144 144 144 198 198 198 190 190 190 178 166 146
53260-154 121 60 156 107 11 156 107 11 168 124 44
53261-174 154 114 187 187 187 190 190 190 210 210 210
53262-246 246 246 253 253 253 253 253 253 182 182 182
53263- 6 6 6 2 2 6 2 2 6 2 2 6
53264- 2 2 6 2 2 6 2 2 6 62 62 62
53265- 74 74 74 34 34 34 14 14 14 0 0 0
53266- 0 0 0 0 0 0 0 0 0 0 0 0
53267- 0 0 0 0 0 0 0 0 0 0 0 0
53268- 0 0 0 0 0 0 0 0 0 0 0 0
53269- 0 0 0 0 0 0 0 0 0 0 0 0
53270- 0 0 0 0 0 0 0 0 0 0 0 0
53271- 0 0 0 0 0 0 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 0 0 0 0 0 0 0 0 0 0
53275- 0 0 0 0 0 0 0 0 0 0 0 0
53276- 0 0 0 0 0 0 0 0 0 0 0 0
53277- 0 0 0 10 10 10 22 22 22 54 54 54
53278- 94 94 94 18 18 18 2 2 6 46 46 46
53279-234 234 234 221 221 221 190 190 190 190 190 190
53280-190 190 190 187 187 187 187 187 187 190 190 190
53281-190 190 190 195 195 195 214 214 214 242 242 242
53282-253 253 253 253 253 253 253 253 253 253 253 253
53283- 82 82 82 2 2 6 2 2 6 2 2 6
53284- 2 2 6 2 2 6 2 2 6 14 14 14
53285- 86 86 86 54 54 54 22 22 22 6 6 6
53286- 0 0 0 0 0 0 0 0 0 0 0 0
53287- 0 0 0 0 0 0 0 0 0 0 0 0
53288- 0 0 0 0 0 0 0 0 0 0 0 0
53289- 0 0 0 0 0 0 0 0 0 0 0 0
53290- 0 0 0 0 0 0 0 0 0 0 0 0
53291- 0 0 0 0 0 0 0 0 0 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 0 0 0 0 0 0 0 0 0 0
53295- 0 0 0 0 0 0 0 0 0 0 0 0
53296- 0 0 0 0 0 0 0 0 0 0 0 0
53297- 6 6 6 18 18 18 46 46 46 90 90 90
53298- 46 46 46 18 18 18 6 6 6 182 182 182
53299-253 253 253 246 246 246 206 206 206 190 190 190
53300-190 190 190 190 190 190 190 190 190 190 190 190
53301-206 206 206 231 231 231 250 250 250 253 253 253
53302-253 253 253 253 253 253 253 253 253 253 253 253
53303-202 202 202 14 14 14 2 2 6 2 2 6
53304- 2 2 6 2 2 6 2 2 6 2 2 6
53305- 42 42 42 86 86 86 42 42 42 18 18 18
53306- 6 6 6 0 0 0 0 0 0 0 0 0
53307- 0 0 0 0 0 0 0 0 0 0 0 0
53308- 0 0 0 0 0 0 0 0 0 0 0 0
53309- 0 0 0 0 0 0 0 0 0 0 0 0
53310- 0 0 0 0 0 0 0 0 0 0 0 0
53311- 0 0 0 0 0 0 0 0 0 0 0 0
53312- 0 0 0 0 0 0 0 0 0 0 0 0
53313- 0 0 0 0 0 0 0 0 0 0 0 0
53314- 0 0 0 0 0 0 0 0 0 0 0 0
53315- 0 0 0 0 0 0 0 0 0 0 0 0
53316- 0 0 0 0 0 0 0 0 0 6 6 6
53317- 14 14 14 38 38 38 74 74 74 66 66 66
53318- 2 2 6 6 6 6 90 90 90 250 250 250
53319-253 253 253 253 253 253 238 238 238 198 198 198
53320-190 190 190 190 190 190 195 195 195 221 221 221
53321-246 246 246 253 253 253 253 253 253 253 253 253
53322-253 253 253 253 253 253 253 253 253 253 253 253
53323-253 253 253 82 82 82 2 2 6 2 2 6
53324- 2 2 6 2 2 6 2 2 6 2 2 6
53325- 2 2 6 78 78 78 70 70 70 34 34 34
53326- 14 14 14 6 6 6 0 0 0 0 0 0
53327- 0 0 0 0 0 0 0 0 0 0 0 0
53328- 0 0 0 0 0 0 0 0 0 0 0 0
53329- 0 0 0 0 0 0 0 0 0 0 0 0
53330- 0 0 0 0 0 0 0 0 0 0 0 0
53331- 0 0 0 0 0 0 0 0 0 0 0 0
53332- 0 0 0 0 0 0 0 0 0 0 0 0
53333- 0 0 0 0 0 0 0 0 0 0 0 0
53334- 0 0 0 0 0 0 0 0 0 0 0 0
53335- 0 0 0 0 0 0 0 0 0 0 0 0
53336- 0 0 0 0 0 0 0 0 0 14 14 14
53337- 34 34 34 66 66 66 78 78 78 6 6 6
53338- 2 2 6 18 18 18 218 218 218 253 253 253
53339-253 253 253 253 253 253 253 253 253 246 246 246
53340-226 226 226 231 231 231 246 246 246 253 253 253
53341-253 253 253 253 253 253 253 253 253 253 253 253
53342-253 253 253 253 253 253 253 253 253 253 253 253
53343-253 253 253 178 178 178 2 2 6 2 2 6
53344- 2 2 6 2 2 6 2 2 6 2 2 6
53345- 2 2 6 18 18 18 90 90 90 62 62 62
53346- 30 30 30 10 10 10 0 0 0 0 0 0
53347- 0 0 0 0 0 0 0 0 0 0 0 0
53348- 0 0 0 0 0 0 0 0 0 0 0 0
53349- 0 0 0 0 0 0 0 0 0 0 0 0
53350- 0 0 0 0 0 0 0 0 0 0 0 0
53351- 0 0 0 0 0 0 0 0 0 0 0 0
53352- 0 0 0 0 0 0 0 0 0 0 0 0
53353- 0 0 0 0 0 0 0 0 0 0 0 0
53354- 0 0 0 0 0 0 0 0 0 0 0 0
53355- 0 0 0 0 0 0 0 0 0 0 0 0
53356- 0 0 0 0 0 0 10 10 10 26 26 26
53357- 58 58 58 90 90 90 18 18 18 2 2 6
53358- 2 2 6 110 110 110 253 253 253 253 253 253
53359-253 253 253 253 253 253 253 253 253 253 253 253
53360-250 250 250 253 253 253 253 253 253 253 253 253
53361-253 253 253 253 253 253 253 253 253 253 253 253
53362-253 253 253 253 253 253 253 253 253 253 253 253
53363-253 253 253 231 231 231 18 18 18 2 2 6
53364- 2 2 6 2 2 6 2 2 6 2 2 6
53365- 2 2 6 2 2 6 18 18 18 94 94 94
53366- 54 54 54 26 26 26 10 10 10 0 0 0
53367- 0 0 0 0 0 0 0 0 0 0 0 0
53368- 0 0 0 0 0 0 0 0 0 0 0 0
53369- 0 0 0 0 0 0 0 0 0 0 0 0
53370- 0 0 0 0 0 0 0 0 0 0 0 0
53371- 0 0 0 0 0 0 0 0 0 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 0 0 0
53375- 0 0 0 0 0 0 0 0 0 0 0 0
53376- 0 0 0 6 6 6 22 22 22 50 50 50
53377- 90 90 90 26 26 26 2 2 6 2 2 6
53378- 14 14 14 195 195 195 250 250 250 253 253 253
53379-253 253 253 253 253 253 253 253 253 253 253 253
53380-253 253 253 253 253 253 253 253 253 253 253 253
53381-253 253 253 253 253 253 253 253 253 253 253 253
53382-253 253 253 253 253 253 253 253 253 253 253 253
53383-250 250 250 242 242 242 54 54 54 2 2 6
53384- 2 2 6 2 2 6 2 2 6 2 2 6
53385- 2 2 6 2 2 6 2 2 6 38 38 38
53386- 86 86 86 50 50 50 22 22 22 6 6 6
53387- 0 0 0 0 0 0 0 0 0 0 0 0
53388- 0 0 0 0 0 0 0 0 0 0 0 0
53389- 0 0 0 0 0 0 0 0 0 0 0 0
53390- 0 0 0 0 0 0 0 0 0 0 0 0
53391- 0 0 0 0 0 0 0 0 0 0 0 0
53392- 0 0 0 0 0 0 0 0 0 0 0 0
53393- 0 0 0 0 0 0 0 0 0 0 0 0
53394- 0 0 0 0 0 0 0 0 0 0 0 0
53395- 0 0 0 0 0 0 0 0 0 0 0 0
53396- 6 6 6 14 14 14 38 38 38 82 82 82
53397- 34 34 34 2 2 6 2 2 6 2 2 6
53398- 42 42 42 195 195 195 246 246 246 253 253 253
53399-253 253 253 253 253 253 253 253 253 250 250 250
53400-242 242 242 242 242 242 250 250 250 253 253 253
53401-253 253 253 253 253 253 253 253 253 253 253 253
53402-253 253 253 250 250 250 246 246 246 238 238 238
53403-226 226 226 231 231 231 101 101 101 6 6 6
53404- 2 2 6 2 2 6 2 2 6 2 2 6
53405- 2 2 6 2 2 6 2 2 6 2 2 6
53406- 38 38 38 82 82 82 42 42 42 14 14 14
53407- 6 6 6 0 0 0 0 0 0 0 0 0
53408- 0 0 0 0 0 0 0 0 0 0 0 0
53409- 0 0 0 0 0 0 0 0 0 0 0 0
53410- 0 0 0 0 0 0 0 0 0 0 0 0
53411- 0 0 0 0 0 0 0 0 0 0 0 0
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 0 0 0 0
53414- 0 0 0 0 0 0 0 0 0 0 0 0
53415- 0 0 0 0 0 0 0 0 0 0 0 0
53416- 10 10 10 26 26 26 62 62 62 66 66 66
53417- 2 2 6 2 2 6 2 2 6 6 6 6
53418- 70 70 70 170 170 170 206 206 206 234 234 234
53419-246 246 246 250 250 250 250 250 250 238 238 238
53420-226 226 226 231 231 231 238 238 238 250 250 250
53421-250 250 250 250 250 250 246 246 246 231 231 231
53422-214 214 214 206 206 206 202 202 202 202 202 202
53423-198 198 198 202 202 202 182 182 182 18 18 18
53424- 2 2 6 2 2 6 2 2 6 2 2 6
53425- 2 2 6 2 2 6 2 2 6 2 2 6
53426- 2 2 6 62 62 62 66 66 66 30 30 30
53427- 10 10 10 0 0 0 0 0 0 0 0 0
53428- 0 0 0 0 0 0 0 0 0 0 0 0
53429- 0 0 0 0 0 0 0 0 0 0 0 0
53430- 0 0 0 0 0 0 0 0 0 0 0 0
53431- 0 0 0 0 0 0 0 0 0 0 0 0
53432- 0 0 0 0 0 0 0 0 0 0 0 0
53433- 0 0 0 0 0 0 0 0 0 0 0 0
53434- 0 0 0 0 0 0 0 0 0 0 0 0
53435- 0 0 0 0 0 0 0 0 0 0 0 0
53436- 14 14 14 42 42 42 82 82 82 18 18 18
53437- 2 2 6 2 2 6 2 2 6 10 10 10
53438- 94 94 94 182 182 182 218 218 218 242 242 242
53439-250 250 250 253 253 253 253 253 253 250 250 250
53440-234 234 234 253 253 253 253 253 253 253 253 253
53441-253 253 253 253 253 253 253 253 253 246 246 246
53442-238 238 238 226 226 226 210 210 210 202 202 202
53443-195 195 195 195 195 195 210 210 210 158 158 158
53444- 6 6 6 14 14 14 50 50 50 14 14 14
53445- 2 2 6 2 2 6 2 2 6 2 2 6
53446- 2 2 6 6 6 6 86 86 86 46 46 46
53447- 18 18 18 6 6 6 0 0 0 0 0 0
53448- 0 0 0 0 0 0 0 0 0 0 0 0
53449- 0 0 0 0 0 0 0 0 0 0 0 0
53450- 0 0 0 0 0 0 0 0 0 0 0 0
53451- 0 0 0 0 0 0 0 0 0 0 0 0
53452- 0 0 0 0 0 0 0 0 0 0 0 0
53453- 0 0 0 0 0 0 0 0 0 0 0 0
53454- 0 0 0 0 0 0 0 0 0 0 0 0
53455- 0 0 0 0 0 0 0 0 0 6 6 6
53456- 22 22 22 54 54 54 70 70 70 2 2 6
53457- 2 2 6 10 10 10 2 2 6 22 22 22
53458-166 166 166 231 231 231 250 250 250 253 253 253
53459-253 253 253 253 253 253 253 253 253 250 250 250
53460-242 242 242 253 253 253 253 253 253 253 253 253
53461-253 253 253 253 253 253 253 253 253 253 253 253
53462-253 253 253 253 253 253 253 253 253 246 246 246
53463-231 231 231 206 206 206 198 198 198 226 226 226
53464- 94 94 94 2 2 6 6 6 6 38 38 38
53465- 30 30 30 2 2 6 2 2 6 2 2 6
53466- 2 2 6 2 2 6 62 62 62 66 66 66
53467- 26 26 26 10 10 10 0 0 0 0 0 0
53468- 0 0 0 0 0 0 0 0 0 0 0 0
53469- 0 0 0 0 0 0 0 0 0 0 0 0
53470- 0 0 0 0 0 0 0 0 0 0 0 0
53471- 0 0 0 0 0 0 0 0 0 0 0 0
53472- 0 0 0 0 0 0 0 0 0 0 0 0
53473- 0 0 0 0 0 0 0 0 0 0 0 0
53474- 0 0 0 0 0 0 0 0 0 0 0 0
53475- 0 0 0 0 0 0 0 0 0 10 10 10
53476- 30 30 30 74 74 74 50 50 50 2 2 6
53477- 26 26 26 26 26 26 2 2 6 106 106 106
53478-238 238 238 253 253 253 253 253 253 253 253 253
53479-253 253 253 253 253 253 253 253 253 253 253 253
53480-253 253 253 253 253 253 253 253 253 253 253 253
53481-253 253 253 253 253 253 253 253 253 253 253 253
53482-253 253 253 253 253 253 253 253 253 253 253 253
53483-253 253 253 246 246 246 218 218 218 202 202 202
53484-210 210 210 14 14 14 2 2 6 2 2 6
53485- 30 30 30 22 22 22 2 2 6 2 2 6
53486- 2 2 6 2 2 6 18 18 18 86 86 86
53487- 42 42 42 14 14 14 0 0 0 0 0 0
53488- 0 0 0 0 0 0 0 0 0 0 0 0
53489- 0 0 0 0 0 0 0 0 0 0 0 0
53490- 0 0 0 0 0 0 0 0 0 0 0 0
53491- 0 0 0 0 0 0 0 0 0 0 0 0
53492- 0 0 0 0 0 0 0 0 0 0 0 0
53493- 0 0 0 0 0 0 0 0 0 0 0 0
53494- 0 0 0 0 0 0 0 0 0 0 0 0
53495- 0 0 0 0 0 0 0 0 0 14 14 14
53496- 42 42 42 90 90 90 22 22 22 2 2 6
53497- 42 42 42 2 2 6 18 18 18 218 218 218
53498-253 253 253 253 253 253 253 253 253 253 253 253
53499-253 253 253 253 253 253 253 253 253 253 253 253
53500-253 253 253 253 253 253 253 253 253 253 253 253
53501-253 253 253 253 253 253 253 253 253 253 253 253
53502-253 253 253 253 253 253 253 253 253 253 253 253
53503-253 253 253 253 253 253 250 250 250 221 221 221
53504-218 218 218 101 101 101 2 2 6 14 14 14
53505- 18 18 18 38 38 38 10 10 10 2 2 6
53506- 2 2 6 2 2 6 2 2 6 78 78 78
53507- 58 58 58 22 22 22 6 6 6 0 0 0
53508- 0 0 0 0 0 0 0 0 0 0 0 0
53509- 0 0 0 0 0 0 0 0 0 0 0 0
53510- 0 0 0 0 0 0 0 0 0 0 0 0
53511- 0 0 0 0 0 0 0 0 0 0 0 0
53512- 0 0 0 0 0 0 0 0 0 0 0 0
53513- 0 0 0 0 0 0 0 0 0 0 0 0
53514- 0 0 0 0 0 0 0 0 0 0 0 0
53515- 0 0 0 0 0 0 6 6 6 18 18 18
53516- 54 54 54 82 82 82 2 2 6 26 26 26
53517- 22 22 22 2 2 6 123 123 123 253 253 253
53518-253 253 253 253 253 253 253 253 253 253 253 253
53519-253 253 253 253 253 253 253 253 253 253 253 253
53520-253 253 253 253 253 253 253 253 253 253 253 253
53521-253 253 253 253 253 253 253 253 253 253 253 253
53522-253 253 253 253 253 253 253 253 253 253 253 253
53523-253 253 253 253 253 253 253 253 253 250 250 250
53524-238 238 238 198 198 198 6 6 6 38 38 38
53525- 58 58 58 26 26 26 38 38 38 2 2 6
53526- 2 2 6 2 2 6 2 2 6 46 46 46
53527- 78 78 78 30 30 30 10 10 10 0 0 0
53528- 0 0 0 0 0 0 0 0 0 0 0 0
53529- 0 0 0 0 0 0 0 0 0 0 0 0
53530- 0 0 0 0 0 0 0 0 0 0 0 0
53531- 0 0 0 0 0 0 0 0 0 0 0 0
53532- 0 0 0 0 0 0 0 0 0 0 0 0
53533- 0 0 0 0 0 0 0 0 0 0 0 0
53534- 0 0 0 0 0 0 0 0 0 0 0 0
53535- 0 0 0 0 0 0 10 10 10 30 30 30
53536- 74 74 74 58 58 58 2 2 6 42 42 42
53537- 2 2 6 22 22 22 231 231 231 253 253 253
53538-253 253 253 253 253 253 253 253 253 253 253 253
53539-253 253 253 253 253 253 253 253 253 250 250 250
53540-253 253 253 253 253 253 253 253 253 253 253 253
53541-253 253 253 253 253 253 253 253 253 253 253 253
53542-253 253 253 253 253 253 253 253 253 253 253 253
53543-253 253 253 253 253 253 253 253 253 253 253 253
53544-253 253 253 246 246 246 46 46 46 38 38 38
53545- 42 42 42 14 14 14 38 38 38 14 14 14
53546- 2 2 6 2 2 6 2 2 6 6 6 6
53547- 86 86 86 46 46 46 14 14 14 0 0 0
53548- 0 0 0 0 0 0 0 0 0 0 0 0
53549- 0 0 0 0 0 0 0 0 0 0 0 0
53550- 0 0 0 0 0 0 0 0 0 0 0 0
53551- 0 0 0 0 0 0 0 0 0 0 0 0
53552- 0 0 0 0 0 0 0 0 0 0 0 0
53553- 0 0 0 0 0 0 0 0 0 0 0 0
53554- 0 0 0 0 0 0 0 0 0 0 0 0
53555- 0 0 0 6 6 6 14 14 14 42 42 42
53556- 90 90 90 18 18 18 18 18 18 26 26 26
53557- 2 2 6 116 116 116 253 253 253 253 253 253
53558-253 253 253 253 253 253 253 253 253 253 253 253
53559-253 253 253 253 253 253 250 250 250 238 238 238
53560-253 253 253 253 253 253 253 253 253 253 253 253
53561-253 253 253 253 253 253 253 253 253 253 253 253
53562-253 253 253 253 253 253 253 253 253 253 253 253
53563-253 253 253 253 253 253 253 253 253 253 253 253
53564-253 253 253 253 253 253 94 94 94 6 6 6
53565- 2 2 6 2 2 6 10 10 10 34 34 34
53566- 2 2 6 2 2 6 2 2 6 2 2 6
53567- 74 74 74 58 58 58 22 22 22 6 6 6
53568- 0 0 0 0 0 0 0 0 0 0 0 0
53569- 0 0 0 0 0 0 0 0 0 0 0 0
53570- 0 0 0 0 0 0 0 0 0 0 0 0
53571- 0 0 0 0 0 0 0 0 0 0 0 0
53572- 0 0 0 0 0 0 0 0 0 0 0 0
53573- 0 0 0 0 0 0 0 0 0 0 0 0
53574- 0 0 0 0 0 0 0 0 0 0 0 0
53575- 0 0 0 10 10 10 26 26 26 66 66 66
53576- 82 82 82 2 2 6 38 38 38 6 6 6
53577- 14 14 14 210 210 210 253 253 253 253 253 253
53578-253 253 253 253 253 253 253 253 253 253 253 253
53579-253 253 253 253 253 253 246 246 246 242 242 242
53580-253 253 253 253 253 253 253 253 253 253 253 253
53581-253 253 253 253 253 253 253 253 253 253 253 253
53582-253 253 253 253 253 253 253 253 253 253 253 253
53583-253 253 253 253 253 253 253 253 253 253 253 253
53584-253 253 253 253 253 253 144 144 144 2 2 6
53585- 2 2 6 2 2 6 2 2 6 46 46 46
53586- 2 2 6 2 2 6 2 2 6 2 2 6
53587- 42 42 42 74 74 74 30 30 30 10 10 10
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 0 0 0
53593- 0 0 0 0 0 0 0 0 0 0 0 0
53594- 0 0 0 0 0 0 0 0 0 0 0 0
53595- 6 6 6 14 14 14 42 42 42 90 90 90
53596- 26 26 26 6 6 6 42 42 42 2 2 6
53597- 74 74 74 250 250 250 253 253 253 253 253 253
53598-253 253 253 253 253 253 253 253 253 253 253 253
53599-253 253 253 253 253 253 242 242 242 242 242 242
53600-253 253 253 253 253 253 253 253 253 253 253 253
53601-253 253 253 253 253 253 253 253 253 253 253 253
53602-253 253 253 253 253 253 253 253 253 253 253 253
53603-253 253 253 253 253 253 253 253 253 253 253 253
53604-253 253 253 253 253 253 182 182 182 2 2 6
53605- 2 2 6 2 2 6 2 2 6 46 46 46
53606- 2 2 6 2 2 6 2 2 6 2 2 6
53607- 10 10 10 86 86 86 38 38 38 10 10 10
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 0 0 0 0 0 0 0
53611- 0 0 0 0 0 0 0 0 0 0 0 0
53612- 0 0 0 0 0 0 0 0 0 0 0 0
53613- 0 0 0 0 0 0 0 0 0 0 0 0
53614- 0 0 0 0 0 0 0 0 0 0 0 0
53615- 10 10 10 26 26 26 66 66 66 82 82 82
53616- 2 2 6 22 22 22 18 18 18 2 2 6
53617-149 149 149 253 253 253 253 253 253 253 253 253
53618-253 253 253 253 253 253 253 253 253 253 253 253
53619-253 253 253 253 253 253 234 234 234 242 242 242
53620-253 253 253 253 253 253 253 253 253 253 253 253
53621-253 253 253 253 253 253 253 253 253 253 253 253
53622-253 253 253 253 253 253 253 253 253 253 253 253
53623-253 253 253 253 253 253 253 253 253 253 253 253
53624-253 253 253 253 253 253 206 206 206 2 2 6
53625- 2 2 6 2 2 6 2 2 6 38 38 38
53626- 2 2 6 2 2 6 2 2 6 2 2 6
53627- 6 6 6 86 86 86 46 46 46 14 14 14
53628- 0 0 0 0 0 0 0 0 0 0 0 0
53629- 0 0 0 0 0 0 0 0 0 0 0 0
53630- 0 0 0 0 0 0 0 0 0 0 0 0
53631- 0 0 0 0 0 0 0 0 0 0 0 0
53632- 0 0 0 0 0 0 0 0 0 0 0 0
53633- 0 0 0 0 0 0 0 0 0 0 0 0
53634- 0 0 0 0 0 0 0 0 0 6 6 6
53635- 18 18 18 46 46 46 86 86 86 18 18 18
53636- 2 2 6 34 34 34 10 10 10 6 6 6
53637-210 210 210 253 253 253 253 253 253 253 253 253
53638-253 253 253 253 253 253 253 253 253 253 253 253
53639-253 253 253 253 253 253 234 234 234 242 242 242
53640-253 253 253 253 253 253 253 253 253 253 253 253
53641-253 253 253 253 253 253 253 253 253 253 253 253
53642-253 253 253 253 253 253 253 253 253 253 253 253
53643-253 253 253 253 253 253 253 253 253 253 253 253
53644-253 253 253 253 253 253 221 221 221 6 6 6
53645- 2 2 6 2 2 6 6 6 6 30 30 30
53646- 2 2 6 2 2 6 2 2 6 2 2 6
53647- 2 2 6 82 82 82 54 54 54 18 18 18
53648- 6 6 6 0 0 0 0 0 0 0 0 0
53649- 0 0 0 0 0 0 0 0 0 0 0 0
53650- 0 0 0 0 0 0 0 0 0 0 0 0
53651- 0 0 0 0 0 0 0 0 0 0 0 0
53652- 0 0 0 0 0 0 0 0 0 0 0 0
53653- 0 0 0 0 0 0 0 0 0 0 0 0
53654- 0 0 0 0 0 0 0 0 0 10 10 10
53655- 26 26 26 66 66 66 62 62 62 2 2 6
53656- 2 2 6 38 38 38 10 10 10 26 26 26
53657-238 238 238 253 253 253 253 253 253 253 253 253
53658-253 253 253 253 253 253 253 253 253 253 253 253
53659-253 253 253 253 253 253 231 231 231 238 238 238
53660-253 253 253 253 253 253 253 253 253 253 253 253
53661-253 253 253 253 253 253 253 253 253 253 253 253
53662-253 253 253 253 253 253 253 253 253 253 253 253
53663-253 253 253 253 253 253 253 253 253 253 253 253
53664-253 253 253 253 253 253 231 231 231 6 6 6
53665- 2 2 6 2 2 6 10 10 10 30 30 30
53666- 2 2 6 2 2 6 2 2 6 2 2 6
53667- 2 2 6 66 66 66 58 58 58 22 22 22
53668- 6 6 6 0 0 0 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 10 10 10
53675- 38 38 38 78 78 78 6 6 6 2 2 6
53676- 2 2 6 46 46 46 14 14 14 42 42 42
53677-246 246 246 253 253 253 253 253 253 253 253 253
53678-253 253 253 253 253 253 253 253 253 253 253 253
53679-253 253 253 253 253 253 231 231 231 242 242 242
53680-253 253 253 253 253 253 253 253 253 253 253 253
53681-253 253 253 253 253 253 253 253 253 253 253 253
53682-253 253 253 253 253 253 253 253 253 253 253 253
53683-253 253 253 253 253 253 253 253 253 253 253 253
53684-253 253 253 253 253 253 234 234 234 10 10 10
53685- 2 2 6 2 2 6 22 22 22 14 14 14
53686- 2 2 6 2 2 6 2 2 6 2 2 6
53687- 2 2 6 66 66 66 62 62 62 22 22 22
53688- 6 6 6 0 0 0 0 0 0 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 0 0 0 0 0 0 0 0 0 0
53691- 0 0 0 0 0 0 0 0 0 0 0 0
53692- 0 0 0 0 0 0 0 0 0 0 0 0
53693- 0 0 0 0 0 0 0 0 0 0 0 0
53694- 0 0 0 0 0 0 6 6 6 18 18 18
53695- 50 50 50 74 74 74 2 2 6 2 2 6
53696- 14 14 14 70 70 70 34 34 34 62 62 62
53697-250 250 250 253 253 253 253 253 253 253 253 253
53698-253 253 253 253 253 253 253 253 253 253 253 253
53699-253 253 253 253 253 253 231 231 231 246 246 246
53700-253 253 253 253 253 253 253 253 253 253 253 253
53701-253 253 253 253 253 253 253 253 253 253 253 253
53702-253 253 253 253 253 253 253 253 253 253 253 253
53703-253 253 253 253 253 253 253 253 253 253 253 253
53704-253 253 253 253 253 253 234 234 234 14 14 14
53705- 2 2 6 2 2 6 30 30 30 2 2 6
53706- 2 2 6 2 2 6 2 2 6 2 2 6
53707- 2 2 6 66 66 66 62 62 62 22 22 22
53708- 6 6 6 0 0 0 0 0 0 0 0 0
53709- 0 0 0 0 0 0 0 0 0 0 0 0
53710- 0 0 0 0 0 0 0 0 0 0 0 0
53711- 0 0 0 0 0 0 0 0 0 0 0 0
53712- 0 0 0 0 0 0 0 0 0 0 0 0
53713- 0 0 0 0 0 0 0 0 0 0 0 0
53714- 0 0 0 0 0 0 6 6 6 18 18 18
53715- 54 54 54 62 62 62 2 2 6 2 2 6
53716- 2 2 6 30 30 30 46 46 46 70 70 70
53717-250 250 250 253 253 253 253 253 253 253 253 253
53718-253 253 253 253 253 253 253 253 253 253 253 253
53719-253 253 253 253 253 253 231 231 231 246 246 246
53720-253 253 253 253 253 253 253 253 253 253 253 253
53721-253 253 253 253 253 253 253 253 253 253 253 253
53722-253 253 253 253 253 253 253 253 253 253 253 253
53723-253 253 253 253 253 253 253 253 253 253 253 253
53724-253 253 253 253 253 253 226 226 226 10 10 10
53725- 2 2 6 6 6 6 30 30 30 2 2 6
53726- 2 2 6 2 2 6 2 2 6 2 2 6
53727- 2 2 6 66 66 66 58 58 58 22 22 22
53728- 6 6 6 0 0 0 0 0 0 0 0 0
53729- 0 0 0 0 0 0 0 0 0 0 0 0
53730- 0 0 0 0 0 0 0 0 0 0 0 0
53731- 0 0 0 0 0 0 0 0 0 0 0 0
53732- 0 0 0 0 0 0 0 0 0 0 0 0
53733- 0 0 0 0 0 0 0 0 0 0 0 0
53734- 0 0 0 0 0 0 6 6 6 22 22 22
53735- 58 58 58 62 62 62 2 2 6 2 2 6
53736- 2 2 6 2 2 6 30 30 30 78 78 78
53737-250 250 250 253 253 253 253 253 253 253 253 253
53738-253 253 253 253 253 253 253 253 253 253 253 253
53739-253 253 253 253 253 253 231 231 231 246 246 246
53740-253 253 253 253 253 253 253 253 253 253 253 253
53741-253 253 253 253 253 253 253 253 253 253 253 253
53742-253 253 253 253 253 253 253 253 253 253 253 253
53743-253 253 253 253 253 253 253 253 253 253 253 253
53744-253 253 253 253 253 253 206 206 206 2 2 6
53745- 22 22 22 34 34 34 18 14 6 22 22 22
53746- 26 26 26 18 18 18 6 6 6 2 2 6
53747- 2 2 6 82 82 82 54 54 54 18 18 18
53748- 6 6 6 0 0 0 0 0 0 0 0 0
53749- 0 0 0 0 0 0 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 0 0 0 0 0 0 0 0 0 0 0 0
53754- 0 0 0 0 0 0 6 6 6 26 26 26
53755- 62 62 62 106 106 106 74 54 14 185 133 11
53756-210 162 10 121 92 8 6 6 6 62 62 62
53757-238 238 238 253 253 253 253 253 253 253 253 253
53758-253 253 253 253 253 253 253 253 253 253 253 253
53759-253 253 253 253 253 253 231 231 231 246 246 246
53760-253 253 253 253 253 253 253 253 253 253 253 253
53761-253 253 253 253 253 253 253 253 253 253 253 253
53762-253 253 253 253 253 253 253 253 253 253 253 253
53763-253 253 253 253 253 253 253 253 253 253 253 253
53764-253 253 253 253 253 253 158 158 158 18 18 18
53765- 14 14 14 2 2 6 2 2 6 2 2 6
53766- 6 6 6 18 18 18 66 66 66 38 38 38
53767- 6 6 6 94 94 94 50 50 50 18 18 18
53768- 6 6 6 0 0 0 0 0 0 0 0 0
53769- 0 0 0 0 0 0 0 0 0 0 0 0
53770- 0 0 0 0 0 0 0 0 0 0 0 0
53771- 0 0 0 0 0 0 0 0 0 0 0 0
53772- 0 0 0 0 0 0 0 0 0 0 0 0
53773- 0 0 0 0 0 0 0 0 0 6 6 6
53774- 10 10 10 10 10 10 18 18 18 38 38 38
53775- 78 78 78 142 134 106 216 158 10 242 186 14
53776-246 190 14 246 190 14 156 118 10 10 10 10
53777- 90 90 90 238 238 238 253 253 253 253 253 253
53778-253 253 253 253 253 253 253 253 253 253 253 253
53779-253 253 253 253 253 253 231 231 231 250 250 250
53780-253 253 253 253 253 253 253 253 253 253 253 253
53781-253 253 253 253 253 253 253 253 253 253 253 253
53782-253 253 253 253 253 253 253 253 253 253 253 253
53783-253 253 253 253 253 253 253 253 253 246 230 190
53784-238 204 91 238 204 91 181 142 44 37 26 9
53785- 2 2 6 2 2 6 2 2 6 2 2 6
53786- 2 2 6 2 2 6 38 38 38 46 46 46
53787- 26 26 26 106 106 106 54 54 54 18 18 18
53788- 6 6 6 0 0 0 0 0 0 0 0 0
53789- 0 0 0 0 0 0 0 0 0 0 0 0
53790- 0 0 0 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 0 0 0 0 0 0
53793- 0 0 0 6 6 6 14 14 14 22 22 22
53794- 30 30 30 38 38 38 50 50 50 70 70 70
53795-106 106 106 190 142 34 226 170 11 242 186 14
53796-246 190 14 246 190 14 246 190 14 154 114 10
53797- 6 6 6 74 74 74 226 226 226 253 253 253
53798-253 253 253 253 253 253 253 253 253 253 253 253
53799-253 253 253 253 253 253 231 231 231 250 250 250
53800-253 253 253 253 253 253 253 253 253 253 253 253
53801-253 253 253 253 253 253 253 253 253 253 253 253
53802-253 253 253 253 253 253 253 253 253 253 253 253
53803-253 253 253 253 253 253 253 253 253 228 184 62
53804-241 196 14 241 208 19 232 195 16 38 30 10
53805- 2 2 6 2 2 6 2 2 6 2 2 6
53806- 2 2 6 6 6 6 30 30 30 26 26 26
53807-203 166 17 154 142 90 66 66 66 26 26 26
53808- 6 6 6 0 0 0 0 0 0 0 0 0
53809- 0 0 0 0 0 0 0 0 0 0 0 0
53810- 0 0 0 0 0 0 0 0 0 0 0 0
53811- 0 0 0 0 0 0 0 0 0 0 0 0
53812- 0 0 0 0 0 0 0 0 0 0 0 0
53813- 6 6 6 18 18 18 38 38 38 58 58 58
53814- 78 78 78 86 86 86 101 101 101 123 123 123
53815-175 146 61 210 150 10 234 174 13 246 186 14
53816-246 190 14 246 190 14 246 190 14 238 190 10
53817-102 78 10 2 2 6 46 46 46 198 198 198
53818-253 253 253 253 253 253 253 253 253 253 253 253
53819-253 253 253 253 253 253 234 234 234 242 242 242
53820-253 253 253 253 253 253 253 253 253 253 253 253
53821-253 253 253 253 253 253 253 253 253 253 253 253
53822-253 253 253 253 253 253 253 253 253 253 253 253
53823-253 253 253 253 253 253 253 253 253 224 178 62
53824-242 186 14 241 196 14 210 166 10 22 18 6
53825- 2 2 6 2 2 6 2 2 6 2 2 6
53826- 2 2 6 2 2 6 6 6 6 121 92 8
53827-238 202 15 232 195 16 82 82 82 34 34 34
53828- 10 10 10 0 0 0 0 0 0 0 0 0
53829- 0 0 0 0 0 0 0 0 0 0 0 0
53830- 0 0 0 0 0 0 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 0 0 0
53833- 14 14 14 38 38 38 70 70 70 154 122 46
53834-190 142 34 200 144 11 197 138 11 197 138 11
53835-213 154 11 226 170 11 242 186 14 246 190 14
53836-246 190 14 246 190 14 246 190 14 246 190 14
53837-225 175 15 46 32 6 2 2 6 22 22 22
53838-158 158 158 250 250 250 253 253 253 253 253 253
53839-253 253 253 253 253 253 253 253 253 253 253 253
53840-253 253 253 253 253 253 253 253 253 253 253 253
53841-253 253 253 253 253 253 253 253 253 253 253 253
53842-253 253 253 253 253 253 253 253 253 253 253 253
53843-253 253 253 250 250 250 242 242 242 224 178 62
53844-239 182 13 236 186 11 213 154 11 46 32 6
53845- 2 2 6 2 2 6 2 2 6 2 2 6
53846- 2 2 6 2 2 6 61 42 6 225 175 15
53847-238 190 10 236 186 11 112 100 78 42 42 42
53848- 14 14 14 0 0 0 0 0 0 0 0 0
53849- 0 0 0 0 0 0 0 0 0 0 0 0
53850- 0 0 0 0 0 0 0 0 0 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 0 0 0 6 6 6
53853- 22 22 22 54 54 54 154 122 46 213 154 11
53854-226 170 11 230 174 11 226 170 11 226 170 11
53855-236 178 12 242 186 14 246 190 14 246 190 14
53856-246 190 14 246 190 14 246 190 14 246 190 14
53857-241 196 14 184 144 12 10 10 10 2 2 6
53858- 6 6 6 116 116 116 242 242 242 253 253 253
53859-253 253 253 253 253 253 253 253 253 253 253 253
53860-253 253 253 253 253 253 253 253 253 253 253 253
53861-253 253 253 253 253 253 253 253 253 253 253 253
53862-253 253 253 253 253 253 253 253 253 253 253 253
53863-253 253 253 231 231 231 198 198 198 214 170 54
53864-236 178 12 236 178 12 210 150 10 137 92 6
53865- 18 14 6 2 2 6 2 2 6 2 2 6
53866- 6 6 6 70 47 6 200 144 11 236 178 12
53867-239 182 13 239 182 13 124 112 88 58 58 58
53868- 22 22 22 6 6 6 0 0 0 0 0 0
53869- 0 0 0 0 0 0 0 0 0 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 10 10 10
53873- 30 30 30 70 70 70 180 133 36 226 170 11
53874-239 182 13 242 186 14 242 186 14 246 186 14
53875-246 190 14 246 190 14 246 190 14 246 190 14
53876-246 190 14 246 190 14 246 190 14 246 190 14
53877-246 190 14 232 195 16 98 70 6 2 2 6
53878- 2 2 6 2 2 6 66 66 66 221 221 221
53879-253 253 253 253 253 253 253 253 253 253 253 253
53880-253 253 253 253 253 253 253 253 253 253 253 253
53881-253 253 253 253 253 253 253 253 253 253 253 253
53882-253 253 253 253 253 253 253 253 253 253 253 253
53883-253 253 253 206 206 206 198 198 198 214 166 58
53884-230 174 11 230 174 11 216 158 10 192 133 9
53885-163 110 8 116 81 8 102 78 10 116 81 8
53886-167 114 7 197 138 11 226 170 11 239 182 13
53887-242 186 14 242 186 14 162 146 94 78 78 78
53888- 34 34 34 14 14 14 6 6 6 0 0 0
53889- 0 0 0 0 0 0 0 0 0 0 0 0
53890- 0 0 0 0 0 0 0 0 0 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 0 0 0 0 0 0 6 6 6
53893- 30 30 30 78 78 78 190 142 34 226 170 11
53894-239 182 13 246 190 14 246 190 14 246 190 14
53895-246 190 14 246 190 14 246 190 14 246 190 14
53896-246 190 14 246 190 14 246 190 14 246 190 14
53897-246 190 14 241 196 14 203 166 17 22 18 6
53898- 2 2 6 2 2 6 2 2 6 38 38 38
53899-218 218 218 253 253 253 253 253 253 253 253 253
53900-253 253 253 253 253 253 253 253 253 253 253 253
53901-253 253 253 253 253 253 253 253 253 253 253 253
53902-253 253 253 253 253 253 253 253 253 253 253 253
53903-250 250 250 206 206 206 198 198 198 202 162 69
53904-226 170 11 236 178 12 224 166 10 210 150 10
53905-200 144 11 197 138 11 192 133 9 197 138 11
53906-210 150 10 226 170 11 242 186 14 246 190 14
53907-246 190 14 246 186 14 225 175 15 124 112 88
53908- 62 62 62 30 30 30 14 14 14 6 6 6
53909- 0 0 0 0 0 0 0 0 0 0 0 0
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 10 10 10
53913- 30 30 30 78 78 78 174 135 50 224 166 10
53914-239 182 13 246 190 14 246 190 14 246 190 14
53915-246 190 14 246 190 14 246 190 14 246 190 14
53916-246 190 14 246 190 14 246 190 14 246 190 14
53917-246 190 14 246 190 14 241 196 14 139 102 15
53918- 2 2 6 2 2 6 2 2 6 2 2 6
53919- 78 78 78 250 250 250 253 253 253 253 253 253
53920-253 253 253 253 253 253 253 253 253 253 253 253
53921-253 253 253 253 253 253 253 253 253 253 253 253
53922-253 253 253 253 253 253 253 253 253 253 253 253
53923-250 250 250 214 214 214 198 198 198 190 150 46
53924-219 162 10 236 178 12 234 174 13 224 166 10
53925-216 158 10 213 154 11 213 154 11 216 158 10
53926-226 170 11 239 182 13 246 190 14 246 190 14
53927-246 190 14 246 190 14 242 186 14 206 162 42
53928-101 101 101 58 58 58 30 30 30 14 14 14
53929- 6 6 6 0 0 0 0 0 0 0 0 0
53930- 0 0 0 0 0 0 0 0 0 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 0 0 0 0 0 0 0 0 0 10 10 10
53933- 30 30 30 74 74 74 174 135 50 216 158 10
53934-236 178 12 246 190 14 246 190 14 246 190 14
53935-246 190 14 246 190 14 246 190 14 246 190 14
53936-246 190 14 246 190 14 246 190 14 246 190 14
53937-246 190 14 246 190 14 241 196 14 226 184 13
53938- 61 42 6 2 2 6 2 2 6 2 2 6
53939- 22 22 22 238 238 238 253 253 253 253 253 253
53940-253 253 253 253 253 253 253 253 253 253 253 253
53941-253 253 253 253 253 253 253 253 253 253 253 253
53942-253 253 253 253 253 253 253 253 253 253 253 253
53943-253 253 253 226 226 226 187 187 187 180 133 36
53944-216 158 10 236 178 12 239 182 13 236 178 12
53945-230 174 11 226 170 11 226 170 11 230 174 11
53946-236 178 12 242 186 14 246 190 14 246 190 14
53947-246 190 14 246 190 14 246 186 14 239 182 13
53948-206 162 42 106 106 106 66 66 66 34 34 34
53949- 14 14 14 6 6 6 0 0 0 0 0 0
53950- 0 0 0 0 0 0 0 0 0 0 0 0
53951- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 0 0 0 0 0 0 0 0 0 6 6 6
53953- 26 26 26 70 70 70 163 133 67 213 154 11
53954-236 178 12 246 190 14 246 190 14 246 190 14
53955-246 190 14 246 190 14 246 190 14 246 190 14
53956-246 190 14 246 190 14 246 190 14 246 190 14
53957-246 190 14 246 190 14 246 190 14 241 196 14
53958-190 146 13 18 14 6 2 2 6 2 2 6
53959- 46 46 46 246 246 246 253 253 253 253 253 253
53960-253 253 253 253 253 253 253 253 253 253 253 253
53961-253 253 253 253 253 253 253 253 253 253 253 253
53962-253 253 253 253 253 253 253 253 253 253 253 253
53963-253 253 253 221 221 221 86 86 86 156 107 11
53964-216 158 10 236 178 12 242 186 14 246 186 14
53965-242 186 14 239 182 13 239 182 13 242 186 14
53966-242 186 14 246 186 14 246 190 14 246 190 14
53967-246 190 14 246 190 14 246 190 14 246 190 14
53968-242 186 14 225 175 15 142 122 72 66 66 66
53969- 30 30 30 10 10 10 0 0 0 0 0 0
53970- 0 0 0 0 0 0 0 0 0 0 0 0
53971- 0 0 0 0 0 0 0 0 0 0 0 0
53972- 0 0 0 0 0 0 0 0 0 6 6 6
53973- 26 26 26 70 70 70 163 133 67 210 150 10
53974-236 178 12 246 190 14 246 190 14 246 190 14
53975-246 190 14 246 190 14 246 190 14 246 190 14
53976-246 190 14 246 190 14 246 190 14 246 190 14
53977-246 190 14 246 190 14 246 190 14 246 190 14
53978-232 195 16 121 92 8 34 34 34 106 106 106
53979-221 221 221 253 253 253 253 253 253 253 253 253
53980-253 253 253 253 253 253 253 253 253 253 253 253
53981-253 253 253 253 253 253 253 253 253 253 253 253
53982-253 253 253 253 253 253 253 253 253 253 253 253
53983-242 242 242 82 82 82 18 14 6 163 110 8
53984-216 158 10 236 178 12 242 186 14 246 190 14
53985-246 190 14 246 190 14 246 190 14 246 190 14
53986-246 190 14 246 190 14 246 190 14 246 190 14
53987-246 190 14 246 190 14 246 190 14 246 190 14
53988-246 190 14 246 190 14 242 186 14 163 133 67
53989- 46 46 46 18 18 18 6 6 6 0 0 0
53990- 0 0 0 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 0 0 0
53992- 0 0 0 0 0 0 0 0 0 10 10 10
53993- 30 30 30 78 78 78 163 133 67 210 150 10
53994-236 178 12 246 186 14 246 190 14 246 190 14
53995-246 190 14 246 190 14 246 190 14 246 190 14
53996-246 190 14 246 190 14 246 190 14 246 190 14
53997-246 190 14 246 190 14 246 190 14 246 190 14
53998-241 196 14 215 174 15 190 178 144 253 253 253
53999-253 253 253 253 253 253 253 253 253 253 253 253
54000-253 253 253 253 253 253 253 253 253 253 253 253
54001-253 253 253 253 253 253 253 253 253 253 253 253
54002-253 253 253 253 253 253 253 253 253 218 218 218
54003- 58 58 58 2 2 6 22 18 6 167 114 7
54004-216 158 10 236 178 12 246 186 14 246 190 14
54005-246 190 14 246 190 14 246 190 14 246 190 14
54006-246 190 14 246 190 14 246 190 14 246 190 14
54007-246 190 14 246 190 14 246 190 14 246 190 14
54008-246 190 14 246 186 14 242 186 14 190 150 46
54009- 54 54 54 22 22 22 6 6 6 0 0 0
54010- 0 0 0 0 0 0 0 0 0 0 0 0
54011- 0 0 0 0 0 0 0 0 0 0 0 0
54012- 0 0 0 0 0 0 0 0 0 14 14 14
54013- 38 38 38 86 86 86 180 133 36 213 154 11
54014-236 178 12 246 186 14 246 190 14 246 190 14
54015-246 190 14 246 190 14 246 190 14 246 190 14
54016-246 190 14 246 190 14 246 190 14 246 190 14
54017-246 190 14 246 190 14 246 190 14 246 190 14
54018-246 190 14 232 195 16 190 146 13 214 214 214
54019-253 253 253 253 253 253 253 253 253 253 253 253
54020-253 253 253 253 253 253 253 253 253 253 253 253
54021-253 253 253 253 253 253 253 253 253 253 253 253
54022-253 253 253 250 250 250 170 170 170 26 26 26
54023- 2 2 6 2 2 6 37 26 9 163 110 8
54024-219 162 10 239 182 13 246 186 14 246 190 14
54025-246 190 14 246 190 14 246 190 14 246 190 14
54026-246 190 14 246 190 14 246 190 14 246 190 14
54027-246 190 14 246 190 14 246 190 14 246 190 14
54028-246 186 14 236 178 12 224 166 10 142 122 72
54029- 46 46 46 18 18 18 6 6 6 0 0 0
54030- 0 0 0 0 0 0 0 0 0 0 0 0
54031- 0 0 0 0 0 0 0 0 0 0 0 0
54032- 0 0 0 0 0 0 6 6 6 18 18 18
54033- 50 50 50 109 106 95 192 133 9 224 166 10
54034-242 186 14 246 190 14 246 190 14 246 190 14
54035-246 190 14 246 190 14 246 190 14 246 190 14
54036-246 190 14 246 190 14 246 190 14 246 190 14
54037-246 190 14 246 190 14 246 190 14 246 190 14
54038-242 186 14 226 184 13 210 162 10 142 110 46
54039-226 226 226 253 253 253 253 253 253 253 253 253
54040-253 253 253 253 253 253 253 253 253 253 253 253
54041-253 253 253 253 253 253 253 253 253 253 253 253
54042-198 198 198 66 66 66 2 2 6 2 2 6
54043- 2 2 6 2 2 6 50 34 6 156 107 11
54044-219 162 10 239 182 13 246 186 14 246 190 14
54045-246 190 14 246 190 14 246 190 14 246 190 14
54046-246 190 14 246 190 14 246 190 14 246 190 14
54047-246 190 14 246 190 14 246 190 14 242 186 14
54048-234 174 13 213 154 11 154 122 46 66 66 66
54049- 30 30 30 10 10 10 0 0 0 0 0 0
54050- 0 0 0 0 0 0 0 0 0 0 0 0
54051- 0 0 0 0 0 0 0 0 0 0 0 0
54052- 0 0 0 0 0 0 6 6 6 22 22 22
54053- 58 58 58 154 121 60 206 145 10 234 174 13
54054-242 186 14 246 186 14 246 190 14 246 190 14
54055-246 190 14 246 190 14 246 190 14 246 190 14
54056-246 190 14 246 190 14 246 190 14 246 190 14
54057-246 190 14 246 190 14 246 190 14 246 190 14
54058-246 186 14 236 178 12 210 162 10 163 110 8
54059- 61 42 6 138 138 138 218 218 218 250 250 250
54060-253 253 253 253 253 253 253 253 253 250 250 250
54061-242 242 242 210 210 210 144 144 144 66 66 66
54062- 6 6 6 2 2 6 2 2 6 2 2 6
54063- 2 2 6 2 2 6 61 42 6 163 110 8
54064-216 158 10 236 178 12 246 190 14 246 190 14
54065-246 190 14 246 190 14 246 190 14 246 190 14
54066-246 190 14 246 190 14 246 190 14 246 190 14
54067-246 190 14 239 182 13 230 174 11 216 158 10
54068-190 142 34 124 112 88 70 70 70 38 38 38
54069- 18 18 18 6 6 6 0 0 0 0 0 0
54070- 0 0 0 0 0 0 0 0 0 0 0 0
54071- 0 0 0 0 0 0 0 0 0 0 0 0
54072- 0 0 0 0 0 0 6 6 6 22 22 22
54073- 62 62 62 168 124 44 206 145 10 224 166 10
54074-236 178 12 239 182 13 242 186 14 242 186 14
54075-246 186 14 246 190 14 246 190 14 246 190 14
54076-246 190 14 246 190 14 246 190 14 246 190 14
54077-246 190 14 246 190 14 246 190 14 246 190 14
54078-246 190 14 236 178 12 216 158 10 175 118 6
54079- 80 54 7 2 2 6 6 6 6 30 30 30
54080- 54 54 54 62 62 62 50 50 50 38 38 38
54081- 14 14 14 2 2 6 2 2 6 2 2 6
54082- 2 2 6 2 2 6 2 2 6 2 2 6
54083- 2 2 6 6 6 6 80 54 7 167 114 7
54084-213 154 11 236 178 12 246 190 14 246 190 14
54085-246 190 14 246 190 14 246 190 14 246 190 14
54086-246 190 14 242 186 14 239 182 13 239 182 13
54087-230 174 11 210 150 10 174 135 50 124 112 88
54088- 82 82 82 54 54 54 34 34 34 18 18 18
54089- 6 6 6 0 0 0 0 0 0 0 0 0
54090- 0 0 0 0 0 0 0 0 0 0 0 0
54091- 0 0 0 0 0 0 0 0 0 0 0 0
54092- 0 0 0 0 0 0 6 6 6 18 18 18
54093- 50 50 50 158 118 36 192 133 9 200 144 11
54094-216 158 10 219 162 10 224 166 10 226 170 11
54095-230 174 11 236 178 12 239 182 13 239 182 13
54096-242 186 14 246 186 14 246 190 14 246 190 14
54097-246 190 14 246 190 14 246 190 14 246 190 14
54098-246 186 14 230 174 11 210 150 10 163 110 8
54099-104 69 6 10 10 10 2 2 6 2 2 6
54100- 2 2 6 2 2 6 2 2 6 2 2 6
54101- 2 2 6 2 2 6 2 2 6 2 2 6
54102- 2 2 6 2 2 6 2 2 6 2 2 6
54103- 2 2 6 6 6 6 91 60 6 167 114 7
54104-206 145 10 230 174 11 242 186 14 246 190 14
54105-246 190 14 246 190 14 246 186 14 242 186 14
54106-239 182 13 230 174 11 224 166 10 213 154 11
54107-180 133 36 124 112 88 86 86 86 58 58 58
54108- 38 38 38 22 22 22 10 10 10 6 6 6
54109- 0 0 0 0 0 0 0 0 0 0 0 0
54110- 0 0 0 0 0 0 0 0 0 0 0 0
54111- 0 0 0 0 0 0 0 0 0 0 0 0
54112- 0 0 0 0 0 0 0 0 0 14 14 14
54113- 34 34 34 70 70 70 138 110 50 158 118 36
54114-167 114 7 180 123 7 192 133 9 197 138 11
54115-200 144 11 206 145 10 213 154 11 219 162 10
54116-224 166 10 230 174 11 239 182 13 242 186 14
54117-246 186 14 246 186 14 246 186 14 246 186 14
54118-239 182 13 216 158 10 185 133 11 152 99 6
54119-104 69 6 18 14 6 2 2 6 2 2 6
54120- 2 2 6 2 2 6 2 2 6 2 2 6
54121- 2 2 6 2 2 6 2 2 6 2 2 6
54122- 2 2 6 2 2 6 2 2 6 2 2 6
54123- 2 2 6 6 6 6 80 54 7 152 99 6
54124-192 133 9 219 162 10 236 178 12 239 182 13
54125-246 186 14 242 186 14 239 182 13 236 178 12
54126-224 166 10 206 145 10 192 133 9 154 121 60
54127- 94 94 94 62 62 62 42 42 42 22 22 22
54128- 14 14 14 6 6 6 0 0 0 0 0 0
54129- 0 0 0 0 0 0 0 0 0 0 0 0
54130- 0 0 0 0 0 0 0 0 0 0 0 0
54131- 0 0 0 0 0 0 0 0 0 0 0 0
54132- 0 0 0 0 0 0 0 0 0 6 6 6
54133- 18 18 18 34 34 34 58 58 58 78 78 78
54134-101 98 89 124 112 88 142 110 46 156 107 11
54135-163 110 8 167 114 7 175 118 6 180 123 7
54136-185 133 11 197 138 11 210 150 10 219 162 10
54137-226 170 11 236 178 12 236 178 12 234 174 13
54138-219 162 10 197 138 11 163 110 8 130 83 6
54139- 91 60 6 10 10 10 2 2 6 2 2 6
54140- 18 18 18 38 38 38 38 38 38 38 38 38
54141- 38 38 38 38 38 38 38 38 38 38 38 38
54142- 38 38 38 38 38 38 26 26 26 2 2 6
54143- 2 2 6 6 6 6 70 47 6 137 92 6
54144-175 118 6 200 144 11 219 162 10 230 174 11
54145-234 174 13 230 174 11 219 162 10 210 150 10
54146-192 133 9 163 110 8 124 112 88 82 82 82
54147- 50 50 50 30 30 30 14 14 14 6 6 6
54148- 0 0 0 0 0 0 0 0 0 0 0 0
54149- 0 0 0 0 0 0 0 0 0 0 0 0
54150- 0 0 0 0 0 0 0 0 0 0 0 0
54151- 0 0 0 0 0 0 0 0 0 0 0 0
54152- 0 0 0 0 0 0 0 0 0 0 0 0
54153- 6 6 6 14 14 14 22 22 22 34 34 34
54154- 42 42 42 58 58 58 74 74 74 86 86 86
54155-101 98 89 122 102 70 130 98 46 121 87 25
54156-137 92 6 152 99 6 163 110 8 180 123 7
54157-185 133 11 197 138 11 206 145 10 200 144 11
54158-180 123 7 156 107 11 130 83 6 104 69 6
54159- 50 34 6 54 54 54 110 110 110 101 98 89
54160- 86 86 86 82 82 82 78 78 78 78 78 78
54161- 78 78 78 78 78 78 78 78 78 78 78 78
54162- 78 78 78 82 82 82 86 86 86 94 94 94
54163-106 106 106 101 101 101 86 66 34 124 80 6
54164-156 107 11 180 123 7 192 133 9 200 144 11
54165-206 145 10 200 144 11 192 133 9 175 118 6
54166-139 102 15 109 106 95 70 70 70 42 42 42
54167- 22 22 22 10 10 10 0 0 0 0 0 0
54168- 0 0 0 0 0 0 0 0 0 0 0 0
54169- 0 0 0 0 0 0 0 0 0 0 0 0
54170- 0 0 0 0 0 0 0 0 0 0 0 0
54171- 0 0 0 0 0 0 0 0 0 0 0 0
54172- 0 0 0 0 0 0 0 0 0 0 0 0
54173- 0 0 0 0 0 0 6 6 6 10 10 10
54174- 14 14 14 22 22 22 30 30 30 38 38 38
54175- 50 50 50 62 62 62 74 74 74 90 90 90
54176-101 98 89 112 100 78 121 87 25 124 80 6
54177-137 92 6 152 99 6 152 99 6 152 99 6
54178-138 86 6 124 80 6 98 70 6 86 66 30
54179-101 98 89 82 82 82 58 58 58 46 46 46
54180- 38 38 38 34 34 34 34 34 34 34 34 34
54181- 34 34 34 34 34 34 34 34 34 34 34 34
54182- 34 34 34 34 34 34 38 38 38 42 42 42
54183- 54 54 54 82 82 82 94 86 76 91 60 6
54184-134 86 6 156 107 11 167 114 7 175 118 6
54185-175 118 6 167 114 7 152 99 6 121 87 25
54186-101 98 89 62 62 62 34 34 34 18 18 18
54187- 6 6 6 0 0 0 0 0 0 0 0 0
54188- 0 0 0 0 0 0 0 0 0 0 0 0
54189- 0 0 0 0 0 0 0 0 0 0 0 0
54190- 0 0 0 0 0 0 0 0 0 0 0 0
54191- 0 0 0 0 0 0 0 0 0 0 0 0
54192- 0 0 0 0 0 0 0 0 0 0 0 0
54193- 0 0 0 0 0 0 0 0 0 0 0 0
54194- 0 0 0 6 6 6 6 6 6 10 10 10
54195- 18 18 18 22 22 22 30 30 30 42 42 42
54196- 50 50 50 66 66 66 86 86 86 101 98 89
54197-106 86 58 98 70 6 104 69 6 104 69 6
54198-104 69 6 91 60 6 82 62 34 90 90 90
54199- 62 62 62 38 38 38 22 22 22 14 14 14
54200- 10 10 10 10 10 10 10 10 10 10 10 10
54201- 10 10 10 10 10 10 6 6 6 10 10 10
54202- 10 10 10 10 10 10 10 10 10 14 14 14
54203- 22 22 22 42 42 42 70 70 70 89 81 66
54204- 80 54 7 104 69 6 124 80 6 137 92 6
54205-134 86 6 116 81 8 100 82 52 86 86 86
54206- 58 58 58 30 30 30 14 14 14 6 6 6
54207- 0 0 0 0 0 0 0 0 0 0 0 0
54208- 0 0 0 0 0 0 0 0 0 0 0 0
54209- 0 0 0 0 0 0 0 0 0 0 0 0
54210- 0 0 0 0 0 0 0 0 0 0 0 0
54211- 0 0 0 0 0 0 0 0 0 0 0 0
54212- 0 0 0 0 0 0 0 0 0 0 0 0
54213- 0 0 0 0 0 0 0 0 0 0 0 0
54214- 0 0 0 0 0 0 0 0 0 0 0 0
54215- 0 0 0 6 6 6 10 10 10 14 14 14
54216- 18 18 18 26 26 26 38 38 38 54 54 54
54217- 70 70 70 86 86 86 94 86 76 89 81 66
54218- 89 81 66 86 86 86 74 74 74 50 50 50
54219- 30 30 30 14 14 14 6 6 6 0 0 0
54220- 0 0 0 0 0 0 0 0 0 0 0 0
54221- 0 0 0 0 0 0 0 0 0 0 0 0
54222- 0 0 0 0 0 0 0 0 0 0 0 0
54223- 6 6 6 18 18 18 34 34 34 58 58 58
54224- 82 82 82 89 81 66 89 81 66 89 81 66
54225- 94 86 66 94 86 76 74 74 74 50 50 50
54226- 26 26 26 14 14 14 6 6 6 0 0 0
54227- 0 0 0 0 0 0 0 0 0 0 0 0
54228- 0 0 0 0 0 0 0 0 0 0 0 0
54229- 0 0 0 0 0 0 0 0 0 0 0 0
54230- 0 0 0 0 0 0 0 0 0 0 0 0
54231- 0 0 0 0 0 0 0 0 0 0 0 0
54232- 0 0 0 0 0 0 0 0 0 0 0 0
54233- 0 0 0 0 0 0 0 0 0 0 0 0
54234- 0 0 0 0 0 0 0 0 0 0 0 0
54235- 0 0 0 0 0 0 0 0 0 0 0 0
54236- 6 6 6 6 6 6 14 14 14 18 18 18
54237- 30 30 30 38 38 38 46 46 46 54 54 54
54238- 50 50 50 42 42 42 30 30 30 18 18 18
54239- 10 10 10 0 0 0 0 0 0 0 0 0
54240- 0 0 0 0 0 0 0 0 0 0 0 0
54241- 0 0 0 0 0 0 0 0 0 0 0 0
54242- 0 0 0 0 0 0 0 0 0 0 0 0
54243- 0 0 0 6 6 6 14 14 14 26 26 26
54244- 38 38 38 50 50 50 58 58 58 58 58 58
54245- 54 54 54 42 42 42 30 30 30 18 18 18
54246- 10 10 10 0 0 0 0 0 0 0 0 0
54247- 0 0 0 0 0 0 0 0 0 0 0 0
54248- 0 0 0 0 0 0 0 0 0 0 0 0
54249- 0 0 0 0 0 0 0 0 0 0 0 0
54250- 0 0 0 0 0 0 0 0 0 0 0 0
54251- 0 0 0 0 0 0 0 0 0 0 0 0
54252- 0 0 0 0 0 0 0 0 0 0 0 0
54253- 0 0 0 0 0 0 0 0 0 0 0 0
54254- 0 0 0 0 0 0 0 0 0 0 0 0
54255- 0 0 0 0 0 0 0 0 0 0 0 0
54256- 0 0 0 0 0 0 0 0 0 6 6 6
54257- 6 6 6 10 10 10 14 14 14 18 18 18
54258- 18 18 18 14 14 14 10 10 10 6 6 6
54259- 0 0 0 0 0 0 0 0 0 0 0 0
54260- 0 0 0 0 0 0 0 0 0 0 0 0
54261- 0 0 0 0 0 0 0 0 0 0 0 0
54262- 0 0 0 0 0 0 0 0 0 0 0 0
54263- 0 0 0 0 0 0 0 0 0 6 6 6
54264- 14 14 14 18 18 18 22 22 22 22 22 22
54265- 18 18 18 14 14 14 10 10 10 6 6 6
54266- 0 0 0 0 0 0 0 0 0 0 0 0
54267- 0 0 0 0 0 0 0 0 0 0 0 0
54268- 0 0 0 0 0 0 0 0 0 0 0 0
54269- 0 0 0 0 0 0 0 0 0 0 0 0
54270- 0 0 0 0 0 0 0 0 0 0 0 0
54271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54284+4 4 4 4 4 4
54285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54298+4 4 4 4 4 4
54299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54312+4 4 4 4 4 4
54313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54326+4 4 4 4 4 4
54327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54340+4 4 4 4 4 4
54341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54354+4 4 4 4 4 4
54355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54359+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54360+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54364+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54365+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54366+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54368+4 4 4 4 4 4
54369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54373+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54374+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54375+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54378+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54379+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54380+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54381+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54382+4 4 4 4 4 4
54383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54387+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54388+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54389+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54392+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54393+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54394+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54395+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54396+4 4 4 4 4 4
54397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54400+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54401+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54402+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54403+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54405+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54406+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54407+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54408+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54409+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54410+4 4 4 4 4 4
54411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54414+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54415+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54416+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54417+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54418+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54419+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54420+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54421+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54422+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54423+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54424+4 4 4 4 4 4
54425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54428+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54429+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54430+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54431+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54432+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54433+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54434+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54435+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54436+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54437+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54438+4 4 4 4 4 4
54439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54441+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54442+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54443+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54444+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54445+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54446+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54447+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54448+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54449+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54450+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54451+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54452+4 4 4 4 4 4
54453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54455+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54456+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54457+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54458+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54459+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54460+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54461+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54462+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54463+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54464+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54465+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54466+4 4 4 4 4 4
54467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54469+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54470+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54471+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54472+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54473+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54474+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54475+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54476+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54477+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54478+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54479+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54480+4 4 4 4 4 4
54481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54483+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54484+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54485+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54486+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54487+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54488+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54489+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54490+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54491+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54492+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54493+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54494+4 4 4 4 4 4
54495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54496+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54497+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54498+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54499+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54500+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54501+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54502+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54503+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54504+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54505+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54506+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54507+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54508+4 4 4 4 4 4
54509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54510+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54511+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54512+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54513+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54514+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54515+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54516+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54517+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54518+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54519+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54520+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54521+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54522+0 0 0 4 4 4
54523+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54524+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54525+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54526+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54527+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54528+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54529+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54530+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54531+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54532+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54533+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54534+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54535+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54536+2 0 0 0 0 0
54537+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54538+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54539+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54540+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54541+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54542+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54543+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54544+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54545+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54546+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54547+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54548+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54549+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54550+37 38 37 0 0 0
54551+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54552+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54553+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54554+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54555+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54556+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54557+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54558+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54559+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54560+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54561+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54562+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54563+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54564+85 115 134 4 0 0
54565+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54566+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54567+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54568+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54569+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54570+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54571+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54572+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54573+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54574+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54575+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54576+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54577+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54578+60 73 81 4 0 0
54579+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54580+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54581+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54582+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54583+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54584+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54585+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54586+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54587+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54588+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54589+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54590+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54591+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54592+16 19 21 4 0 0
54593+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54594+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54595+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54596+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54597+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54598+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54599+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54600+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54601+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54602+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54603+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54604+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54605+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54606+4 0 0 4 3 3
54607+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54608+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54609+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54611+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54612+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54613+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54614+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54615+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54616+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54617+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54618+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54619+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54620+3 2 2 4 4 4
54621+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54622+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54623+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54624+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54625+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54626+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54627+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54628+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54629+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54630+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54631+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54632+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54633+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54634+4 4 4 4 4 4
54635+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54636+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54637+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54638+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54639+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54640+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54641+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54642+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54643+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54644+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54645+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54646+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54647+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54648+4 4 4 4 4 4
54649+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54650+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54651+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54652+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54653+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54654+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54655+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54656+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54657+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54658+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54659+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54660+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54661+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54662+5 5 5 5 5 5
54663+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54664+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54665+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54666+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54667+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54668+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54669+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54670+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54671+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54672+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54673+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54674+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54675+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54676+5 5 5 4 4 4
54677+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54678+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54679+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54680+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54681+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54682+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54683+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54684+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54685+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54686+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54687+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54688+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54690+4 4 4 4 4 4
54691+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54692+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54693+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54694+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54695+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54696+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54697+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54698+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54699+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54700+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54701+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54702+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54704+4 4 4 4 4 4
54705+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54706+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54707+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54708+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54709+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54710+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54711+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54712+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54713+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54714+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54715+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718+4 4 4 4 4 4
54719+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54720+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54721+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54722+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54723+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54724+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54725+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54726+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54727+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54728+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54729+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54732+4 4 4 4 4 4
54733+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54734+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54735+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54736+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54737+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54738+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54739+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54740+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54741+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54742+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54743+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54746+4 4 4 4 4 4
54747+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54748+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54749+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54750+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54751+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54752+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54753+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54754+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54755+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54756+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54757+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760+4 4 4 4 4 4
54761+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54762+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54763+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54764+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54765+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54766+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54767+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54768+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54769+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54770+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54771+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54774+4 4 4 4 4 4
54775+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54776+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54777+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54778+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54779+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54780+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54781+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54782+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54783+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54784+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54785+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54788+4 4 4 4 4 4
54789+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54790+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54791+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54792+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54793+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54794+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54795+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54796+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54797+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54798+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54799+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54802+4 4 4 4 4 4
54803+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54804+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54805+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54806+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54807+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54808+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54809+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54810+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54811+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54812+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54813+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54816+4 4 4 4 4 4
54817+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54818+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54819+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54820+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54821+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54822+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54823+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54824+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54825+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54826+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54827+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54830+4 4 4 4 4 4
54831+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54832+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54833+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54834+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54835+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54836+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54837+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54838+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54839+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54840+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54841+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54844+4 4 4 4 4 4
54845+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54846+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54847+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54848+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54849+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54850+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54851+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54852+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54853+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54854+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54855+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54858+4 4 4 4 4 4
54859+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54860+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54861+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54862+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54863+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54864+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54865+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54866+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54867+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54868+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54869+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54872+4 4 4 4 4 4
54873+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54874+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54875+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54876+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54877+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54878+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54879+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54880+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54881+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54882+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54883+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54886+4 4 4 4 4 4
54887+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54888+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54889+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54890+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54891+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54892+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54893+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54894+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54895+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54896+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54897+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54900+4 4 4 4 4 4
54901+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54902+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54903+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54904+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54905+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54906+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54907+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54908+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54909+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54910+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54911+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54914+4 4 4 4 4 4
54915+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54916+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54917+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54918+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54919+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54920+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54921+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54922+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54923+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54924+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54925+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54928+4 4 4 4 4 4
54929+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54930+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54931+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54932+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54933+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54934+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54935+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54936+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54937+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54938+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54939+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54942+4 4 4 4 4 4
54943+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54944+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54945+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54946+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54947+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54948+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54949+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54950+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54951+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54952+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54953+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54956+4 4 4 4 4 4
54957+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54958+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54959+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54960+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54961+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54962+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54963+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54964+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54965+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54966+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54967+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54970+4 4 4 4 4 4
54971+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54972+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54973+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54974+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54975+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54976+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54977+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54978+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54979+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54980+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54981+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54984+4 4 4 4 4 4
54985+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54986+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54987+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54988+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54989+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54990+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54991+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54992+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54993+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54994+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54995+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54998+4 4 4 4 4 4
54999+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55000+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55001+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55002+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55003+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55004+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55005+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55006+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55007+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55008+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55009+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55012+4 4 4 4 4 4
55013+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55014+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55015+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55016+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55017+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55018+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55019+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55020+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55021+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55022+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55023+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55026+4 4 4 4 4 4
55027+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55028+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55029+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55030+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55031+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55032+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55033+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55034+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55035+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55036+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55037+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55040+4 4 4 4 4 4
55041+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55042+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55043+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55044+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55045+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55046+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55047+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55048+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55049+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55050+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55051+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55054+4 4 4 4 4 4
55055+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55056+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55057+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55058+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55059+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55060+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55061+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55062+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55063+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55064+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55065+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55068+4 4 4 4 4 4
55069+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55070+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55071+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55072+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55073+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55074+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55075+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55076+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55077+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55078+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55079+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55082+4 4 4 4 4 4
55083+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55084+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55085+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55086+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55087+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55088+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55089+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55090+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55091+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55092+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55096+4 4 4 4 4 4
55097+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55098+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55099+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55100+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55101+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55102+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55103+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55104+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55105+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55106+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55110+4 4 4 4 4 4
55111+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55112+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55113+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55114+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55115+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55116+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55117+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55118+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55119+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55120+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55124+4 4 4 4 4 4
55125+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55126+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55127+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55128+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55129+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55130+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55131+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55132+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55133+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55134+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55138+4 4 4 4 4 4
55139+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55140+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55141+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55142+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55143+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55144+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55145+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55146+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55147+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55152+4 4 4 4 4 4
55153+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55154+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55155+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55156+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55157+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55158+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55159+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55160+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55161+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55166+4 4 4 4 4 4
55167+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55168+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55169+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55170+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55171+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55172+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55173+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55174+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55175+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55180+4 4 4 4 4 4
55181+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55182+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55183+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55184+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55185+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55186+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55187+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55188+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194+4 4 4 4 4 4
55195+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55196+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55197+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55198+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55199+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55200+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55201+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55202+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208+4 4 4 4 4 4
55209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55210+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55211+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55212+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55213+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55214+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55215+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55216+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55222+4 4 4 4 4 4
55223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55224+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55225+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55226+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55227+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55228+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55229+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55230+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55236+4 4 4 4 4 4
55237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55238+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55239+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55240+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55241+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55242+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55243+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55244+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250+4 4 4 4 4 4
55251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55253+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55254+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55255+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55256+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55257+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55258+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264+4 4 4 4 4 4
55265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55268+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55269+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55270+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55271+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55278+4 4 4 4 4 4
55279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55282+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55283+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55284+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55285+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55292+4 4 4 4 4 4
55293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55296+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55297+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55298+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55299+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55306+4 4 4 4 4 4
55307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55310+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55311+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55312+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55313+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55320+4 4 4 4 4 4
55321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55325+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55326+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55327+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55334+4 4 4 4 4 4
55335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55339+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55340+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55341+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55348+4 4 4 4 4 4
55349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55353+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55354+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55355+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55362+4 4 4 4 4 4
55363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55367+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55368+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55376+4 4 4 4 4 4
55377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55381+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55382+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55390+4 4 4 4 4 4
55391diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55392index a01147f..5d896f8 100644
55393--- a/drivers/video/matrox/matroxfb_DAC1064.c
55394+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55395@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55396
55397 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55398 struct matrox_switch matrox_mystique = {
55399- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55400+ .preinit = MGA1064_preinit,
55401+ .reset = MGA1064_reset,
55402+ .init = MGA1064_init,
55403+ .restore = MGA1064_restore,
55404 };
55405 EXPORT_SYMBOL(matrox_mystique);
55406 #endif
55407
55408 #ifdef CONFIG_FB_MATROX_G
55409 struct matrox_switch matrox_G100 = {
55410- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55411+ .preinit = MGAG100_preinit,
55412+ .reset = MGAG100_reset,
55413+ .init = MGAG100_init,
55414+ .restore = MGAG100_restore,
55415 };
55416 EXPORT_SYMBOL(matrox_G100);
55417 #endif
55418diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55419index 195ad7c..09743fc 100644
55420--- a/drivers/video/matrox/matroxfb_Ti3026.c
55421+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55422@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55423 }
55424
55425 struct matrox_switch matrox_millennium = {
55426- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55427+ .preinit = Ti3026_preinit,
55428+ .reset = Ti3026_reset,
55429+ .init = Ti3026_init,
55430+ .restore = Ti3026_restore
55431 };
55432 EXPORT_SYMBOL(matrox_millennium);
55433 #endif
55434diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55435index fe92eed..106e085 100644
55436--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55437+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55438@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55439 struct mb862xxfb_par *par = info->par;
55440
55441 if (info->var.bits_per_pixel == 32) {
55442- info->fbops->fb_fillrect = cfb_fillrect;
55443- info->fbops->fb_copyarea = cfb_copyarea;
55444- info->fbops->fb_imageblit = cfb_imageblit;
55445+ pax_open_kernel();
55446+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55447+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55448+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55449+ pax_close_kernel();
55450 } else {
55451 outreg(disp, GC_L0EM, 3);
55452- info->fbops->fb_fillrect = mb86290fb_fillrect;
55453- info->fbops->fb_copyarea = mb86290fb_copyarea;
55454- info->fbops->fb_imageblit = mb86290fb_imageblit;
55455+ pax_open_kernel();
55456+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55457+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55458+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55459+ pax_close_kernel();
55460 }
55461 outreg(draw, GDC_REG_DRAW_BASE, 0);
55462 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55463diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55464index def0412..fed6529 100644
55465--- a/drivers/video/nvidia/nvidia.c
55466+++ b/drivers/video/nvidia/nvidia.c
55467@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55468 info->fix.line_length = (info->var.xres_virtual *
55469 info->var.bits_per_pixel) >> 3;
55470 if (info->var.accel_flags) {
55471- info->fbops->fb_imageblit = nvidiafb_imageblit;
55472- info->fbops->fb_fillrect = nvidiafb_fillrect;
55473- info->fbops->fb_copyarea = nvidiafb_copyarea;
55474- info->fbops->fb_sync = nvidiafb_sync;
55475+ pax_open_kernel();
55476+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55477+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55478+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55479+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55480+ pax_close_kernel();
55481 info->pixmap.scan_align = 4;
55482 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55483 info->flags |= FBINFO_READS_FAST;
55484 NVResetGraphics(info);
55485 } else {
55486- info->fbops->fb_imageblit = cfb_imageblit;
55487- info->fbops->fb_fillrect = cfb_fillrect;
55488- info->fbops->fb_copyarea = cfb_copyarea;
55489- info->fbops->fb_sync = NULL;
55490+ pax_open_kernel();
55491+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55492+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55493+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55494+ *(void **)&info->fbops->fb_sync = NULL;
55495+ pax_close_kernel();
55496 info->pixmap.scan_align = 1;
55497 info->flags |= FBINFO_HWACCEL_DISABLED;
55498 info->flags &= ~FBINFO_READS_FAST;
55499@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55500 info->pixmap.size = 8 * 1024;
55501 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55502
55503- if (!hwcur)
55504- info->fbops->fb_cursor = NULL;
55505+ if (!hwcur) {
55506+ pax_open_kernel();
55507+ *(void **)&info->fbops->fb_cursor = NULL;
55508+ pax_close_kernel();
55509+ }
55510
55511 info->var.accel_flags = (!noaccel);
55512
55513diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55514index 669a81f..e216d76 100644
55515--- a/drivers/video/omap2/dss/display.c
55516+++ b/drivers/video/omap2/dss/display.c
55517@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55518 snprintf(dssdev->alias, sizeof(dssdev->alias),
55519 "display%d", disp_num_counter++);
55520
55521+ pax_open_kernel();
55522 if (drv && drv->get_resolution == NULL)
55523- drv->get_resolution = omapdss_default_get_resolution;
55524+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55525 if (drv && drv->get_recommended_bpp == NULL)
55526- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55527+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55528 if (drv && drv->get_timings == NULL)
55529- drv->get_timings = omapdss_default_get_timings;
55530+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55531+ pax_close_kernel();
55532
55533 mutex_lock(&panel_list_mutex);
55534 list_add_tail(&dssdev->panel_list, &panel_list);
55535diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55536index 83433cb..71e9b98 100644
55537--- a/drivers/video/s1d13xxxfb.c
55538+++ b/drivers/video/s1d13xxxfb.c
55539@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55540
55541 switch(prod_id) {
55542 case S1D13506_PROD_ID: /* activate acceleration */
55543- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55544- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55545+ pax_open_kernel();
55546+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55547+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55548+ pax_close_kernel();
55549 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55550 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55551 break;
55552diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55553index 2bcc84a..29dd1ea 100644
55554--- a/drivers/video/sh_mobile_lcdcfb.c
55555+++ b/drivers/video/sh_mobile_lcdcfb.c
55556@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55557 }
55558
55559 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55560- lcdc_sys_write_index,
55561- lcdc_sys_write_data,
55562- lcdc_sys_read_data,
55563+ .write_index = lcdc_sys_write_index,
55564+ .write_data = lcdc_sys_write_data,
55565+ .read_data = lcdc_sys_read_data,
55566 };
55567
55568 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55569diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55570index d513ed6..90b0de9 100644
55571--- a/drivers/video/smscufx.c
55572+++ b/drivers/video/smscufx.c
55573@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55574 fb_deferred_io_cleanup(info);
55575 kfree(info->fbdefio);
55576 info->fbdefio = NULL;
55577- info->fbops->fb_mmap = ufx_ops_mmap;
55578+ pax_open_kernel();
55579+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55580+ pax_close_kernel();
55581 }
55582
55583 pr_debug("released /dev/fb%d user=%d count=%d",
55584diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55585index 77b890e..458e666 100644
55586--- a/drivers/video/udlfb.c
55587+++ b/drivers/video/udlfb.c
55588@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55589 dlfb_urb_completion(urb);
55590
55591 error:
55592- atomic_add(bytes_sent, &dev->bytes_sent);
55593- atomic_add(bytes_identical, &dev->bytes_identical);
55594- atomic_add(width*height*2, &dev->bytes_rendered);
55595+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55596+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55597+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55598 end_cycles = get_cycles();
55599- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55600+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55601 >> 10)), /* Kcycles */
55602 &dev->cpu_kcycles_used);
55603
55604@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55605 dlfb_urb_completion(urb);
55606
55607 error:
55608- atomic_add(bytes_sent, &dev->bytes_sent);
55609- atomic_add(bytes_identical, &dev->bytes_identical);
55610- atomic_add(bytes_rendered, &dev->bytes_rendered);
55611+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55612+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55613+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55614 end_cycles = get_cycles();
55615- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55616+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55617 >> 10)), /* Kcycles */
55618 &dev->cpu_kcycles_used);
55619 }
55620@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55621 fb_deferred_io_cleanup(info);
55622 kfree(info->fbdefio);
55623 info->fbdefio = NULL;
55624- info->fbops->fb_mmap = dlfb_ops_mmap;
55625+ pax_open_kernel();
55626+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55627+ pax_close_kernel();
55628 }
55629
55630 pr_warn("released /dev/fb%d user=%d count=%d\n",
55631@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55632 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55633 struct dlfb_data *dev = fb_info->par;
55634 return snprintf(buf, PAGE_SIZE, "%u\n",
55635- atomic_read(&dev->bytes_rendered));
55636+ atomic_read_unchecked(&dev->bytes_rendered));
55637 }
55638
55639 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55640@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55641 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55642 struct dlfb_data *dev = fb_info->par;
55643 return snprintf(buf, PAGE_SIZE, "%u\n",
55644- atomic_read(&dev->bytes_identical));
55645+ atomic_read_unchecked(&dev->bytes_identical));
55646 }
55647
55648 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55649@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55650 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55651 struct dlfb_data *dev = fb_info->par;
55652 return snprintf(buf, PAGE_SIZE, "%u\n",
55653- atomic_read(&dev->bytes_sent));
55654+ atomic_read_unchecked(&dev->bytes_sent));
55655 }
55656
55657 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55658@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55659 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55660 struct dlfb_data *dev = fb_info->par;
55661 return snprintf(buf, PAGE_SIZE, "%u\n",
55662- atomic_read(&dev->cpu_kcycles_used));
55663+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55664 }
55665
55666 static ssize_t edid_show(
55667@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55668 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55669 struct dlfb_data *dev = fb_info->par;
55670
55671- atomic_set(&dev->bytes_rendered, 0);
55672- atomic_set(&dev->bytes_identical, 0);
55673- atomic_set(&dev->bytes_sent, 0);
55674- atomic_set(&dev->cpu_kcycles_used, 0);
55675+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55676+ atomic_set_unchecked(&dev->bytes_identical, 0);
55677+ atomic_set_unchecked(&dev->bytes_sent, 0);
55678+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55679
55680 return count;
55681 }
55682diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55683index 256fba7..6e75516 100644
55684--- a/drivers/video/uvesafb.c
55685+++ b/drivers/video/uvesafb.c
55686@@ -19,6 +19,7 @@
55687 #include <linux/io.h>
55688 #include <linux/mutex.h>
55689 #include <linux/slab.h>
55690+#include <linux/moduleloader.h>
55691 #include <video/edid.h>
55692 #include <video/uvesafb.h>
55693 #ifdef CONFIG_X86
55694@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55695 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55696 par->pmi_setpal = par->ypan = 0;
55697 } else {
55698+
55699+#ifdef CONFIG_PAX_KERNEXEC
55700+#ifdef CONFIG_MODULES
55701+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55702+#endif
55703+ if (!par->pmi_code) {
55704+ par->pmi_setpal = par->ypan = 0;
55705+ return 0;
55706+ }
55707+#endif
55708+
55709 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55710 + task->t.regs.edi);
55711+
55712+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55713+ pax_open_kernel();
55714+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55715+ pax_close_kernel();
55716+
55717+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55718+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55719+#else
55720 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55721 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55722+#endif
55723+
55724 printk(KERN_INFO "uvesafb: protected mode interface info at "
55725 "%04x:%04x\n",
55726 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55727@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55728 par->ypan = ypan;
55729
55730 if (par->pmi_setpal || par->ypan) {
55731+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55732 if (__supported_pte_mask & _PAGE_NX) {
55733 par->pmi_setpal = par->ypan = 0;
55734 printk(KERN_WARNING "uvesafb: NX protection is active, "
55735 "better not use the PMI.\n");
55736- } else {
55737+ } else
55738+#endif
55739 uvesafb_vbe_getpmi(task, par);
55740- }
55741 }
55742 #else
55743 /* The protected mode interface is not available on non-x86. */
55744@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55745 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55746
55747 /* Disable blanking if the user requested so. */
55748- if (!blank)
55749- info->fbops->fb_blank = NULL;
55750+ if (!blank) {
55751+ pax_open_kernel();
55752+ *(void **)&info->fbops->fb_blank = NULL;
55753+ pax_close_kernel();
55754+ }
55755
55756 /*
55757 * Find out how much IO memory is required for the mode with
55758@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55759 info->flags = FBINFO_FLAG_DEFAULT |
55760 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55761
55762- if (!par->ypan)
55763- info->fbops->fb_pan_display = NULL;
55764+ if (!par->ypan) {
55765+ pax_open_kernel();
55766+ *(void **)&info->fbops->fb_pan_display = NULL;
55767+ pax_close_kernel();
55768+ }
55769 }
55770
55771 static void uvesafb_init_mtrr(struct fb_info *info)
55772@@ -1792,6 +1822,11 @@ out_mode:
55773 out:
55774 kfree(par->vbe_modes);
55775
55776+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55777+ if (par->pmi_code)
55778+ module_free_exec(NULL, par->pmi_code);
55779+#endif
55780+
55781 framebuffer_release(info);
55782 return err;
55783 }
55784@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55785 kfree(par->vbe_modes);
55786 kfree(par->vbe_state_orig);
55787 kfree(par->vbe_state_saved);
55788+
55789+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55790+ if (par->pmi_code)
55791+ module_free_exec(NULL, par->pmi_code);
55792+#endif
55793+
55794 }
55795
55796 framebuffer_release(info);
55797diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55798index 1c7da3b..56ea0bd 100644
55799--- a/drivers/video/vesafb.c
55800+++ b/drivers/video/vesafb.c
55801@@ -9,6 +9,7 @@
55802 */
55803
55804 #include <linux/module.h>
55805+#include <linux/moduleloader.h>
55806 #include <linux/kernel.h>
55807 #include <linux/errno.h>
55808 #include <linux/string.h>
55809@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55810 static int vram_total; /* Set total amount of memory */
55811 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55812 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55813-static void (*pmi_start)(void) __read_mostly;
55814-static void (*pmi_pal) (void) __read_mostly;
55815+static void (*pmi_start)(void) __read_only;
55816+static void (*pmi_pal) (void) __read_only;
55817 static int depth __read_mostly;
55818 static int vga_compat __read_mostly;
55819 /* --------------------------------------------------------------------- */
55820@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55821 unsigned int size_remap;
55822 unsigned int size_total;
55823 char *option = NULL;
55824+ void *pmi_code = NULL;
55825
55826 /* ignore error return of fb_get_options */
55827 fb_get_options("vesafb", &option);
55828@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55829 size_remap = size_total;
55830 vesafb_fix.smem_len = size_remap;
55831
55832-#ifndef __i386__
55833- screen_info.vesapm_seg = 0;
55834-#endif
55835-
55836 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55837 printk(KERN_WARNING
55838 "vesafb: cannot reserve video memory at 0x%lx\n",
55839@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55840 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55841 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55842
55843+#ifdef __i386__
55844+
55845+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55846+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55847+ if (!pmi_code)
55848+#elif !defined(CONFIG_PAX_KERNEXEC)
55849+ if (0)
55850+#endif
55851+
55852+#endif
55853+ screen_info.vesapm_seg = 0;
55854+
55855 if (screen_info.vesapm_seg) {
55856- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55857- screen_info.vesapm_seg,screen_info.vesapm_off);
55858+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55859+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55860 }
55861
55862 if (screen_info.vesapm_seg < 0xc000)
55863@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55864
55865 if (ypan || pmi_setpal) {
55866 unsigned short *pmi_base;
55867+
55868 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55869- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55870- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55871+
55872+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55873+ pax_open_kernel();
55874+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55875+#else
55876+ pmi_code = pmi_base;
55877+#endif
55878+
55879+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55880+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55881+
55882+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55883+ pmi_start = ktva_ktla(pmi_start);
55884+ pmi_pal = ktva_ktla(pmi_pal);
55885+ pax_close_kernel();
55886+#endif
55887+
55888 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55889 if (pmi_base[3]) {
55890 printk(KERN_INFO "vesafb: pmi: ports = ");
55891@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55892 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55893 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55894
55895- if (!ypan)
55896- info->fbops->fb_pan_display = NULL;
55897+ if (!ypan) {
55898+ pax_open_kernel();
55899+ *(void **)&info->fbops->fb_pan_display = NULL;
55900+ pax_close_kernel();
55901+ }
55902
55903 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55904 err = -ENOMEM;
55905@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55906 fb_info(info, "%s frame buffer device\n", info->fix.id);
55907 return 0;
55908 err:
55909+
55910+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55911+ module_free_exec(NULL, pmi_code);
55912+#endif
55913+
55914 if (info->screen_base)
55915 iounmap(info->screen_base);
55916 framebuffer_release(info);
55917diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55918index 88714ae..16c2e11 100644
55919--- a/drivers/video/via/via_clock.h
55920+++ b/drivers/video/via/via_clock.h
55921@@ -56,7 +56,7 @@ struct via_clock {
55922
55923 void (*set_engine_pll_state)(u8 state);
55924 void (*set_engine_pll)(struct via_pll_config config);
55925-};
55926+} __no_const;
55927
55928
55929 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55930diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55931index fef20db..d28b1ab 100644
55932--- a/drivers/xen/xenfs/xenstored.c
55933+++ b/drivers/xen/xenfs/xenstored.c
55934@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55935 static int xsd_kva_open(struct inode *inode, struct file *file)
55936 {
55937 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55938+#ifdef CONFIG_GRKERNSEC_HIDESYM
55939+ NULL);
55940+#else
55941 xen_store_interface);
55942+#endif
55943+
55944 if (!file->private_data)
55945 return -ENOMEM;
55946 return 0;
55947diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55948index c71e886..61d3d44b 100644
55949--- a/fs/9p/vfs_addr.c
55950+++ b/fs/9p/vfs_addr.c
55951@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55952
55953 retval = v9fs_file_write_internal(inode,
55954 v9inode->writeback_fid,
55955- (__force const char __user *)buffer,
55956+ (const char __force_user *)buffer,
55957 len, &offset, 0);
55958 if (retval > 0)
55959 retval = 0;
55960diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55961index bb7991c..481e21a 100644
55962--- a/fs/9p/vfs_inode.c
55963+++ b/fs/9p/vfs_inode.c
55964@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55965 void
55966 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55967 {
55968- char *s = nd_get_link(nd);
55969+ const char *s = nd_get_link(nd);
55970
55971 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55972 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55973diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55974index 370b24c..ff0be7b 100644
55975--- a/fs/Kconfig.binfmt
55976+++ b/fs/Kconfig.binfmt
55977@@ -103,7 +103,7 @@ config HAVE_AOUT
55978
55979 config BINFMT_AOUT
55980 tristate "Kernel support for a.out and ECOFF binaries"
55981- depends on HAVE_AOUT
55982+ depends on HAVE_AOUT && BROKEN
55983 ---help---
55984 A.out (Assembler.OUTput) is a set of formats for libraries and
55985 executables used in the earliest versions of UNIX. Linux used
55986diff --git a/fs/affs/super.c b/fs/affs/super.c
55987index d098731..9a5b19d 100644
55988--- a/fs/affs/super.c
55989+++ b/fs/affs/super.c
55990@@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
55991 &blocksize,&sbi->s_prefix,
55992 sbi->s_volume, &mount_flags)) {
55993 printk(KERN_ERR "AFFS: Error parsing options\n");
55994- kfree(sbi->s_prefix);
55995- kfree(sbi);
55996 return -EINVAL;
55997 }
55998 /* N.B. after this point s_prefix must be released */
55999diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56000index ce25d75..dc09eeb 100644
56001--- a/fs/afs/inode.c
56002+++ b/fs/afs/inode.c
56003@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56004 struct afs_vnode *vnode;
56005 struct super_block *sb;
56006 struct inode *inode;
56007- static atomic_t afs_autocell_ino;
56008+ static atomic_unchecked_t afs_autocell_ino;
56009
56010 _enter("{%x:%u},%*.*s,",
56011 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56012@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56013 data.fid.unique = 0;
56014 data.fid.vnode = 0;
56015
56016- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56017+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56018 afs_iget5_autocell_test, afs_iget5_set,
56019 &data);
56020 if (!inode) {
56021diff --git a/fs/aio.c b/fs/aio.c
56022index 062a5f6..6ecefa2 100644
56023--- a/fs/aio.c
56024+++ b/fs/aio.c
56025@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56026 size += sizeof(struct io_event) * nr_events;
56027
56028 nr_pages = PFN_UP(size);
56029- if (nr_pages < 0)
56030+ if (nr_pages <= 0)
56031 return -EINVAL;
56032
56033 file = aio_private_file(ctx, nr_pages);
56034@@ -1285,10 +1285,8 @@ rw_common:
56035 &iovec, compat)
56036 : aio_setup_single_vector(req, rw, buf, &nr_segs,
56037 iovec);
56038- if (ret)
56039- return ret;
56040-
56041- ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56042+ if (!ret)
56043+ ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56044 if (ret < 0) {
56045 if (iovec != &inline_vec)
56046 kfree(iovec);
56047diff --git a/fs/attr.c b/fs/attr.c
56048index 5d4e59d..fd02418 100644
56049--- a/fs/attr.c
56050+++ b/fs/attr.c
56051@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56052 unsigned long limit;
56053
56054 limit = rlimit(RLIMIT_FSIZE);
56055+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56056 if (limit != RLIM_INFINITY && offset > limit)
56057 goto out_sig;
56058 if (offset > inode->i_sb->s_maxbytes)
56059diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56060index 116fd38..c04182da 100644
56061--- a/fs/autofs4/waitq.c
56062+++ b/fs/autofs4/waitq.c
56063@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56064 {
56065 unsigned long sigpipe, flags;
56066 mm_segment_t fs;
56067- const char *data = (const char *)addr;
56068+ const char __user *data = (const char __force_user *)addr;
56069 ssize_t wr = 0;
56070
56071 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56072@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56073 return 1;
56074 }
56075
56076+#ifdef CONFIG_GRKERNSEC_HIDESYM
56077+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56078+#endif
56079+
56080 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56081 enum autofs_notify notify)
56082 {
56083@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56084
56085 /* If this is a direct mount request create a dummy name */
56086 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56087+#ifdef CONFIG_GRKERNSEC_HIDESYM
56088+ /* this name does get written to userland via autofs4_write() */
56089+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56090+#else
56091 qstr.len = sprintf(name, "%p", dentry);
56092+#endif
56093 else {
56094 qstr.len = autofs4_getpath(sbi, dentry, &name);
56095 if (!qstr.len) {
56096diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56097index 2722387..56059b5 100644
56098--- a/fs/befs/endian.h
56099+++ b/fs/befs/endian.h
56100@@ -11,7 +11,7 @@
56101
56102 #include <asm/byteorder.h>
56103
56104-static inline u64
56105+static inline u64 __intentional_overflow(-1)
56106 fs64_to_cpu(const struct super_block *sb, fs64 n)
56107 {
56108 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56109@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56110 return (__force fs64)cpu_to_be64(n);
56111 }
56112
56113-static inline u32
56114+static inline u32 __intentional_overflow(-1)
56115 fs32_to_cpu(const struct super_block *sb, fs32 n)
56116 {
56117 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56118@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56119 return (__force fs32)cpu_to_be32(n);
56120 }
56121
56122-static inline u16
56123+static inline u16 __intentional_overflow(-1)
56124 fs16_to_cpu(const struct super_block *sb, fs16 n)
56125 {
56126 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56127diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56128index ca0ba15..0fa3257 100644
56129--- a/fs/binfmt_aout.c
56130+++ b/fs/binfmt_aout.c
56131@@ -16,6 +16,7 @@
56132 #include <linux/string.h>
56133 #include <linux/fs.h>
56134 #include <linux/file.h>
56135+#include <linux/security.h>
56136 #include <linux/stat.h>
56137 #include <linux/fcntl.h>
56138 #include <linux/ptrace.h>
56139@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56140 #endif
56141 # define START_STACK(u) ((void __user *)u.start_stack)
56142
56143+ memset(&dump, 0, sizeof(dump));
56144+
56145 fs = get_fs();
56146 set_fs(KERNEL_DS);
56147 has_dumped = 1;
56148@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56149
56150 /* If the size of the dump file exceeds the rlimit, then see what would happen
56151 if we wrote the stack, but not the data area. */
56152+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56153 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56154 dump.u_dsize = 0;
56155
56156 /* Make sure we have enough room to write the stack and data areas. */
56157+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56158 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56159 dump.u_ssize = 0;
56160
56161@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56162 rlim = rlimit(RLIMIT_DATA);
56163 if (rlim >= RLIM_INFINITY)
56164 rlim = ~0;
56165+
56166+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56167 if (ex.a_data + ex.a_bss > rlim)
56168 return -ENOMEM;
56169
56170@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56171
56172 install_exec_creds(bprm);
56173
56174+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56175+ current->mm->pax_flags = 0UL;
56176+#endif
56177+
56178+#ifdef CONFIG_PAX_PAGEEXEC
56179+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56180+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56181+
56182+#ifdef CONFIG_PAX_EMUTRAMP
56183+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56184+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56185+#endif
56186+
56187+#ifdef CONFIG_PAX_MPROTECT
56188+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56189+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56190+#endif
56191+
56192+ }
56193+#endif
56194+
56195 if (N_MAGIC(ex) == OMAGIC) {
56196 unsigned long text_addr, map_size;
56197 loff_t pos;
56198@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56199 }
56200
56201 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56202- PROT_READ | PROT_WRITE | PROT_EXEC,
56203+ PROT_READ | PROT_WRITE,
56204 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56205 fd_offset + ex.a_text);
56206 if (error != N_DATADDR(ex)) {
56207diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56208index 67be295..83e2f86 100644
56209--- a/fs/binfmt_elf.c
56210+++ b/fs/binfmt_elf.c
56211@@ -34,6 +34,7 @@
56212 #include <linux/utsname.h>
56213 #include <linux/coredump.h>
56214 #include <linux/sched.h>
56215+#include <linux/xattr.h>
56216 #include <asm/uaccess.h>
56217 #include <asm/param.h>
56218 #include <asm/page.h>
56219@@ -48,7 +49,7 @@
56220 static int load_elf_binary(struct linux_binprm *bprm);
56221 static int load_elf_library(struct file *);
56222 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56223- int, int, unsigned long);
56224+ int, int, unsigned long) __intentional_overflow(-1);
56225
56226 /*
56227 * If we don't support core dumping, then supply a NULL so we
56228@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56229 #define elf_core_dump NULL
56230 #endif
56231
56232+#ifdef CONFIG_PAX_MPROTECT
56233+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56234+#endif
56235+
56236+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56237+static void elf_handle_mmap(struct file *file);
56238+#endif
56239+
56240 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56241 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56242 #else
56243@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56244 .load_binary = load_elf_binary,
56245 .load_shlib = load_elf_library,
56246 .core_dump = elf_core_dump,
56247+
56248+#ifdef CONFIG_PAX_MPROTECT
56249+ .handle_mprotect= elf_handle_mprotect,
56250+#endif
56251+
56252+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56253+ .handle_mmap = elf_handle_mmap,
56254+#endif
56255+
56256 .min_coredump = ELF_EXEC_PAGESIZE,
56257 };
56258
56259@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56260
56261 static int set_brk(unsigned long start, unsigned long end)
56262 {
56263+ unsigned long e = end;
56264+
56265 start = ELF_PAGEALIGN(start);
56266 end = ELF_PAGEALIGN(end);
56267 if (end > start) {
56268@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56269 if (BAD_ADDR(addr))
56270 return addr;
56271 }
56272- current->mm->start_brk = current->mm->brk = end;
56273+ current->mm->start_brk = current->mm->brk = e;
56274 return 0;
56275 }
56276
56277@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56278 elf_addr_t __user *u_rand_bytes;
56279 const char *k_platform = ELF_PLATFORM;
56280 const char *k_base_platform = ELF_BASE_PLATFORM;
56281- unsigned char k_rand_bytes[16];
56282+ u32 k_rand_bytes[4];
56283 int items;
56284 elf_addr_t *elf_info;
56285 int ei_index = 0;
56286 const struct cred *cred = current_cred();
56287 struct vm_area_struct *vma;
56288+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56289
56290 /*
56291 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56292@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56293 * Generate 16 random bytes for userspace PRNG seeding.
56294 */
56295 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56296- u_rand_bytes = (elf_addr_t __user *)
56297- STACK_ALLOC(p, sizeof(k_rand_bytes));
56298+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56299+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56300+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56301+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56302+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56303+ u_rand_bytes = (elf_addr_t __user *) p;
56304 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56305 return -EFAULT;
56306
56307@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56308 return -EFAULT;
56309 current->mm->env_end = p;
56310
56311+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56312+
56313 /* Put the elf_info on the stack in the right place. */
56314 sp = (elf_addr_t __user *)envp + 1;
56315- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56316+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56317 return -EFAULT;
56318 return 0;
56319 }
56320@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56321 an ELF header */
56322
56323 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56324- struct file *interpreter, unsigned long *interp_map_addr,
56325- unsigned long no_base)
56326+ struct file *interpreter, unsigned long no_base)
56327 {
56328 struct elf_phdr *elf_phdata;
56329 struct elf_phdr *eppnt;
56330- unsigned long load_addr = 0;
56331+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56332 int load_addr_set = 0;
56333 unsigned long last_bss = 0, elf_bss = 0;
56334- unsigned long error = ~0UL;
56335+ unsigned long error = -EINVAL;
56336 unsigned long total_size;
56337 int retval, i, size;
56338
56339@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56340 goto out_close;
56341 }
56342
56343+#ifdef CONFIG_PAX_SEGMEXEC
56344+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56345+ pax_task_size = SEGMEXEC_TASK_SIZE;
56346+#endif
56347+
56348 eppnt = elf_phdata;
56349 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56350 if (eppnt->p_type == PT_LOAD) {
56351@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56352 map_addr = elf_map(interpreter, load_addr + vaddr,
56353 eppnt, elf_prot, elf_type, total_size);
56354 total_size = 0;
56355- if (!*interp_map_addr)
56356- *interp_map_addr = map_addr;
56357 error = map_addr;
56358 if (BAD_ADDR(map_addr))
56359 goto out_close;
56360@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56361 k = load_addr + eppnt->p_vaddr;
56362 if (BAD_ADDR(k) ||
56363 eppnt->p_filesz > eppnt->p_memsz ||
56364- eppnt->p_memsz > TASK_SIZE ||
56365- TASK_SIZE - eppnt->p_memsz < k) {
56366+ eppnt->p_memsz > pax_task_size ||
56367+ pax_task_size - eppnt->p_memsz < k) {
56368 error = -ENOMEM;
56369 goto out_close;
56370 }
56371@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56372 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56373
56374 /* Map the last of the bss segment */
56375- error = vm_brk(elf_bss, last_bss - elf_bss);
56376- if (BAD_ADDR(error))
56377- goto out_close;
56378+ if (last_bss > elf_bss) {
56379+ error = vm_brk(elf_bss, last_bss - elf_bss);
56380+ if (BAD_ADDR(error))
56381+ goto out_close;
56382+ }
56383 }
56384
56385 error = load_addr;
56386@@ -538,6 +569,336 @@ out:
56387 return error;
56388 }
56389
56390+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56391+#ifdef CONFIG_PAX_SOFTMODE
56392+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56393+{
56394+ unsigned long pax_flags = 0UL;
56395+
56396+#ifdef CONFIG_PAX_PAGEEXEC
56397+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56398+ pax_flags |= MF_PAX_PAGEEXEC;
56399+#endif
56400+
56401+#ifdef CONFIG_PAX_SEGMEXEC
56402+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56403+ pax_flags |= MF_PAX_SEGMEXEC;
56404+#endif
56405+
56406+#ifdef CONFIG_PAX_EMUTRAMP
56407+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56408+ pax_flags |= MF_PAX_EMUTRAMP;
56409+#endif
56410+
56411+#ifdef CONFIG_PAX_MPROTECT
56412+ if (elf_phdata->p_flags & PF_MPROTECT)
56413+ pax_flags |= MF_PAX_MPROTECT;
56414+#endif
56415+
56416+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56417+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56418+ pax_flags |= MF_PAX_RANDMMAP;
56419+#endif
56420+
56421+ return pax_flags;
56422+}
56423+#endif
56424+
56425+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56426+{
56427+ unsigned long pax_flags = 0UL;
56428+
56429+#ifdef CONFIG_PAX_PAGEEXEC
56430+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56431+ pax_flags |= MF_PAX_PAGEEXEC;
56432+#endif
56433+
56434+#ifdef CONFIG_PAX_SEGMEXEC
56435+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56436+ pax_flags |= MF_PAX_SEGMEXEC;
56437+#endif
56438+
56439+#ifdef CONFIG_PAX_EMUTRAMP
56440+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56441+ pax_flags |= MF_PAX_EMUTRAMP;
56442+#endif
56443+
56444+#ifdef CONFIG_PAX_MPROTECT
56445+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56446+ pax_flags |= MF_PAX_MPROTECT;
56447+#endif
56448+
56449+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56450+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56451+ pax_flags |= MF_PAX_RANDMMAP;
56452+#endif
56453+
56454+ return pax_flags;
56455+}
56456+#endif
56457+
56458+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56459+#ifdef CONFIG_PAX_SOFTMODE
56460+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56461+{
56462+ unsigned long pax_flags = 0UL;
56463+
56464+#ifdef CONFIG_PAX_PAGEEXEC
56465+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56466+ pax_flags |= MF_PAX_PAGEEXEC;
56467+#endif
56468+
56469+#ifdef CONFIG_PAX_SEGMEXEC
56470+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56471+ pax_flags |= MF_PAX_SEGMEXEC;
56472+#endif
56473+
56474+#ifdef CONFIG_PAX_EMUTRAMP
56475+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56476+ pax_flags |= MF_PAX_EMUTRAMP;
56477+#endif
56478+
56479+#ifdef CONFIG_PAX_MPROTECT
56480+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56481+ pax_flags |= MF_PAX_MPROTECT;
56482+#endif
56483+
56484+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56485+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56486+ pax_flags |= MF_PAX_RANDMMAP;
56487+#endif
56488+
56489+ return pax_flags;
56490+}
56491+#endif
56492+
56493+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56494+{
56495+ unsigned long pax_flags = 0UL;
56496+
56497+#ifdef CONFIG_PAX_PAGEEXEC
56498+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56499+ pax_flags |= MF_PAX_PAGEEXEC;
56500+#endif
56501+
56502+#ifdef CONFIG_PAX_SEGMEXEC
56503+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56504+ pax_flags |= MF_PAX_SEGMEXEC;
56505+#endif
56506+
56507+#ifdef CONFIG_PAX_EMUTRAMP
56508+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56509+ pax_flags |= MF_PAX_EMUTRAMP;
56510+#endif
56511+
56512+#ifdef CONFIG_PAX_MPROTECT
56513+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56514+ pax_flags |= MF_PAX_MPROTECT;
56515+#endif
56516+
56517+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56518+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56519+ pax_flags |= MF_PAX_RANDMMAP;
56520+#endif
56521+
56522+ return pax_flags;
56523+}
56524+#endif
56525+
56526+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56527+static unsigned long pax_parse_defaults(void)
56528+{
56529+ unsigned long pax_flags = 0UL;
56530+
56531+#ifdef CONFIG_PAX_SOFTMODE
56532+ if (pax_softmode)
56533+ return pax_flags;
56534+#endif
56535+
56536+#ifdef CONFIG_PAX_PAGEEXEC
56537+ pax_flags |= MF_PAX_PAGEEXEC;
56538+#endif
56539+
56540+#ifdef CONFIG_PAX_SEGMEXEC
56541+ pax_flags |= MF_PAX_SEGMEXEC;
56542+#endif
56543+
56544+#ifdef CONFIG_PAX_MPROTECT
56545+ pax_flags |= MF_PAX_MPROTECT;
56546+#endif
56547+
56548+#ifdef CONFIG_PAX_RANDMMAP
56549+ if (randomize_va_space)
56550+ pax_flags |= MF_PAX_RANDMMAP;
56551+#endif
56552+
56553+ return pax_flags;
56554+}
56555+
56556+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56557+{
56558+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56559+
56560+#ifdef CONFIG_PAX_EI_PAX
56561+
56562+#ifdef CONFIG_PAX_SOFTMODE
56563+ if (pax_softmode)
56564+ return pax_flags;
56565+#endif
56566+
56567+ pax_flags = 0UL;
56568+
56569+#ifdef CONFIG_PAX_PAGEEXEC
56570+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56571+ pax_flags |= MF_PAX_PAGEEXEC;
56572+#endif
56573+
56574+#ifdef CONFIG_PAX_SEGMEXEC
56575+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56576+ pax_flags |= MF_PAX_SEGMEXEC;
56577+#endif
56578+
56579+#ifdef CONFIG_PAX_EMUTRAMP
56580+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56581+ pax_flags |= MF_PAX_EMUTRAMP;
56582+#endif
56583+
56584+#ifdef CONFIG_PAX_MPROTECT
56585+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56586+ pax_flags |= MF_PAX_MPROTECT;
56587+#endif
56588+
56589+#ifdef CONFIG_PAX_ASLR
56590+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56591+ pax_flags |= MF_PAX_RANDMMAP;
56592+#endif
56593+
56594+#endif
56595+
56596+ return pax_flags;
56597+
56598+}
56599+
56600+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56601+{
56602+
56603+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56604+ unsigned long i;
56605+
56606+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56607+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56608+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56609+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56610+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56611+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56612+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56613+ return PAX_PARSE_FLAGS_FALLBACK;
56614+
56615+#ifdef CONFIG_PAX_SOFTMODE
56616+ if (pax_softmode)
56617+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56618+ else
56619+#endif
56620+
56621+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56622+ break;
56623+ }
56624+#endif
56625+
56626+ return PAX_PARSE_FLAGS_FALLBACK;
56627+}
56628+
56629+static unsigned long pax_parse_xattr_pax(struct file * const file)
56630+{
56631+
56632+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56633+ ssize_t xattr_size, i;
56634+ unsigned char xattr_value[sizeof("pemrs") - 1];
56635+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56636+
56637+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56638+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56639+ return PAX_PARSE_FLAGS_FALLBACK;
56640+
56641+ for (i = 0; i < xattr_size; i++)
56642+ switch (xattr_value[i]) {
56643+ default:
56644+ return PAX_PARSE_FLAGS_FALLBACK;
56645+
56646+#define parse_flag(option1, option2, flag) \
56647+ case option1: \
56648+ if (pax_flags_hardmode & MF_PAX_##flag) \
56649+ return PAX_PARSE_FLAGS_FALLBACK;\
56650+ pax_flags_hardmode |= MF_PAX_##flag; \
56651+ break; \
56652+ case option2: \
56653+ if (pax_flags_softmode & MF_PAX_##flag) \
56654+ return PAX_PARSE_FLAGS_FALLBACK;\
56655+ pax_flags_softmode |= MF_PAX_##flag; \
56656+ break;
56657+
56658+ parse_flag('p', 'P', PAGEEXEC);
56659+ parse_flag('e', 'E', EMUTRAMP);
56660+ parse_flag('m', 'M', MPROTECT);
56661+ parse_flag('r', 'R', RANDMMAP);
56662+ parse_flag('s', 'S', SEGMEXEC);
56663+
56664+#undef parse_flag
56665+ }
56666+
56667+ if (pax_flags_hardmode & pax_flags_softmode)
56668+ return PAX_PARSE_FLAGS_FALLBACK;
56669+
56670+#ifdef CONFIG_PAX_SOFTMODE
56671+ if (pax_softmode)
56672+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56673+ else
56674+#endif
56675+
56676+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56677+#else
56678+ return PAX_PARSE_FLAGS_FALLBACK;
56679+#endif
56680+
56681+}
56682+
56683+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56684+{
56685+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56686+
56687+ pax_flags = pax_parse_defaults();
56688+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56689+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56690+ xattr_pax_flags = pax_parse_xattr_pax(file);
56691+
56692+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56693+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56694+ pt_pax_flags != xattr_pax_flags)
56695+ return -EINVAL;
56696+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56697+ pax_flags = xattr_pax_flags;
56698+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56699+ pax_flags = pt_pax_flags;
56700+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56701+ pax_flags = ei_pax_flags;
56702+
56703+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56704+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56705+ if ((__supported_pte_mask & _PAGE_NX))
56706+ pax_flags &= ~MF_PAX_SEGMEXEC;
56707+ else
56708+ pax_flags &= ~MF_PAX_PAGEEXEC;
56709+ }
56710+#endif
56711+
56712+ if (0 > pax_check_flags(&pax_flags))
56713+ return -EINVAL;
56714+
56715+ current->mm->pax_flags = pax_flags;
56716+ return 0;
56717+}
56718+#endif
56719+
56720 /*
56721 * These are the functions used to load ELF style executables and shared
56722 * libraries. There is no binary dependent code anywhere else.
56723@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56724 {
56725 unsigned int random_variable = 0;
56726
56727+#ifdef CONFIG_PAX_RANDUSTACK
56728+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56729+ return stack_top - current->mm->delta_stack;
56730+#endif
56731+
56732 if ((current->flags & PF_RANDOMIZE) &&
56733 !(current->personality & ADDR_NO_RANDOMIZE)) {
56734 random_variable = get_random_int() & STACK_RND_MASK;
56735@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56736 unsigned long load_addr = 0, load_bias = 0;
56737 int load_addr_set = 0;
56738 char * elf_interpreter = NULL;
56739- unsigned long error;
56740+ unsigned long error = 0;
56741 struct elf_phdr *elf_ppnt, *elf_phdata;
56742 unsigned long elf_bss, elf_brk;
56743 int retval, i;
56744@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56745 unsigned long start_code, end_code, start_data, end_data;
56746 unsigned long reloc_func_desc __maybe_unused = 0;
56747 int executable_stack = EXSTACK_DEFAULT;
56748- unsigned long def_flags = 0;
56749 struct pt_regs *regs = current_pt_regs();
56750 struct {
56751 struct elfhdr elf_ex;
56752 struct elfhdr interp_elf_ex;
56753 } *loc;
56754+ unsigned long pax_task_size;
56755
56756 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56757 if (!loc) {
56758@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56759 goto out_free_dentry;
56760
56761 /* OK, This is the point of no return */
56762- current->mm->def_flags = def_flags;
56763+ current->mm->def_flags = 0;
56764
56765 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56766 may depend on the personality. */
56767 SET_PERSONALITY(loc->elf_ex);
56768+
56769+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56770+ current->mm->pax_flags = 0UL;
56771+#endif
56772+
56773+#ifdef CONFIG_PAX_DLRESOLVE
56774+ current->mm->call_dl_resolve = 0UL;
56775+#endif
56776+
56777+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56778+ current->mm->call_syscall = 0UL;
56779+#endif
56780+
56781+#ifdef CONFIG_PAX_ASLR
56782+ current->mm->delta_mmap = 0UL;
56783+ current->mm->delta_stack = 0UL;
56784+#endif
56785+
56786+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56787+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56788+ send_sig(SIGKILL, current, 0);
56789+ goto out_free_dentry;
56790+ }
56791+#endif
56792+
56793+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56794+ pax_set_initial_flags(bprm);
56795+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56796+ if (pax_set_initial_flags_func)
56797+ (pax_set_initial_flags_func)(bprm);
56798+#endif
56799+
56800+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56801+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56802+ current->mm->context.user_cs_limit = PAGE_SIZE;
56803+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56804+ }
56805+#endif
56806+
56807+#ifdef CONFIG_PAX_SEGMEXEC
56808+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56809+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56810+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56811+ pax_task_size = SEGMEXEC_TASK_SIZE;
56812+ current->mm->def_flags |= VM_NOHUGEPAGE;
56813+ } else
56814+#endif
56815+
56816+ pax_task_size = TASK_SIZE;
56817+
56818+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56819+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56820+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56821+ put_cpu();
56822+ }
56823+#endif
56824+
56825+#ifdef CONFIG_PAX_ASLR
56826+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56827+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56828+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56829+ }
56830+#endif
56831+
56832+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56833+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56834+ executable_stack = EXSTACK_DISABLE_X;
56835+ current->personality &= ~READ_IMPLIES_EXEC;
56836+ } else
56837+#endif
56838+
56839 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56840 current->personality |= READ_IMPLIES_EXEC;
56841
56842@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56843 #else
56844 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56845 #endif
56846+
56847+#ifdef CONFIG_PAX_RANDMMAP
56848+ /* PaX: randomize base address at the default exe base if requested */
56849+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56850+#ifdef CONFIG_SPARC64
56851+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56852+#else
56853+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56854+#endif
56855+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56856+ elf_flags |= MAP_FIXED;
56857+ }
56858+#endif
56859+
56860 }
56861
56862 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56863@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56864 * allowed task size. Note that p_filesz must always be
56865 * <= p_memsz so it is only necessary to check p_memsz.
56866 */
56867- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56868- elf_ppnt->p_memsz > TASK_SIZE ||
56869- TASK_SIZE - elf_ppnt->p_memsz < k) {
56870+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56871+ elf_ppnt->p_memsz > pax_task_size ||
56872+ pax_task_size - elf_ppnt->p_memsz < k) {
56873 /* set_brk can never work. Avoid overflows. */
56874 send_sig(SIGKILL, current, 0);
56875 retval = -EINVAL;
56876@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56877 goto out_free_dentry;
56878 }
56879 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56880- send_sig(SIGSEGV, current, 0);
56881- retval = -EFAULT; /* Nobody gets to see this, but.. */
56882- goto out_free_dentry;
56883+ /*
56884+ * This bss-zeroing can fail if the ELF
56885+ * file specifies odd protections. So
56886+ * we don't check the return value
56887+ */
56888 }
56889
56890+#ifdef CONFIG_PAX_RANDMMAP
56891+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56892+ unsigned long start, size, flags;
56893+ vm_flags_t vm_flags;
56894+
56895+ start = ELF_PAGEALIGN(elf_brk);
56896+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56897+ flags = MAP_FIXED | MAP_PRIVATE;
56898+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56899+
56900+ down_write(&current->mm->mmap_sem);
56901+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56902+ retval = -ENOMEM;
56903+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56904+// if (current->personality & ADDR_NO_RANDOMIZE)
56905+// vm_flags |= VM_READ | VM_MAYREAD;
56906+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56907+ retval = IS_ERR_VALUE(start) ? start : 0;
56908+ }
56909+ up_write(&current->mm->mmap_sem);
56910+ if (retval == 0)
56911+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56912+ if (retval < 0) {
56913+ send_sig(SIGKILL, current, 0);
56914+ goto out_free_dentry;
56915+ }
56916+ }
56917+#endif
56918+
56919 if (elf_interpreter) {
56920- unsigned long interp_map_addr = 0;
56921-
56922 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56923 interpreter,
56924- &interp_map_addr,
56925 load_bias);
56926 if (!IS_ERR((void *)elf_entry)) {
56927 /*
56928@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56929 * Decide what to dump of a segment, part, all or none.
56930 */
56931 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56932- unsigned long mm_flags)
56933+ unsigned long mm_flags, long signr)
56934 {
56935 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56936
56937@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56938 if (vma->vm_file == NULL)
56939 return 0;
56940
56941- if (FILTER(MAPPED_PRIVATE))
56942+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56943 goto whole;
56944
56945 /*
56946@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56947 {
56948 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56949 int i = 0;
56950- do
56951+ do {
56952 i += 2;
56953- while (auxv[i - 2] != AT_NULL);
56954+ } while (auxv[i - 2] != AT_NULL);
56955 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56956 }
56957
56958@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56959 {
56960 mm_segment_t old_fs = get_fs();
56961 set_fs(KERNEL_DS);
56962- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56963+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56964 set_fs(old_fs);
56965 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56966 }
56967@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56968 }
56969
56970 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56971- unsigned long mm_flags)
56972+ struct coredump_params *cprm)
56973 {
56974 struct vm_area_struct *vma;
56975 size_t size = 0;
56976
56977 for (vma = first_vma(current, gate_vma); vma != NULL;
56978 vma = next_vma(vma, gate_vma))
56979- size += vma_dump_size(vma, mm_flags);
56980+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56981 return size;
56982 }
56983
56984@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56985
56986 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56987
56988- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56989+ offset += elf_core_vma_data_size(gate_vma, cprm);
56990 offset += elf_core_extra_data_size();
56991 e_shoff = offset;
56992
56993@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56994 phdr.p_offset = offset;
56995 phdr.p_vaddr = vma->vm_start;
56996 phdr.p_paddr = 0;
56997- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56998+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56999 phdr.p_memsz = vma->vm_end - vma->vm_start;
57000 offset += phdr.p_filesz;
57001 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57002@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57003 unsigned long addr;
57004 unsigned long end;
57005
57006- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57007+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57008
57009 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57010 struct page *page;
57011@@ -2199,6 +2678,167 @@ out:
57012
57013 #endif /* CONFIG_ELF_CORE */
57014
57015+#ifdef CONFIG_PAX_MPROTECT
57016+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57017+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57018+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57019+ *
57020+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57021+ * basis because we want to allow the common case and not the special ones.
57022+ */
57023+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57024+{
57025+ struct elfhdr elf_h;
57026+ struct elf_phdr elf_p;
57027+ unsigned long i;
57028+ unsigned long oldflags;
57029+ bool is_textrel_rw, is_textrel_rx, is_relro;
57030+
57031+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57032+ return;
57033+
57034+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57035+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57036+
57037+#ifdef CONFIG_PAX_ELFRELOCS
57038+ /* possible TEXTREL */
57039+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57040+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57041+#else
57042+ is_textrel_rw = false;
57043+ is_textrel_rx = false;
57044+#endif
57045+
57046+ /* possible RELRO */
57047+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57048+
57049+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57050+ return;
57051+
57052+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57053+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57054+
57055+#ifdef CONFIG_PAX_ETEXECRELOCS
57056+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57057+#else
57058+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57059+#endif
57060+
57061+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57062+ !elf_check_arch(&elf_h) ||
57063+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57064+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57065+ return;
57066+
57067+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57068+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57069+ return;
57070+ switch (elf_p.p_type) {
57071+ case PT_DYNAMIC:
57072+ if (!is_textrel_rw && !is_textrel_rx)
57073+ continue;
57074+ i = 0UL;
57075+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57076+ elf_dyn dyn;
57077+
57078+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57079+ break;
57080+ if (dyn.d_tag == DT_NULL)
57081+ break;
57082+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57083+ gr_log_textrel(vma);
57084+ if (is_textrel_rw)
57085+ vma->vm_flags |= VM_MAYWRITE;
57086+ else
57087+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57088+ vma->vm_flags &= ~VM_MAYWRITE;
57089+ break;
57090+ }
57091+ i++;
57092+ }
57093+ is_textrel_rw = false;
57094+ is_textrel_rx = false;
57095+ continue;
57096+
57097+ case PT_GNU_RELRO:
57098+ if (!is_relro)
57099+ continue;
57100+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57101+ vma->vm_flags &= ~VM_MAYWRITE;
57102+ is_relro = false;
57103+ continue;
57104+
57105+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57106+ case PT_PAX_FLAGS: {
57107+ const char *msg_mprotect = "", *msg_emutramp = "";
57108+ char *buffer_lib, *buffer_exe;
57109+
57110+ if (elf_p.p_flags & PF_NOMPROTECT)
57111+ msg_mprotect = "MPROTECT disabled";
57112+
57113+#ifdef CONFIG_PAX_EMUTRAMP
57114+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57115+ msg_emutramp = "EMUTRAMP enabled";
57116+#endif
57117+
57118+ if (!msg_mprotect[0] && !msg_emutramp[0])
57119+ continue;
57120+
57121+ if (!printk_ratelimit())
57122+ continue;
57123+
57124+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57125+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57126+ if (buffer_lib && buffer_exe) {
57127+ char *path_lib, *path_exe;
57128+
57129+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57130+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57131+
57132+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57133+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57134+
57135+ }
57136+ free_page((unsigned long)buffer_exe);
57137+ free_page((unsigned long)buffer_lib);
57138+ continue;
57139+ }
57140+#endif
57141+
57142+ }
57143+ }
57144+}
57145+#endif
57146+
57147+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57148+
57149+extern int grsec_enable_log_rwxmaps;
57150+
57151+static void elf_handle_mmap(struct file *file)
57152+{
57153+ struct elfhdr elf_h;
57154+ struct elf_phdr elf_p;
57155+ unsigned long i;
57156+
57157+ if (!grsec_enable_log_rwxmaps)
57158+ return;
57159+
57160+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57161+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57162+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57163+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57164+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57165+ return;
57166+
57167+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57168+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57169+ return;
57170+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57171+ gr_log_ptgnustack(file);
57172+ }
57173+}
57174+#endif
57175+
57176 static int __init init_elf_binfmt(void)
57177 {
57178 register_binfmt(&elf_format);
57179diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
57180index d50bbe5..af3b649 100644
57181--- a/fs/binfmt_flat.c
57182+++ b/fs/binfmt_flat.c
57183@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
57184 realdatastart = (unsigned long) -ENOMEM;
57185 printk("Unable to allocate RAM for process data, errno %d\n",
57186 (int)-realdatastart);
57187+ down_write(&current->mm->mmap_sem);
57188 vm_munmap(textpos, text_len);
57189+ up_write(&current->mm->mmap_sem);
57190 ret = realdatastart;
57191 goto err;
57192 }
57193@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57194 }
57195 if (IS_ERR_VALUE(result)) {
57196 printk("Unable to read data+bss, errno %d\n", (int)-result);
57197+ down_write(&current->mm->mmap_sem);
57198 vm_munmap(textpos, text_len);
57199 vm_munmap(realdatastart, len);
57200+ up_write(&current->mm->mmap_sem);
57201 ret = result;
57202 goto err;
57203 }
57204@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57205 }
57206 if (IS_ERR_VALUE(result)) {
57207 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
57208+ down_write(&current->mm->mmap_sem);
57209 vm_munmap(textpos, text_len + data_len + extra +
57210 MAX_SHARED_LIBS * sizeof(unsigned long));
57211+ up_write(&current->mm->mmap_sem);
57212 ret = result;
57213 goto err;
57214 }
57215diff --git a/fs/bio.c b/fs/bio.c
57216index 8754e7b..0669094 100644
57217--- a/fs/bio.c
57218+++ b/fs/bio.c
57219@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57220 /*
57221 * Overflow, abort
57222 */
57223- if (end < start)
57224+ if (end < start || end - start > INT_MAX - nr_pages)
57225 return ERR_PTR(-EINVAL);
57226
57227 nr_pages += end - start;
57228@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57229 /*
57230 * Overflow, abort
57231 */
57232- if (end < start)
57233+ if (end < start || end - start > INT_MAX - nr_pages)
57234 return ERR_PTR(-EINVAL);
57235
57236 nr_pages += end - start;
57237@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57238 const int read = bio_data_dir(bio) == READ;
57239 struct bio_map_data *bmd = bio->bi_private;
57240 int i;
57241- char *p = bmd->sgvecs[0].iov_base;
57242+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57243
57244 bio_for_each_segment_all(bvec, bio, i) {
57245 char *addr = page_address(bvec->bv_page);
57246diff --git a/fs/block_dev.c b/fs/block_dev.c
57247index 1e86823..8e34695 100644
57248--- a/fs/block_dev.c
57249+++ b/fs/block_dev.c
57250@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57251 else if (bdev->bd_contains == bdev)
57252 return true; /* is a whole device which isn't held */
57253
57254- else if (whole->bd_holder == bd_may_claim)
57255+ else if (whole->bd_holder == (void *)bd_may_claim)
57256 return true; /* is a partition of a device that is being partitioned */
57257 else if (whole->bd_holder != NULL)
57258 return false; /* is a partition of a held device */
57259diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57260index cbd3a7d..c6a2881 100644
57261--- a/fs/btrfs/ctree.c
57262+++ b/fs/btrfs/ctree.c
57263@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57264 free_extent_buffer(buf);
57265 add_root_to_dirty_list(root);
57266 } else {
57267- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57268- parent_start = parent->start;
57269- else
57270+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57271+ if (parent)
57272+ parent_start = parent->start;
57273+ else
57274+ parent_start = 0;
57275+ } else
57276 parent_start = 0;
57277
57278 WARN_ON(trans->transid != btrfs_header_generation(parent));
57279diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57280index 451b00c..a2cccee 100644
57281--- a/fs/btrfs/delayed-inode.c
57282+++ b/fs/btrfs/delayed-inode.c
57283@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57284
57285 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57286 {
57287- int seq = atomic_inc_return(&delayed_root->items_seq);
57288+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57289 if ((atomic_dec_return(&delayed_root->items) <
57290 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57291 waitqueue_active(&delayed_root->wait))
57292@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57293
57294 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57295 {
57296- int val = atomic_read(&delayed_root->items_seq);
57297+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57298
57299 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57300 return 1;
57301@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57302 int seq;
57303 int ret;
57304
57305- seq = atomic_read(&delayed_root->items_seq);
57306+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57307
57308 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57309 if (ret)
57310diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57311index f70119f..ab5894d 100644
57312--- a/fs/btrfs/delayed-inode.h
57313+++ b/fs/btrfs/delayed-inode.h
57314@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57315 */
57316 struct list_head prepare_list;
57317 atomic_t items; /* for delayed items */
57318- atomic_t items_seq; /* for delayed items */
57319+ atomic_unchecked_t items_seq; /* for delayed items */
57320 int nodes; /* for delayed nodes */
57321 wait_queue_head_t wait;
57322 };
57323@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57324 struct btrfs_delayed_root *delayed_root)
57325 {
57326 atomic_set(&delayed_root->items, 0);
57327- atomic_set(&delayed_root->items_seq, 0);
57328+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57329 delayed_root->nodes = 0;
57330 spin_lock_init(&delayed_root->lock);
57331 init_waitqueue_head(&delayed_root->wait);
57332diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57333index a6d8efa..2f062cf 100644
57334--- a/fs/btrfs/ioctl.c
57335+++ b/fs/btrfs/ioctl.c
57336@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57337 for (i = 0; i < num_types; i++) {
57338 struct btrfs_space_info *tmp;
57339
57340+ /* Don't copy in more than we allocated */
57341 if (!slot_count)
57342 break;
57343
57344+ slot_count--;
57345+
57346 info = NULL;
57347 rcu_read_lock();
57348 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57349@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57350 memcpy(dest, &space, sizeof(space));
57351 dest++;
57352 space_args.total_spaces++;
57353- slot_count--;
57354 }
57355- if (!slot_count)
57356- break;
57357 }
57358 up_read(&info->groups_sem);
57359 }
57360diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57361index d04db81..96e54f1 100644
57362--- a/fs/btrfs/super.c
57363+++ b/fs/btrfs/super.c
57364@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57365 function, line, errstr);
57366 return;
57367 }
57368- ACCESS_ONCE(trans->transaction->aborted) = errno;
57369+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57370 /* Wake up anybody who may be waiting on this transaction */
57371 wake_up(&root->fs_info->transaction_wait);
57372 wake_up(&root->fs_info->transaction_blocked_wait);
57373diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57374index 865f4cf..f321e86 100644
57375--- a/fs/btrfs/sysfs.c
57376+++ b/fs/btrfs/sysfs.c
57377@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57378 for (set = 0; set < FEAT_MAX; set++) {
57379 int i;
57380 struct attribute *attrs[2];
57381- struct attribute_group agroup = {
57382+ attribute_group_no_const agroup = {
57383 .name = "features",
57384 .attrs = attrs,
57385 };
57386diff --git a/fs/buffer.c b/fs/buffer.c
57387index 27265a8..289f488 100644
57388--- a/fs/buffer.c
57389+++ b/fs/buffer.c
57390@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57391 bh_cachep = kmem_cache_create("buffer_head",
57392 sizeof(struct buffer_head), 0,
57393 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57394- SLAB_MEM_SPREAD),
57395+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57396 NULL);
57397
57398 /*
57399diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57400index 622f469..e8d2d55 100644
57401--- a/fs/cachefiles/bind.c
57402+++ b/fs/cachefiles/bind.c
57403@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57404 args);
57405
57406 /* start by checking things over */
57407- ASSERT(cache->fstop_percent >= 0 &&
57408- cache->fstop_percent < cache->fcull_percent &&
57409+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57410 cache->fcull_percent < cache->frun_percent &&
57411 cache->frun_percent < 100);
57412
57413- ASSERT(cache->bstop_percent >= 0 &&
57414- cache->bstop_percent < cache->bcull_percent &&
57415+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57416 cache->bcull_percent < cache->brun_percent &&
57417 cache->brun_percent < 100);
57418
57419diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57420index 0a1467b..6a53245 100644
57421--- a/fs/cachefiles/daemon.c
57422+++ b/fs/cachefiles/daemon.c
57423@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57424 if (n > buflen)
57425 return -EMSGSIZE;
57426
57427- if (copy_to_user(_buffer, buffer, n) != 0)
57428+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57429 return -EFAULT;
57430
57431 return n;
57432@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57433 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57434 return -EIO;
57435
57436- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57437+ if (datalen > PAGE_SIZE - 1)
57438 return -EOPNOTSUPP;
57439
57440 /* drag the command string into the kernel so we can parse it */
57441@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57442 if (args[0] != '%' || args[1] != '\0')
57443 return -EINVAL;
57444
57445- if (fstop < 0 || fstop >= cache->fcull_percent)
57446+ if (fstop >= cache->fcull_percent)
57447 return cachefiles_daemon_range_error(cache, args);
57448
57449 cache->fstop_percent = fstop;
57450@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57451 if (args[0] != '%' || args[1] != '\0')
57452 return -EINVAL;
57453
57454- if (bstop < 0 || bstop >= cache->bcull_percent)
57455+ if (bstop >= cache->bcull_percent)
57456 return cachefiles_daemon_range_error(cache, args);
57457
57458 cache->bstop_percent = bstop;
57459diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57460index 5349473..d6c0b93 100644
57461--- a/fs/cachefiles/internal.h
57462+++ b/fs/cachefiles/internal.h
57463@@ -59,7 +59,7 @@ struct cachefiles_cache {
57464 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57465 struct rb_root active_nodes; /* active nodes (can't be culled) */
57466 rwlock_t active_lock; /* lock for active_nodes */
57467- atomic_t gravecounter; /* graveyard uniquifier */
57468+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57469 unsigned frun_percent; /* when to stop culling (% files) */
57470 unsigned fcull_percent; /* when to start culling (% files) */
57471 unsigned fstop_percent; /* when to stop allocating (% files) */
57472@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57473 * proc.c
57474 */
57475 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57476-extern atomic_t cachefiles_lookup_histogram[HZ];
57477-extern atomic_t cachefiles_mkdir_histogram[HZ];
57478-extern atomic_t cachefiles_create_histogram[HZ];
57479+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57480+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57481+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57482
57483 extern int __init cachefiles_proc_init(void);
57484 extern void cachefiles_proc_cleanup(void);
57485 static inline
57486-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57487+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57488 {
57489 unsigned long jif = jiffies - start_jif;
57490 if (jif >= HZ)
57491 jif = HZ - 1;
57492- atomic_inc(&histogram[jif]);
57493+ atomic_inc_unchecked(&histogram[jif]);
57494 }
57495
57496 #else
57497diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57498index ca65f39..48921e3 100644
57499--- a/fs/cachefiles/namei.c
57500+++ b/fs/cachefiles/namei.c
57501@@ -317,7 +317,7 @@ try_again:
57502 /* first step is to make up a grave dentry in the graveyard */
57503 sprintf(nbuffer, "%08x%08x",
57504 (uint32_t) get_seconds(),
57505- (uint32_t) atomic_inc_return(&cache->gravecounter));
57506+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57507
57508 /* do the multiway lock magic */
57509 trap = lock_rename(cache->graveyard, dir);
57510diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57511index eccd339..4c1d995 100644
57512--- a/fs/cachefiles/proc.c
57513+++ b/fs/cachefiles/proc.c
57514@@ -14,9 +14,9 @@
57515 #include <linux/seq_file.h>
57516 #include "internal.h"
57517
57518-atomic_t cachefiles_lookup_histogram[HZ];
57519-atomic_t cachefiles_mkdir_histogram[HZ];
57520-atomic_t cachefiles_create_histogram[HZ];
57521+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57522+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57523+atomic_unchecked_t cachefiles_create_histogram[HZ];
57524
57525 /*
57526 * display the latency histogram
57527@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57528 return 0;
57529 default:
57530 index = (unsigned long) v - 3;
57531- x = atomic_read(&cachefiles_lookup_histogram[index]);
57532- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57533- z = atomic_read(&cachefiles_create_histogram[index]);
57534+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57535+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57536+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57537 if (x == 0 && y == 0 && z == 0)
57538 return 0;
57539
57540diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57541index ebaff36..7e3ea26 100644
57542--- a/fs/cachefiles/rdwr.c
57543+++ b/fs/cachefiles/rdwr.c
57544@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57545 old_fs = get_fs();
57546 set_fs(KERNEL_DS);
57547 ret = file->f_op->write(
57548- file, (const void __user *) data, len, &pos);
57549+ file, (const void __force_user *) data, len, &pos);
57550 set_fs(old_fs);
57551 kunmap(page);
57552 file_end_write(file);
57553diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57554index 45eda6d..9126f7f 100644
57555--- a/fs/ceph/dir.c
57556+++ b/fs/ceph/dir.c
57557@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57558 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57559 struct ceph_mds_client *mdsc = fsc->mdsc;
57560 unsigned frag = fpos_frag(ctx->pos);
57561- int off = fpos_off(ctx->pos);
57562+ unsigned int off = fpos_off(ctx->pos);
57563 int err;
57564 u32 ftype;
57565 struct ceph_mds_reply_info_parsed *rinfo;
57566diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57567index 10a4ccb..92dbc5e 100644
57568--- a/fs/ceph/super.c
57569+++ b/fs/ceph/super.c
57570@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57571 /*
57572 * construct our own bdi so we can control readahead, etc.
57573 */
57574-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57575+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57576
57577 static int ceph_register_bdi(struct super_block *sb,
57578 struct ceph_fs_client *fsc)
57579@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57580 default_backing_dev_info.ra_pages;
57581
57582 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57583- atomic_long_inc_return(&bdi_seq));
57584+ atomic_long_inc_return_unchecked(&bdi_seq));
57585 if (!err)
57586 sb->s_bdi = &fsc->backing_dev_info;
57587 return err;
57588diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57589index f3ac415..3d2420c 100644
57590--- a/fs/cifs/cifs_debug.c
57591+++ b/fs/cifs/cifs_debug.c
57592@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57593
57594 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57595 #ifdef CONFIG_CIFS_STATS2
57596- atomic_set(&totBufAllocCount, 0);
57597- atomic_set(&totSmBufAllocCount, 0);
57598+ atomic_set_unchecked(&totBufAllocCount, 0);
57599+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57600 #endif /* CONFIG_CIFS_STATS2 */
57601 spin_lock(&cifs_tcp_ses_lock);
57602 list_for_each(tmp1, &cifs_tcp_ses_list) {
57603@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57604 tcon = list_entry(tmp3,
57605 struct cifs_tcon,
57606 tcon_list);
57607- atomic_set(&tcon->num_smbs_sent, 0);
57608+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57609 if (server->ops->clear_stats)
57610 server->ops->clear_stats(tcon);
57611 }
57612@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57613 smBufAllocCount.counter, cifs_min_small);
57614 #ifdef CONFIG_CIFS_STATS2
57615 seq_printf(m, "Total Large %d Small %d Allocations\n",
57616- atomic_read(&totBufAllocCount),
57617- atomic_read(&totSmBufAllocCount));
57618+ atomic_read_unchecked(&totBufAllocCount),
57619+ atomic_read_unchecked(&totSmBufAllocCount));
57620 #endif /* CONFIG_CIFS_STATS2 */
57621
57622 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57623@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57624 if (tcon->need_reconnect)
57625 seq_puts(m, "\tDISCONNECTED ");
57626 seq_printf(m, "\nSMBs: %d",
57627- atomic_read(&tcon->num_smbs_sent));
57628+ atomic_read_unchecked(&tcon->num_smbs_sent));
57629 if (server->ops->print_stats)
57630 server->ops->print_stats(m, tcon);
57631 }
57632diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57633index 849f613..eae6dec 100644
57634--- a/fs/cifs/cifsfs.c
57635+++ b/fs/cifs/cifsfs.c
57636@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57637 */
57638 cifs_req_cachep = kmem_cache_create("cifs_request",
57639 CIFSMaxBufSize + max_hdr_size, 0,
57640- SLAB_HWCACHE_ALIGN, NULL);
57641+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57642 if (cifs_req_cachep == NULL)
57643 return -ENOMEM;
57644
57645@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57646 efficient to alloc 1 per page off the slab compared to 17K (5page)
57647 alloc of large cifs buffers even when page debugging is on */
57648 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57649- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57650+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57651 NULL);
57652 if (cifs_sm_req_cachep == NULL) {
57653 mempool_destroy(cifs_req_poolp);
57654@@ -1168,8 +1168,8 @@ init_cifs(void)
57655 atomic_set(&bufAllocCount, 0);
57656 atomic_set(&smBufAllocCount, 0);
57657 #ifdef CONFIG_CIFS_STATS2
57658- atomic_set(&totBufAllocCount, 0);
57659- atomic_set(&totSmBufAllocCount, 0);
57660+ atomic_set_unchecked(&totBufAllocCount, 0);
57661+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57662 #endif /* CONFIG_CIFS_STATS2 */
57663
57664 atomic_set(&midCount, 0);
57665diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57666index c0f3718..6afed7d 100644
57667--- a/fs/cifs/cifsglob.h
57668+++ b/fs/cifs/cifsglob.h
57669@@ -804,35 +804,35 @@ struct cifs_tcon {
57670 __u16 Flags; /* optional support bits */
57671 enum statusEnum tidStatus;
57672 #ifdef CONFIG_CIFS_STATS
57673- atomic_t num_smbs_sent;
57674+ atomic_unchecked_t num_smbs_sent;
57675 union {
57676 struct {
57677- atomic_t num_writes;
57678- atomic_t num_reads;
57679- atomic_t num_flushes;
57680- atomic_t num_oplock_brks;
57681- atomic_t num_opens;
57682- atomic_t num_closes;
57683- atomic_t num_deletes;
57684- atomic_t num_mkdirs;
57685- atomic_t num_posixopens;
57686- atomic_t num_posixmkdirs;
57687- atomic_t num_rmdirs;
57688- atomic_t num_renames;
57689- atomic_t num_t2renames;
57690- atomic_t num_ffirst;
57691- atomic_t num_fnext;
57692- atomic_t num_fclose;
57693- atomic_t num_hardlinks;
57694- atomic_t num_symlinks;
57695- atomic_t num_locks;
57696- atomic_t num_acl_get;
57697- atomic_t num_acl_set;
57698+ atomic_unchecked_t num_writes;
57699+ atomic_unchecked_t num_reads;
57700+ atomic_unchecked_t num_flushes;
57701+ atomic_unchecked_t num_oplock_brks;
57702+ atomic_unchecked_t num_opens;
57703+ atomic_unchecked_t num_closes;
57704+ atomic_unchecked_t num_deletes;
57705+ atomic_unchecked_t num_mkdirs;
57706+ atomic_unchecked_t num_posixopens;
57707+ atomic_unchecked_t num_posixmkdirs;
57708+ atomic_unchecked_t num_rmdirs;
57709+ atomic_unchecked_t num_renames;
57710+ atomic_unchecked_t num_t2renames;
57711+ atomic_unchecked_t num_ffirst;
57712+ atomic_unchecked_t num_fnext;
57713+ atomic_unchecked_t num_fclose;
57714+ atomic_unchecked_t num_hardlinks;
57715+ atomic_unchecked_t num_symlinks;
57716+ atomic_unchecked_t num_locks;
57717+ atomic_unchecked_t num_acl_get;
57718+ atomic_unchecked_t num_acl_set;
57719 } cifs_stats;
57720 #ifdef CONFIG_CIFS_SMB2
57721 struct {
57722- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57723- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57724+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57725+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57726 } smb2_stats;
57727 #endif /* CONFIG_CIFS_SMB2 */
57728 } stats;
57729@@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
57730 }
57731
57732 #ifdef CONFIG_CIFS_STATS
57733-#define cifs_stats_inc atomic_inc
57734+#define cifs_stats_inc atomic_inc_unchecked
57735
57736 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57737 unsigned int bytes)
57738@@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57739 /* Various Debug counters */
57740 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57741 #ifdef CONFIG_CIFS_STATS2
57742-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57743-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57744+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57745+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57746 #endif
57747 GLOBAL_EXTERN atomic_t smBufAllocCount;
57748 GLOBAL_EXTERN atomic_t midCount;
57749diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57750index 834fce7..8a314b5 100644
57751--- a/fs/cifs/file.c
57752+++ b/fs/cifs/file.c
57753@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57754 index = mapping->writeback_index; /* Start from prev offset */
57755 end = -1;
57756 } else {
57757- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57758- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57759- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57760+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57761 range_whole = true;
57762+ index = 0;
57763+ end = ULONG_MAX;
57764+ } else {
57765+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57766+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57767+ }
57768 scanned = true;
57769 }
57770 retry:
57771diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57772index 2f9f379..43f8025 100644
57773--- a/fs/cifs/misc.c
57774+++ b/fs/cifs/misc.c
57775@@ -170,7 +170,7 @@ cifs_buf_get(void)
57776 memset(ret_buf, 0, buf_size + 3);
57777 atomic_inc(&bufAllocCount);
57778 #ifdef CONFIG_CIFS_STATS2
57779- atomic_inc(&totBufAllocCount);
57780+ atomic_inc_unchecked(&totBufAllocCount);
57781 #endif /* CONFIG_CIFS_STATS2 */
57782 }
57783
57784@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57785 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57786 atomic_inc(&smBufAllocCount);
57787 #ifdef CONFIG_CIFS_STATS2
57788- atomic_inc(&totSmBufAllocCount);
57789+ atomic_inc_unchecked(&totSmBufAllocCount);
57790 #endif /* CONFIG_CIFS_STATS2 */
57791
57792 }
57793diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57794index 526fb89..ecdbf5a 100644
57795--- a/fs/cifs/smb1ops.c
57796+++ b/fs/cifs/smb1ops.c
57797@@ -616,27 +616,27 @@ static void
57798 cifs_clear_stats(struct cifs_tcon *tcon)
57799 {
57800 #ifdef CONFIG_CIFS_STATS
57801- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57802- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57803- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57804- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57805- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57806- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57807- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57808- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57809- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57810- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57811- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57812- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57813- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57814- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57815- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57816- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57817- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57818- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57819- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57820- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57821- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57822+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57823+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57824+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57825+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57826+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57827+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57828+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57829+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57830+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57831+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57832+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57833+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57834+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57835+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57836+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57837+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57838+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57839+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57840+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57841+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57842+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57843 #endif
57844 }
57845
57846@@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57847 {
57848 #ifdef CONFIG_CIFS_STATS
57849 seq_printf(m, " Oplocks breaks: %d",
57850- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57851+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57852 seq_printf(m, "\nReads: %d Bytes: %llu",
57853- atomic_read(&tcon->stats.cifs_stats.num_reads),
57854+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57855 (long long)(tcon->bytes_read));
57856 seq_printf(m, "\nWrites: %d Bytes: %llu",
57857- atomic_read(&tcon->stats.cifs_stats.num_writes),
57858+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57859 (long long)(tcon->bytes_written));
57860 seq_printf(m, "\nFlushes: %d",
57861- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57862+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57863 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57864- atomic_read(&tcon->stats.cifs_stats.num_locks),
57865- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57866- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57867+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57868+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57869+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57870 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57871- atomic_read(&tcon->stats.cifs_stats.num_opens),
57872- atomic_read(&tcon->stats.cifs_stats.num_closes),
57873- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57874+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57875+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57876+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57877 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57878- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57879- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57880+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57881+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57882 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57883- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57884- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57885+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57886+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57887 seq_printf(m, "\nRenames: %d T2 Renames %d",
57888- atomic_read(&tcon->stats.cifs_stats.num_renames),
57889- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57890+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57891+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57892 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57893- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57894- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57895- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57897+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57898+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57899 #endif
57900 }
57901
57902diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57903index 192f51a..539307e 100644
57904--- a/fs/cifs/smb2ops.c
57905+++ b/fs/cifs/smb2ops.c
57906@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57907 #ifdef CONFIG_CIFS_STATS
57908 int i;
57909 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57910- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57911- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57912+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57913+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57914 }
57915 #endif
57916 }
57917@@ -405,65 +405,65 @@ static void
57918 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57919 {
57920 #ifdef CONFIG_CIFS_STATS
57921- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57922- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57923+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57924+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57925 seq_printf(m, "\nNegotiates: %d sent %d failed",
57926- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57927- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57928+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57929+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57930 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57931- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57932- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57933+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57934+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57935 seq_printf(m, "\nLogoffs: %d sent %d failed",
57936- atomic_read(&sent[SMB2_LOGOFF_HE]),
57937- atomic_read(&failed[SMB2_LOGOFF_HE]));
57938+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57939+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57940 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57941- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57942- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57943+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57944+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57945 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57946- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57947- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57948+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57949+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57950 seq_printf(m, "\nCreates: %d sent %d failed",
57951- atomic_read(&sent[SMB2_CREATE_HE]),
57952- atomic_read(&failed[SMB2_CREATE_HE]));
57953+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57954+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57955 seq_printf(m, "\nCloses: %d sent %d failed",
57956- atomic_read(&sent[SMB2_CLOSE_HE]),
57957- atomic_read(&failed[SMB2_CLOSE_HE]));
57958+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57959+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57960 seq_printf(m, "\nFlushes: %d sent %d failed",
57961- atomic_read(&sent[SMB2_FLUSH_HE]),
57962- atomic_read(&failed[SMB2_FLUSH_HE]));
57963+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57964+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57965 seq_printf(m, "\nReads: %d sent %d failed",
57966- atomic_read(&sent[SMB2_READ_HE]),
57967- atomic_read(&failed[SMB2_READ_HE]));
57968+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57969+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57970 seq_printf(m, "\nWrites: %d sent %d failed",
57971- atomic_read(&sent[SMB2_WRITE_HE]),
57972- atomic_read(&failed[SMB2_WRITE_HE]));
57973+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57974+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57975 seq_printf(m, "\nLocks: %d sent %d failed",
57976- atomic_read(&sent[SMB2_LOCK_HE]),
57977- atomic_read(&failed[SMB2_LOCK_HE]));
57978+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57979+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57980 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57981- atomic_read(&sent[SMB2_IOCTL_HE]),
57982- atomic_read(&failed[SMB2_IOCTL_HE]));
57983+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57984+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57985 seq_printf(m, "\nCancels: %d sent %d failed",
57986- atomic_read(&sent[SMB2_CANCEL_HE]),
57987- atomic_read(&failed[SMB2_CANCEL_HE]));
57988+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57989+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57990 seq_printf(m, "\nEchos: %d sent %d failed",
57991- atomic_read(&sent[SMB2_ECHO_HE]),
57992- atomic_read(&failed[SMB2_ECHO_HE]));
57993+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57994+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57995 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57996- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57997- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57998+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57999+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58000 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58001- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58002- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58003+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58004+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58005 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58006- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58007- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58008+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58009+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58010 seq_printf(m, "\nSetInfos: %d sent %d failed",
58011- atomic_read(&sent[SMB2_SET_INFO_HE]),
58012- atomic_read(&failed[SMB2_SET_INFO_HE]));
58013+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58014+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58015 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58016- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58017- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58018+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58019+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58020 #endif
58021 }
58022
58023diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58024index 8603447..f9caeee 100644
58025--- a/fs/cifs/smb2pdu.c
58026+++ b/fs/cifs/smb2pdu.c
58027@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58028 default:
58029 cifs_dbg(VFS, "info level %u isn't supported\n",
58030 srch_inf->info_level);
58031- rc = -EINVAL;
58032- goto qdir_exit;
58033+ return -EINVAL;
58034 }
58035
58036 req->FileIndex = cpu_to_le32(index);
58037diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58038index 1da168c..8bc7ff6 100644
58039--- a/fs/coda/cache.c
58040+++ b/fs/coda/cache.c
58041@@ -24,7 +24,7 @@
58042 #include "coda_linux.h"
58043 #include "coda_cache.h"
58044
58045-static atomic_t permission_epoch = ATOMIC_INIT(0);
58046+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58047
58048 /* replace or extend an acl cache hit */
58049 void coda_cache_enter(struct inode *inode, int mask)
58050@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58051 struct coda_inode_info *cii = ITOC(inode);
58052
58053 spin_lock(&cii->c_lock);
58054- cii->c_cached_epoch = atomic_read(&permission_epoch);
58055+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58056 if (!uid_eq(cii->c_uid, current_fsuid())) {
58057 cii->c_uid = current_fsuid();
58058 cii->c_cached_perm = mask;
58059@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58060 {
58061 struct coda_inode_info *cii = ITOC(inode);
58062 spin_lock(&cii->c_lock);
58063- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58064+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58065 spin_unlock(&cii->c_lock);
58066 }
58067
58068 /* remove all acl caches */
58069 void coda_cache_clear_all(struct super_block *sb)
58070 {
58071- atomic_inc(&permission_epoch);
58072+ atomic_inc_unchecked(&permission_epoch);
58073 }
58074
58075
58076@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58077 spin_lock(&cii->c_lock);
58078 hit = (mask & cii->c_cached_perm) == mask &&
58079 uid_eq(cii->c_uid, current_fsuid()) &&
58080- cii->c_cached_epoch == atomic_read(&permission_epoch);
58081+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58082 spin_unlock(&cii->c_lock);
58083
58084 return hit;
58085diff --git a/fs/compat.c b/fs/compat.c
58086index 6af20de..fec3fbb 100644
58087--- a/fs/compat.c
58088+++ b/fs/compat.c
58089@@ -54,7 +54,7 @@
58090 #include <asm/ioctls.h>
58091 #include "internal.h"
58092
58093-int compat_log = 1;
58094+int compat_log = 0;
58095
58096 int compat_printk(const char *fmt, ...)
58097 {
58098@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58099
58100 set_fs(KERNEL_DS);
58101 /* The __user pointer cast is valid because of the set_fs() */
58102- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58103+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58104 set_fs(oldfs);
58105 /* truncating is ok because it's a user address */
58106 if (!ret)
58107@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58108 goto out;
58109
58110 ret = -EINVAL;
58111- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58112+ if (nr_segs > UIO_MAXIOV)
58113 goto out;
58114 if (nr_segs > fast_segs) {
58115 ret = -ENOMEM;
58116@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58117 struct compat_readdir_callback {
58118 struct dir_context ctx;
58119 struct compat_old_linux_dirent __user *dirent;
58120+ struct file * file;
58121 int result;
58122 };
58123
58124@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58125 buf->result = -EOVERFLOW;
58126 return -EOVERFLOW;
58127 }
58128+
58129+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58130+ return 0;
58131+
58132 buf->result++;
58133 dirent = buf->dirent;
58134 if (!access_ok(VERIFY_WRITE, dirent,
58135@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58136 if (!f.file)
58137 return -EBADF;
58138
58139+ buf.file = f.file;
58140 error = iterate_dir(f.file, &buf.ctx);
58141 if (buf.result)
58142 error = buf.result;
58143@@ -901,6 +907,7 @@ struct compat_getdents_callback {
58144 struct dir_context ctx;
58145 struct compat_linux_dirent __user *current_dir;
58146 struct compat_linux_dirent __user *previous;
58147+ struct file * file;
58148 int count;
58149 int error;
58150 };
58151@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58152 buf->error = -EOVERFLOW;
58153 return -EOVERFLOW;
58154 }
58155+
58156+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58157+ return 0;
58158+
58159 dirent = buf->previous;
58160 if (dirent) {
58161 if (__put_user(offset, &dirent->d_off))
58162@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58163 if (!f.file)
58164 return -EBADF;
58165
58166+ buf.file = f.file;
58167 error = iterate_dir(f.file, &buf.ctx);
58168 if (error >= 0)
58169 error = buf.error;
58170@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58171 struct dir_context ctx;
58172 struct linux_dirent64 __user *current_dir;
58173 struct linux_dirent64 __user *previous;
58174+ struct file * file;
58175 int count;
58176 int error;
58177 };
58178@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58179 buf->error = -EINVAL; /* only used if we fail.. */
58180 if (reclen > buf->count)
58181 return -EINVAL;
58182+
58183+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58184+ return 0;
58185+
58186 dirent = buf->previous;
58187
58188 if (dirent) {
58189@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58190 if (!f.file)
58191 return -EBADF;
58192
58193+ buf.file = f.file;
58194 error = iterate_dir(f.file, &buf.ctx);
58195 if (error >= 0)
58196 error = buf.error;
58197diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58198index a81147e..20bf2b5 100644
58199--- a/fs/compat_binfmt_elf.c
58200+++ b/fs/compat_binfmt_elf.c
58201@@ -30,11 +30,13 @@
58202 #undef elf_phdr
58203 #undef elf_shdr
58204 #undef elf_note
58205+#undef elf_dyn
58206 #undef elf_addr_t
58207 #define elfhdr elf32_hdr
58208 #define elf_phdr elf32_phdr
58209 #define elf_shdr elf32_shdr
58210 #define elf_note elf32_note
58211+#define elf_dyn Elf32_Dyn
58212 #define elf_addr_t Elf32_Addr
58213
58214 /*
58215diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58216index 3881610..ab3df0b 100644
58217--- a/fs/compat_ioctl.c
58218+++ b/fs/compat_ioctl.c
58219@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58220 return -EFAULT;
58221 if (__get_user(udata, &ss32->iomem_base))
58222 return -EFAULT;
58223- ss.iomem_base = compat_ptr(udata);
58224+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58225 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58226 __get_user(ss.port_high, &ss32->port_high))
58227 return -EFAULT;
58228@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58229 for (i = 0; i < nmsgs; i++) {
58230 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58231 return -EFAULT;
58232- if (get_user(datap, &umsgs[i].buf) ||
58233- put_user(compat_ptr(datap), &tmsgs[i].buf))
58234+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58235+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58236 return -EFAULT;
58237 }
58238 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58239@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58240 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58241 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58242 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58243- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58244+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58245 return -EFAULT;
58246
58247 return ioctl_preallocate(file, p);
58248@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58249 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58250 {
58251 unsigned int a, b;
58252- a = *(unsigned int *)p;
58253- b = *(unsigned int *)q;
58254+ a = *(const unsigned int *)p;
58255+ b = *(const unsigned int *)q;
58256 if (a > b)
58257 return 1;
58258 if (a < b)
58259diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58260index e081acb..911df21 100644
58261--- a/fs/configfs/dir.c
58262+++ b/fs/configfs/dir.c
58263@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58264 }
58265 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58266 struct configfs_dirent *next;
58267- const char *name;
58268+ const unsigned char * name;
58269+ char d_name[sizeof(next->s_dentry->d_iname)];
58270 int len;
58271 struct inode *inode = NULL;
58272
58273@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58274 continue;
58275
58276 name = configfs_get_name(next);
58277- len = strlen(name);
58278+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58279+ len = next->s_dentry->d_name.len;
58280+ memcpy(d_name, name, len);
58281+ name = d_name;
58282+ } else
58283+ len = strlen(name);
58284
58285 /*
58286 * We'll have a dentry and an inode for
58287diff --git a/fs/coredump.c b/fs/coredump.c
58288index e3ad709..836c55f 100644
58289--- a/fs/coredump.c
58290+++ b/fs/coredump.c
58291@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58292 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58293 {
58294 int free, need;
58295+ va_list arg_copy;
58296
58297 again:
58298 free = cn->size - cn->used;
58299- need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58300+
58301+ va_copy(arg_copy, arg);
58302+ need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58303+ va_end(arg_copy);
58304+
58305 if (need < free) {
58306 cn->used += need;
58307 return 0;
58308@@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58309 struct pipe_inode_info *pipe = file->private_data;
58310
58311 pipe_lock(pipe);
58312- pipe->readers++;
58313- pipe->writers--;
58314+ atomic_inc(&pipe->readers);
58315+ atomic_dec(&pipe->writers);
58316 wake_up_interruptible_sync(&pipe->wait);
58317 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58318 pipe_unlock(pipe);
58319@@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58320 * We actually want wait_event_freezable() but then we need
58321 * to clear TIF_SIGPENDING and improve dump_interrupted().
58322 */
58323- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58324+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58325
58326 pipe_lock(pipe);
58327- pipe->readers--;
58328- pipe->writers++;
58329+ atomic_dec(&pipe->readers);
58330+ atomic_inc(&pipe->writers);
58331 pipe_unlock(pipe);
58332 }
58333
58334@@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58335 struct files_struct *displaced;
58336 bool need_nonrelative = false;
58337 bool core_dumped = false;
58338- static atomic_t core_dump_count = ATOMIC_INIT(0);
58339+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58340+ long signr = siginfo->si_signo;
58341+ int dumpable;
58342 struct coredump_params cprm = {
58343 .siginfo = siginfo,
58344 .regs = signal_pt_regs(),
58345@@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58346 .mm_flags = mm->flags,
58347 };
58348
58349- audit_core_dumps(siginfo->si_signo);
58350+ audit_core_dumps(signr);
58351+
58352+ dumpable = __get_dumpable(cprm.mm_flags);
58353+
58354+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58355+ gr_handle_brute_attach(dumpable);
58356
58357 binfmt = mm->binfmt;
58358 if (!binfmt || !binfmt->core_dump)
58359 goto fail;
58360- if (!__get_dumpable(cprm.mm_flags))
58361+ if (!dumpable)
58362 goto fail;
58363
58364 cred = prepare_creds();
58365@@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58366 need_nonrelative = true;
58367 }
58368
58369- retval = coredump_wait(siginfo->si_signo, &core_state);
58370+ retval = coredump_wait(signr, &core_state);
58371 if (retval < 0)
58372 goto fail_creds;
58373
58374@@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58375 }
58376 cprm.limit = RLIM_INFINITY;
58377
58378- dump_count = atomic_inc_return(&core_dump_count);
58379+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58380 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58381 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58382 task_tgid_vnr(current), current->comm);
58383@@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58384 } else {
58385 struct inode *inode;
58386
58387+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58388+
58389 if (cprm.limit < binfmt->min_coredump)
58390 goto fail_unlock;
58391
58392@@ -668,7 +682,7 @@ close_fail:
58393 filp_close(cprm.file, NULL);
58394 fail_dropcount:
58395 if (ispipe)
58396- atomic_dec(&core_dump_count);
58397+ atomic_dec_unchecked(&core_dump_count);
58398 fail_unlock:
58399 kfree(cn.corename);
58400 coredump_finish(mm, core_dumped);
58401@@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58402 struct file *file = cprm->file;
58403 loff_t pos = file->f_pos;
58404 ssize_t n;
58405+
58406+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58407 if (cprm->written + nr > cprm->limit)
58408 return 0;
58409 while (nr) {
58410diff --git a/fs/dcache.c b/fs/dcache.c
58411index ca02c13..7e2b581 100644
58412--- a/fs/dcache.c
58413+++ b/fs/dcache.c
58414@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58415 */
58416 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58417 if (name->len > DNAME_INLINE_LEN-1) {
58418- dname = kmalloc(name->len + 1, GFP_KERNEL);
58419+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58420 if (!dname) {
58421 kmem_cache_free(dentry_cache, dentry);
58422 return NULL;
58423@@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58424 mempages -= reserve;
58425
58426 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58427- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58428+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58429+ SLAB_NO_SANITIZE, NULL);
58430
58431 dcache_init();
58432 inode_init();
58433diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58434index 9c0444c..628490c 100644
58435--- a/fs/debugfs/inode.c
58436+++ b/fs/debugfs/inode.c
58437@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58438 */
58439 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58440 {
58441+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58442+ return __create_file(name, S_IFDIR | S_IRWXU,
58443+#else
58444 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58445+#endif
58446 parent, NULL, NULL);
58447 }
58448 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58449diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58450index b167ca4..a224e19 100644
58451--- a/fs/ecryptfs/inode.c
58452+++ b/fs/ecryptfs/inode.c
58453@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58454 old_fs = get_fs();
58455 set_fs(get_ds());
58456 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58457- (char __user *)lower_buf,
58458+ (char __force_user *)lower_buf,
58459 PATH_MAX);
58460 set_fs(old_fs);
58461 if (rc < 0)
58462diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58463index e4141f2..d8263e8 100644
58464--- a/fs/ecryptfs/miscdev.c
58465+++ b/fs/ecryptfs/miscdev.c
58466@@ -304,7 +304,7 @@ check_list:
58467 goto out_unlock_msg_ctx;
58468 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58469 if (msg_ctx->msg) {
58470- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58471+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58472 goto out_unlock_msg_ctx;
58473 i += packet_length_size;
58474 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58475diff --git a/fs/exec.c b/fs/exec.c
58476index 3d78fcc..460e2a0 100644
58477--- a/fs/exec.c
58478+++ b/fs/exec.c
58479@@ -55,8 +55,20 @@
58480 #include <linux/pipe_fs_i.h>
58481 #include <linux/oom.h>
58482 #include <linux/compat.h>
58483+#include <linux/random.h>
58484+#include <linux/seq_file.h>
58485+#include <linux/coredump.h>
58486+#include <linux/mman.h>
58487+
58488+#ifdef CONFIG_PAX_REFCOUNT
58489+#include <linux/kallsyms.h>
58490+#include <linux/kdebug.h>
58491+#endif
58492+
58493+#include <trace/events/fs.h>
58494
58495 #include <asm/uaccess.h>
58496+#include <asm/sections.h>
58497 #include <asm/mmu_context.h>
58498 #include <asm/tlb.h>
58499
58500@@ -65,19 +77,34 @@
58501
58502 #include <trace/events/sched.h>
58503
58504+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58505+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58506+{
58507+ 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");
58508+}
58509+#endif
58510+
58511+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58512+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58513+EXPORT_SYMBOL(pax_set_initial_flags_func);
58514+#endif
58515+
58516 int suid_dumpable = 0;
58517
58518 static LIST_HEAD(formats);
58519 static DEFINE_RWLOCK(binfmt_lock);
58520
58521+extern int gr_process_kernel_exec_ban(void);
58522+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58523+
58524 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58525 {
58526 BUG_ON(!fmt);
58527 if (WARN_ON(!fmt->load_binary))
58528 return;
58529 write_lock(&binfmt_lock);
58530- insert ? list_add(&fmt->lh, &formats) :
58531- list_add_tail(&fmt->lh, &formats);
58532+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58533+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58534 write_unlock(&binfmt_lock);
58535 }
58536
58537@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58538 void unregister_binfmt(struct linux_binfmt * fmt)
58539 {
58540 write_lock(&binfmt_lock);
58541- list_del(&fmt->lh);
58542+ pax_list_del((struct list_head *)&fmt->lh);
58543 write_unlock(&binfmt_lock);
58544 }
58545
58546@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58547 int write)
58548 {
58549 struct page *page;
58550- int ret;
58551
58552-#ifdef CONFIG_STACK_GROWSUP
58553- if (write) {
58554- ret = expand_downwards(bprm->vma, pos);
58555- if (ret < 0)
58556- return NULL;
58557- }
58558-#endif
58559- ret = get_user_pages(current, bprm->mm, pos,
58560- 1, write, 1, &page, NULL);
58561- if (ret <= 0)
58562+ if (0 > expand_downwards(bprm->vma, pos))
58563+ return NULL;
58564+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58565 return NULL;
58566
58567 if (write) {
58568@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58569 if (size <= ARG_MAX)
58570 return page;
58571
58572+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58573+ // only allow 512KB for argv+env on suid/sgid binaries
58574+ // to prevent easy ASLR exhaustion
58575+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58576+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58577+ (size > (512 * 1024))) {
58578+ put_page(page);
58579+ return NULL;
58580+ }
58581+#endif
58582+
58583 /*
58584 * Limit to 1/4-th the stack size for the argv+env strings.
58585 * This ensures that:
58586@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58587 vma->vm_end = STACK_TOP_MAX;
58588 vma->vm_start = vma->vm_end - PAGE_SIZE;
58589 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58590+
58591+#ifdef CONFIG_PAX_SEGMEXEC
58592+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58593+#endif
58594+
58595 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58596 INIT_LIST_HEAD(&vma->anon_vma_chain);
58597
58598@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58599 mm->stack_vm = mm->total_vm = 1;
58600 up_write(&mm->mmap_sem);
58601 bprm->p = vma->vm_end - sizeof(void *);
58602+
58603+#ifdef CONFIG_PAX_RANDUSTACK
58604+ if (randomize_va_space)
58605+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58606+#endif
58607+
58608 return 0;
58609 err:
58610 up_write(&mm->mmap_sem);
58611@@ -396,7 +437,7 @@ struct user_arg_ptr {
58612 } ptr;
58613 };
58614
58615-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58616+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58617 {
58618 const char __user *native;
58619
58620@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58621 compat_uptr_t compat;
58622
58623 if (get_user(compat, argv.ptr.compat + nr))
58624- return ERR_PTR(-EFAULT);
58625+ return (const char __force_user *)ERR_PTR(-EFAULT);
58626
58627 return compat_ptr(compat);
58628 }
58629 #endif
58630
58631 if (get_user(native, argv.ptr.native + nr))
58632- return ERR_PTR(-EFAULT);
58633+ return (const char __force_user *)ERR_PTR(-EFAULT);
58634
58635 return native;
58636 }
58637@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58638 if (!p)
58639 break;
58640
58641- if (IS_ERR(p))
58642+ if (IS_ERR((const char __force_kernel *)p))
58643 return -EFAULT;
58644
58645 if (i >= max)
58646@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58647
58648 ret = -EFAULT;
58649 str = get_user_arg_ptr(argv, argc);
58650- if (IS_ERR(str))
58651+ if (IS_ERR((const char __force_kernel *)str))
58652 goto out;
58653
58654 len = strnlen_user(str, MAX_ARG_STRLEN);
58655@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58656 int r;
58657 mm_segment_t oldfs = get_fs();
58658 struct user_arg_ptr argv = {
58659- .ptr.native = (const char __user *const __user *)__argv,
58660+ .ptr.native = (const char __user * const __force_user *)__argv,
58661 };
58662
58663 set_fs(KERNEL_DS);
58664@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58665 unsigned long new_end = old_end - shift;
58666 struct mmu_gather tlb;
58667
58668- BUG_ON(new_start > new_end);
58669+ if (new_start >= new_end || new_start < mmap_min_addr)
58670+ return -ENOMEM;
58671
58672 /*
58673 * ensure there are no vmas between where we want to go
58674@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58675 if (vma != find_vma(mm, new_start))
58676 return -EFAULT;
58677
58678+#ifdef CONFIG_PAX_SEGMEXEC
58679+ BUG_ON(pax_find_mirror_vma(vma));
58680+#endif
58681+
58682 /*
58683 * cover the whole range: [new_start, old_end)
58684 */
58685@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58686 stack_top = arch_align_stack(stack_top);
58687 stack_top = PAGE_ALIGN(stack_top);
58688
58689- if (unlikely(stack_top < mmap_min_addr) ||
58690- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58691- return -ENOMEM;
58692-
58693 stack_shift = vma->vm_end - stack_top;
58694
58695 bprm->p -= stack_shift;
58696@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58697 bprm->exec -= stack_shift;
58698
58699 down_write(&mm->mmap_sem);
58700+
58701+ /* Move stack pages down in memory. */
58702+ if (stack_shift) {
58703+ ret = shift_arg_pages(vma, stack_shift);
58704+ if (ret)
58705+ goto out_unlock;
58706+ }
58707+
58708 vm_flags = VM_STACK_FLAGS;
58709
58710+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58711+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58712+ vm_flags &= ~VM_EXEC;
58713+
58714+#ifdef CONFIG_PAX_MPROTECT
58715+ if (mm->pax_flags & MF_PAX_MPROTECT)
58716+ vm_flags &= ~VM_MAYEXEC;
58717+#endif
58718+
58719+ }
58720+#endif
58721+
58722 /*
58723 * Adjust stack execute permissions; explicitly enable for
58724 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58725@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58726 goto out_unlock;
58727 BUG_ON(prev != vma);
58728
58729- /* Move stack pages down in memory. */
58730- if (stack_shift) {
58731- ret = shift_arg_pages(vma, stack_shift);
58732- if (ret)
58733- goto out_unlock;
58734- }
58735-
58736 /* mprotect_fixup is overkill to remove the temporary stack flags */
58737 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58738
58739@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58740 #endif
58741 current->mm->start_stack = bprm->p;
58742 ret = expand_stack(vma, stack_base);
58743+
58744+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58745+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58746+ unsigned long size;
58747+ vm_flags_t vm_flags;
58748+
58749+ size = STACK_TOP - vma->vm_end;
58750+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58751+
58752+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58753+
58754+#ifdef CONFIG_X86
58755+ if (!ret) {
58756+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58757+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58758+ }
58759+#endif
58760+
58761+ }
58762+#endif
58763+
58764 if (ret)
58765 ret = -EFAULT;
58766
58767@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
58768
58769 fsnotify_open(file);
58770
58771+ trace_open_exec(name->name);
58772+
58773 err = deny_write_access(file);
58774 if (err)
58775 goto exit;
58776@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
58777 old_fs = get_fs();
58778 set_fs(get_ds());
58779 /* The cast to a user pointer is valid due to the set_fs() */
58780- result = vfs_read(file, (void __user *)addr, count, &pos);
58781+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58782 set_fs(old_fs);
58783 return result;
58784 }
58785@@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58786 }
58787 rcu_read_unlock();
58788
58789- if (p->fs->users > n_fs)
58790+ if (atomic_read(&p->fs->users) > n_fs)
58791 bprm->unsafe |= LSM_UNSAFE_SHARE;
58792 else
58793 p->fs->in_exec = 1;
58794@@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58795 return ret;
58796 }
58797
58798+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58799+static DEFINE_PER_CPU(u64, exec_counter);
58800+static int __init init_exec_counters(void)
58801+{
58802+ unsigned int cpu;
58803+
58804+ for_each_possible_cpu(cpu) {
58805+ per_cpu(exec_counter, cpu) = (u64)cpu;
58806+ }
58807+
58808+ return 0;
58809+}
58810+early_initcall(init_exec_counters);
58811+static inline void increment_exec_counter(void)
58812+{
58813+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58814+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58815+}
58816+#else
58817+static inline void increment_exec_counter(void) {}
58818+#endif
58819+
58820+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58821+ struct user_arg_ptr argv);
58822+
58823 /*
58824 * sys_execve() executes a new program.
58825 */
58826@@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
58827 struct user_arg_ptr argv,
58828 struct user_arg_ptr envp)
58829 {
58830+#ifdef CONFIG_GRKERNSEC
58831+ struct file *old_exec_file;
58832+ struct acl_subject_label *old_acl;
58833+ struct rlimit old_rlim[RLIM_NLIMITS];
58834+#endif
58835 struct linux_binprm *bprm;
58836 struct file *file;
58837 struct files_struct *displaced;
58838@@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
58839 if (IS_ERR(filename))
58840 return PTR_ERR(filename);
58841
58842+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58843+
58844 /*
58845 * We move the actual failure in case of RLIMIT_NPROC excess from
58846 * set*uid() to execve() because too many poorly written programs
58847@@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
58848 if (IS_ERR(file))
58849 goto out_unmark;
58850
58851+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58852+ retval = -EPERM;
58853+ goto out_unmark;
58854+ }
58855+
58856 sched_exec();
58857
58858 bprm->file = file;
58859 bprm->filename = bprm->interp = filename->name;
58860
58861+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58862+ retval = -EACCES;
58863+ goto out_unmark;
58864+ }
58865+
58866 retval = bprm_mm_init(bprm);
58867 if (retval)
58868 goto out_unmark;
58869@@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
58870 if (retval < 0)
58871 goto out;
58872
58873+#ifdef CONFIG_GRKERNSEC
58874+ old_acl = current->acl;
58875+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58876+ old_exec_file = current->exec_file;
58877+ get_file(file);
58878+ current->exec_file = file;
58879+#endif
58880+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58881+ /* limit suid stack to 8MB
58882+ * we saved the old limits above and will restore them if this exec fails
58883+ */
58884+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58885+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58886+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58887+#endif
58888+
58889+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58890+ retval = -EPERM;
58891+ goto out_fail;
58892+ }
58893+
58894+ if (!gr_tpe_allow(file)) {
58895+ retval = -EACCES;
58896+ goto out_fail;
58897+ }
58898+
58899+ if (gr_check_crash_exec(file)) {
58900+ retval = -EACCES;
58901+ goto out_fail;
58902+ }
58903+
58904+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58905+ bprm->unsafe);
58906+ if (retval < 0)
58907+ goto out_fail;
58908+
58909 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58910 if (retval < 0)
58911- goto out;
58912+ goto out_fail;
58913
58914 bprm->exec = bprm->p;
58915 retval = copy_strings(bprm->envc, envp, bprm);
58916 if (retval < 0)
58917- goto out;
58918+ goto out_fail;
58919
58920 retval = copy_strings(bprm->argc, argv, bprm);
58921 if (retval < 0)
58922- goto out;
58923+ goto out_fail;
58924+
58925+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58926+
58927+ gr_handle_exec_args(bprm, argv);
58928
58929 retval = exec_binprm(bprm);
58930 if (retval < 0)
58931- goto out;
58932+ goto out_fail;
58933+#ifdef CONFIG_GRKERNSEC
58934+ if (old_exec_file)
58935+ fput(old_exec_file);
58936+#endif
58937
58938 /* execve succeeded */
58939+
58940+ increment_exec_counter();
58941 current->fs->in_exec = 0;
58942 current->in_execve = 0;
58943 acct_update_integrals(current);
58944@@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
58945 put_files_struct(displaced);
58946 return retval;
58947
58948+out_fail:
58949+#ifdef CONFIG_GRKERNSEC
58950+ current->acl = old_acl;
58951+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58952+ fput(current->exec_file);
58953+ current->exec_file = old_exec_file;
58954+#endif
58955+
58956 out:
58957 if (bprm->mm) {
58958 acct_arg_size(bprm, 0);
58959@@ -1626,3 +1800,296 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58960 return compat_do_execve(getname(filename), argv, envp);
58961 }
58962 #endif
58963+
58964+int pax_check_flags(unsigned long *flags)
58965+{
58966+ int retval = 0;
58967+
58968+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58969+ if (*flags & MF_PAX_SEGMEXEC)
58970+ {
58971+ *flags &= ~MF_PAX_SEGMEXEC;
58972+ retval = -EINVAL;
58973+ }
58974+#endif
58975+
58976+ if ((*flags & MF_PAX_PAGEEXEC)
58977+
58978+#ifdef CONFIG_PAX_PAGEEXEC
58979+ && (*flags & MF_PAX_SEGMEXEC)
58980+#endif
58981+
58982+ )
58983+ {
58984+ *flags &= ~MF_PAX_PAGEEXEC;
58985+ retval = -EINVAL;
58986+ }
58987+
58988+ if ((*flags & MF_PAX_MPROTECT)
58989+
58990+#ifdef CONFIG_PAX_MPROTECT
58991+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58992+#endif
58993+
58994+ )
58995+ {
58996+ *flags &= ~MF_PAX_MPROTECT;
58997+ retval = -EINVAL;
58998+ }
58999+
59000+ if ((*flags & MF_PAX_EMUTRAMP)
59001+
59002+#ifdef CONFIG_PAX_EMUTRAMP
59003+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59004+#endif
59005+
59006+ )
59007+ {
59008+ *flags &= ~MF_PAX_EMUTRAMP;
59009+ retval = -EINVAL;
59010+ }
59011+
59012+ return retval;
59013+}
59014+
59015+EXPORT_SYMBOL(pax_check_flags);
59016+
59017+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59018+char *pax_get_path(const struct path *path, char *buf, int buflen)
59019+{
59020+ char *pathname = d_path(path, buf, buflen);
59021+
59022+ if (IS_ERR(pathname))
59023+ goto toolong;
59024+
59025+ pathname = mangle_path(buf, pathname, "\t\n\\");
59026+ if (!pathname)
59027+ goto toolong;
59028+
59029+ *pathname = 0;
59030+ return buf;
59031+
59032+toolong:
59033+ return "<path too long>";
59034+}
59035+EXPORT_SYMBOL(pax_get_path);
59036+
59037+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59038+{
59039+ struct task_struct *tsk = current;
59040+ struct mm_struct *mm = current->mm;
59041+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59042+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59043+ char *path_exec = NULL;
59044+ char *path_fault = NULL;
59045+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59046+ siginfo_t info = { };
59047+
59048+ if (buffer_exec && buffer_fault) {
59049+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59050+
59051+ down_read(&mm->mmap_sem);
59052+ vma = mm->mmap;
59053+ while (vma && (!vma_exec || !vma_fault)) {
59054+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59055+ vma_exec = vma;
59056+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59057+ vma_fault = vma;
59058+ vma = vma->vm_next;
59059+ }
59060+ if (vma_exec)
59061+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59062+ if (vma_fault) {
59063+ start = vma_fault->vm_start;
59064+ end = vma_fault->vm_end;
59065+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59066+ if (vma_fault->vm_file)
59067+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59068+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59069+ path_fault = "<heap>";
59070+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59071+ path_fault = "<stack>";
59072+ else
59073+ path_fault = "<anonymous mapping>";
59074+ }
59075+ up_read(&mm->mmap_sem);
59076+ }
59077+ if (tsk->signal->curr_ip)
59078+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59079+ else
59080+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59081+ 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),
59082+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59083+ free_page((unsigned long)buffer_exec);
59084+ free_page((unsigned long)buffer_fault);
59085+ pax_report_insns(regs, pc, sp);
59086+ info.si_signo = SIGKILL;
59087+ info.si_errno = 0;
59088+ info.si_code = SI_KERNEL;
59089+ info.si_pid = 0;
59090+ info.si_uid = 0;
59091+ do_coredump(&info);
59092+}
59093+#endif
59094+
59095+#ifdef CONFIG_PAX_REFCOUNT
59096+void pax_report_refcount_overflow(struct pt_regs *regs)
59097+{
59098+ if (current->signal->curr_ip)
59099+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59100+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59101+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59102+ else
59103+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59104+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59105+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59106+ preempt_disable();
59107+ show_regs(regs);
59108+ preempt_enable();
59109+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59110+}
59111+#endif
59112+
59113+#ifdef CONFIG_PAX_USERCOPY
59114+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59115+static noinline int check_stack_object(const void *obj, unsigned long len)
59116+{
59117+ const void * const stack = task_stack_page(current);
59118+ const void * const stackend = stack + THREAD_SIZE;
59119+
59120+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59121+ const void *frame = NULL;
59122+ const void *oldframe;
59123+#endif
59124+
59125+ if (obj + len < obj)
59126+ return -1;
59127+
59128+ if (obj + len <= stack || stackend <= obj)
59129+ return 0;
59130+
59131+ if (obj < stack || stackend < obj + len)
59132+ return -1;
59133+
59134+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59135+ oldframe = __builtin_frame_address(1);
59136+ if (oldframe)
59137+ frame = __builtin_frame_address(2);
59138+ /*
59139+ low ----------------------------------------------> high
59140+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59141+ ^----------------^
59142+ allow copies only within here
59143+ */
59144+ while (stack <= frame && frame < stackend) {
59145+ /* if obj + len extends past the last frame, this
59146+ check won't pass and the next frame will be 0,
59147+ causing us to bail out and correctly report
59148+ the copy as invalid
59149+ */
59150+ if (obj + len <= frame)
59151+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59152+ oldframe = frame;
59153+ frame = *(const void * const *)frame;
59154+ }
59155+ return -1;
59156+#else
59157+ return 1;
59158+#endif
59159+}
59160+
59161+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59162+{
59163+ if (current->signal->curr_ip)
59164+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59165+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59166+ else
59167+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59168+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59169+ dump_stack();
59170+ gr_handle_kernel_exploit();
59171+ do_group_exit(SIGKILL);
59172+}
59173+#endif
59174+
59175+#ifdef CONFIG_PAX_USERCOPY
59176+
59177+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59178+{
59179+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59180+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59181+#ifdef CONFIG_MODULES
59182+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59183+#else
59184+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59185+#endif
59186+
59187+#else
59188+ unsigned long textlow = (unsigned long)_stext;
59189+ unsigned long texthigh = (unsigned long)_etext;
59190+
59191+#ifdef CONFIG_X86_64
59192+ /* check against linear mapping as well */
59193+ if (high > (unsigned long)__va(__pa(textlow)) &&
59194+ low < (unsigned long)__va(__pa(texthigh)))
59195+ return true;
59196+#endif
59197+
59198+#endif
59199+
59200+ if (high <= textlow || low >= texthigh)
59201+ return false;
59202+ else
59203+ return true;
59204+}
59205+#endif
59206+
59207+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59208+{
59209+
59210+#ifdef CONFIG_PAX_USERCOPY
59211+ const char *type;
59212+
59213+ if (!n)
59214+ return;
59215+
59216+ type = check_heap_object(ptr, n);
59217+ if (!type) {
59218+ int ret = check_stack_object(ptr, n);
59219+ if (ret == 1 || ret == 2)
59220+ return;
59221+ if (ret == 0) {
59222+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59223+ type = "<kernel text>";
59224+ else
59225+ return;
59226+ } else
59227+ type = "<process stack>";
59228+ }
59229+
59230+ pax_report_usercopy(ptr, n, to_user, type);
59231+#endif
59232+
59233+}
59234+EXPORT_SYMBOL(__check_object_size);
59235+
59236+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59237+void pax_track_stack(void)
59238+{
59239+ unsigned long sp = (unsigned long)&sp;
59240+ if (sp < current_thread_info()->lowest_stack &&
59241+ sp > (unsigned long)task_stack_page(current))
59242+ current_thread_info()->lowest_stack = sp;
59243+}
59244+EXPORT_SYMBOL(pax_track_stack);
59245+#endif
59246+
59247+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59248+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59249+{
59250+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59251+ dump_stack();
59252+ do_group_exit(SIGKILL);
59253+}
59254+EXPORT_SYMBOL(report_size_overflow);
59255+#endif
59256diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59257index 9f9992b..8b59411 100644
59258--- a/fs/ext2/balloc.c
59259+++ b/fs/ext2/balloc.c
59260@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59261
59262 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59263 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59264- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59265+ if (free_blocks < root_blocks + 1 &&
59266 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59267 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59268- !in_group_p (sbi->s_resgid))) {
59269+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59270 return 0;
59271 }
59272 return 1;
59273diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59274index 9142614..97484fa 100644
59275--- a/fs/ext2/xattr.c
59276+++ b/fs/ext2/xattr.c
59277@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59278 struct buffer_head *bh = NULL;
59279 struct ext2_xattr_entry *entry;
59280 char *end;
59281- size_t rest = buffer_size;
59282+ size_t rest = buffer_size, total_size = 0;
59283 int error;
59284
59285 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59286@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59287 buffer += size;
59288 }
59289 rest -= size;
59290+ total_size += size;
59291 }
59292 }
59293- error = buffer_size - rest; /* total size */
59294+ error = total_size;
59295
59296 cleanup:
59297 brelse(bh);
59298diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59299index 22548f5..41521d8 100644
59300--- a/fs/ext3/balloc.c
59301+++ b/fs/ext3/balloc.c
59302@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59303
59304 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59305 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59306- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59307+ if (free_blocks < root_blocks + 1 &&
59308 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59309 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59310- !in_group_p (sbi->s_resgid))) {
59311+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59312 return 0;
59313 }
59314 return 1;
59315diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59316index c6874be..f8a6ae8 100644
59317--- a/fs/ext3/xattr.c
59318+++ b/fs/ext3/xattr.c
59319@@ -330,7 +330,7 @@ static int
59320 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59321 char *buffer, size_t buffer_size)
59322 {
59323- size_t rest = buffer_size;
59324+ size_t rest = buffer_size, total_size = 0;
59325
59326 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59327 const struct xattr_handler *handler =
59328@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59329 buffer += size;
59330 }
59331 rest -= size;
59332+ total_size += size;
59333 }
59334 }
59335- return buffer_size - rest;
59336+ return total_size;
59337 }
59338
59339 static int
59340diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59341index 6ea7b14..8fa16d9 100644
59342--- a/fs/ext4/balloc.c
59343+++ b/fs/ext4/balloc.c
59344@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59345 /* Hm, nope. Are (enough) root reserved clusters available? */
59346 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59347 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59348- capable(CAP_SYS_RESOURCE) ||
59349- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59350+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59351+ capable_nolog(CAP_SYS_RESOURCE)) {
59352
59353 if (free_clusters >= (nclusters + dirty_clusters +
59354 resv_clusters))
59355diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59356index 3a603a8..9b868ba 100644
59357--- a/fs/ext4/ext4.h
59358+++ b/fs/ext4/ext4.h
59359@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59360 unsigned long s_mb_last_start;
59361
59362 /* stats for buddy allocator */
59363- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59364- atomic_t s_bal_success; /* we found long enough chunks */
59365- atomic_t s_bal_allocated; /* in blocks */
59366- atomic_t s_bal_ex_scanned; /* total extents scanned */
59367- atomic_t s_bal_goals; /* goal hits */
59368- atomic_t s_bal_breaks; /* too long searches */
59369- atomic_t s_bal_2orders; /* 2^order hits */
59370+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59371+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59372+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59373+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59374+ atomic_unchecked_t s_bal_goals; /* goal hits */
59375+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59376+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59377 spinlock_t s_bal_lock;
59378 unsigned long s_mb_buddies_generated;
59379 unsigned long long s_mb_generation_time;
59380- atomic_t s_mb_lost_chunks;
59381- atomic_t s_mb_preallocated;
59382- atomic_t s_mb_discarded;
59383+ atomic_unchecked_t s_mb_lost_chunks;
59384+ atomic_unchecked_t s_mb_preallocated;
59385+ atomic_unchecked_t s_mb_discarded;
59386 atomic_t s_lock_busy;
59387
59388 /* locality groups */
59389diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59390index 04a5c75..09894fa 100644
59391--- a/fs/ext4/mballoc.c
59392+++ b/fs/ext4/mballoc.c
59393@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59394 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59395
59396 if (EXT4_SB(sb)->s_mb_stats)
59397- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59398+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59399
59400 break;
59401 }
59402@@ -2189,7 +2189,7 @@ repeat:
59403 ac->ac_status = AC_STATUS_CONTINUE;
59404 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59405 cr = 3;
59406- atomic_inc(&sbi->s_mb_lost_chunks);
59407+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59408 goto repeat;
59409 }
59410 }
59411@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59412 if (sbi->s_mb_stats) {
59413 ext4_msg(sb, KERN_INFO,
59414 "mballoc: %u blocks %u reqs (%u success)",
59415- atomic_read(&sbi->s_bal_allocated),
59416- atomic_read(&sbi->s_bal_reqs),
59417- atomic_read(&sbi->s_bal_success));
59418+ atomic_read_unchecked(&sbi->s_bal_allocated),
59419+ atomic_read_unchecked(&sbi->s_bal_reqs),
59420+ atomic_read_unchecked(&sbi->s_bal_success));
59421 ext4_msg(sb, KERN_INFO,
59422 "mballoc: %u extents scanned, %u goal hits, "
59423 "%u 2^N hits, %u breaks, %u lost",
59424- atomic_read(&sbi->s_bal_ex_scanned),
59425- atomic_read(&sbi->s_bal_goals),
59426- atomic_read(&sbi->s_bal_2orders),
59427- atomic_read(&sbi->s_bal_breaks),
59428- atomic_read(&sbi->s_mb_lost_chunks));
59429+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59430+ atomic_read_unchecked(&sbi->s_bal_goals),
59431+ atomic_read_unchecked(&sbi->s_bal_2orders),
59432+ atomic_read_unchecked(&sbi->s_bal_breaks),
59433+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59434 ext4_msg(sb, KERN_INFO,
59435 "mballoc: %lu generated and it took %Lu",
59436 sbi->s_mb_buddies_generated,
59437 sbi->s_mb_generation_time);
59438 ext4_msg(sb, KERN_INFO,
59439 "mballoc: %u preallocated, %u discarded",
59440- atomic_read(&sbi->s_mb_preallocated),
59441- atomic_read(&sbi->s_mb_discarded));
59442+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59443+ atomic_read_unchecked(&sbi->s_mb_discarded));
59444 }
59445
59446 free_percpu(sbi->s_locality_groups);
59447@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59448 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59449
59450 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59451- atomic_inc(&sbi->s_bal_reqs);
59452- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59453+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59454+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59455 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59456- atomic_inc(&sbi->s_bal_success);
59457- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59458+ atomic_inc_unchecked(&sbi->s_bal_success);
59459+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59460 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59461 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59462- atomic_inc(&sbi->s_bal_goals);
59463+ atomic_inc_unchecked(&sbi->s_bal_goals);
59464 if (ac->ac_found > sbi->s_mb_max_to_scan)
59465- atomic_inc(&sbi->s_bal_breaks);
59466+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59467 }
59468
59469 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59470@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59471 trace_ext4_mb_new_inode_pa(ac, pa);
59472
59473 ext4_mb_use_inode_pa(ac, pa);
59474- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59475+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59476
59477 ei = EXT4_I(ac->ac_inode);
59478 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59479@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59480 trace_ext4_mb_new_group_pa(ac, pa);
59481
59482 ext4_mb_use_group_pa(ac, pa);
59483- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59484+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59485
59486 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59487 lg = ac->ac_lg;
59488@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59489 * from the bitmap and continue.
59490 */
59491 }
59492- atomic_add(free, &sbi->s_mb_discarded);
59493+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59494
59495 return err;
59496 }
59497@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59498 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59499 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59500 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59501- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59502+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59503 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59504
59505 return 0;
59506diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59507index 04434ad..6404663 100644
59508--- a/fs/ext4/mmp.c
59509+++ b/fs/ext4/mmp.c
59510@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59511 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59512 const char *function, unsigned int line, const char *msg)
59513 {
59514- __ext4_warning(sb, function, line, msg);
59515+ __ext4_warning(sb, function, line, "%s", msg);
59516 __ext4_warning(sb, function, line,
59517 "MMP failure info: last update time: %llu, last update "
59518 "node: %s, last update device: %s\n",
59519diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59520index 710fed2..a82e4e8 100644
59521--- a/fs/ext4/super.c
59522+++ b/fs/ext4/super.c
59523@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59524 }
59525
59526 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59527-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59528+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59529 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59530
59531 #ifdef CONFIG_QUOTA
59532@@ -2450,7 +2450,7 @@ struct ext4_attr {
59533 int offset;
59534 int deprecated_val;
59535 } u;
59536-};
59537+} __do_const;
59538
59539 static int parse_strtoull(const char *buf,
59540 unsigned long long max, unsigned long long *value)
59541diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59542index 55e611c..cfad16d 100644
59543--- a/fs/ext4/xattr.c
59544+++ b/fs/ext4/xattr.c
59545@@ -381,7 +381,7 @@ static int
59546 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59547 char *buffer, size_t buffer_size)
59548 {
59549- size_t rest = buffer_size;
59550+ size_t rest = buffer_size, total_size = 0;
59551
59552 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59553 const struct xattr_handler *handler =
59554@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59555 buffer += size;
59556 }
59557 rest -= size;
59558+ total_size += size;
59559 }
59560 }
59561- return buffer_size - rest;
59562+ return total_size;
59563 }
59564
59565 static int
59566diff --git a/fs/fcntl.c b/fs/fcntl.c
59567index ef68665..5deacdc 100644
59568--- a/fs/fcntl.c
59569+++ b/fs/fcntl.c
59570@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59571 if (err)
59572 return err;
59573
59574+ if (gr_handle_chroot_fowner(pid, type))
59575+ return -ENOENT;
59576+ if (gr_check_protected_task_fowner(pid, type))
59577+ return -EACCES;
59578+
59579 f_modown(filp, pid, type, force);
59580 return 0;
59581 }
59582diff --git a/fs/fhandle.c b/fs/fhandle.c
59583index 999ff5c..41f4109 100644
59584--- a/fs/fhandle.c
59585+++ b/fs/fhandle.c
59586@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59587 } else
59588 retval = 0;
59589 /* copy the mount id */
59590- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59591- sizeof(*mnt_id)) ||
59592+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59593 copy_to_user(ufh, handle,
59594 sizeof(struct file_handle) + handle_bytes))
59595 retval = -EFAULT;
59596diff --git a/fs/file.c b/fs/file.c
59597index eb56a13..ccee850 100644
59598--- a/fs/file.c
59599+++ b/fs/file.c
59600@@ -16,6 +16,7 @@
59601 #include <linux/slab.h>
59602 #include <linux/vmalloc.h>
59603 #include <linux/file.h>
59604+#include <linux/security.h>
59605 #include <linux/fdtable.h>
59606 #include <linux/bitops.h>
59607 #include <linux/interrupt.h>
59608@@ -141,7 +142,7 @@ out:
59609 * Return <0 error code on error; 1 on successful completion.
59610 * The files->file_lock should be held on entry, and will be held on exit.
59611 */
59612-static int expand_fdtable(struct files_struct *files, int nr)
59613+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59614 __releases(files->file_lock)
59615 __acquires(files->file_lock)
59616 {
59617@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59618 * expanded and execution may have blocked.
59619 * The files->file_lock should be held on entry, and will be held on exit.
59620 */
59621-static int expand_files(struct files_struct *files, int nr)
59622+static int expand_files(struct files_struct *files, unsigned int nr)
59623 {
59624 struct fdtable *fdt;
59625
59626@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59627 if (!file)
59628 return __close_fd(files, fd);
59629
59630+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59631 if (fd >= rlimit(RLIMIT_NOFILE))
59632 return -EBADF;
59633
59634@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59635 if (unlikely(oldfd == newfd))
59636 return -EINVAL;
59637
59638+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59639 if (newfd >= rlimit(RLIMIT_NOFILE))
59640 return -EBADF;
59641
59642@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59643 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59644 {
59645 int err;
59646+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59647 if (from >= rlimit(RLIMIT_NOFILE))
59648 return -EINVAL;
59649 err = alloc_fd(from, flags);
59650diff --git a/fs/filesystems.c b/fs/filesystems.c
59651index 92567d9..fcd8cbf 100644
59652--- a/fs/filesystems.c
59653+++ b/fs/filesystems.c
59654@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59655 int len = dot ? dot - name : strlen(name);
59656
59657 fs = __get_fs_type(name, len);
59658+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59659+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59660+#else
59661 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59662+#endif
59663 fs = __get_fs_type(name, len);
59664
59665 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59666diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59667index 7dca743..543d620 100644
59668--- a/fs/fs_struct.c
59669+++ b/fs/fs_struct.c
59670@@ -4,6 +4,7 @@
59671 #include <linux/path.h>
59672 #include <linux/slab.h>
59673 #include <linux/fs_struct.h>
59674+#include <linux/grsecurity.h>
59675 #include "internal.h"
59676
59677 /*
59678@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59679 write_seqcount_begin(&fs->seq);
59680 old_root = fs->root;
59681 fs->root = *path;
59682+ gr_set_chroot_entries(current, path);
59683 write_seqcount_end(&fs->seq);
59684 spin_unlock(&fs->lock);
59685 if (old_root.dentry)
59686@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59687 int hits = 0;
59688 spin_lock(&fs->lock);
59689 write_seqcount_begin(&fs->seq);
59690+ /* this root replacement is only done by pivot_root,
59691+ leave grsec's chroot tagging alone for this task
59692+ so that a pivoted root isn't treated as a chroot
59693+ */
59694 hits += replace_path(&fs->root, old_root, new_root);
59695 hits += replace_path(&fs->pwd, old_root, new_root);
59696 write_seqcount_end(&fs->seq);
59697@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59698 task_lock(tsk);
59699 spin_lock(&fs->lock);
59700 tsk->fs = NULL;
59701- kill = !--fs->users;
59702+ gr_clear_chroot_entries(tsk);
59703+ kill = !atomic_dec_return(&fs->users);
59704 spin_unlock(&fs->lock);
59705 task_unlock(tsk);
59706 if (kill)
59707@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59708 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59709 /* We don't need to lock fs - think why ;-) */
59710 if (fs) {
59711- fs->users = 1;
59712+ atomic_set(&fs->users, 1);
59713 fs->in_exec = 0;
59714 spin_lock_init(&fs->lock);
59715 seqcount_init(&fs->seq);
59716@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59717 spin_lock(&old->lock);
59718 fs->root = old->root;
59719 path_get(&fs->root);
59720+ /* instead of calling gr_set_chroot_entries here,
59721+ we call it from every caller of this function
59722+ */
59723 fs->pwd = old->pwd;
59724 path_get(&fs->pwd);
59725 spin_unlock(&old->lock);
59726@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59727
59728 task_lock(current);
59729 spin_lock(&fs->lock);
59730- kill = !--fs->users;
59731+ kill = !atomic_dec_return(&fs->users);
59732 current->fs = new_fs;
59733+ gr_set_chroot_entries(current, &new_fs->root);
59734 spin_unlock(&fs->lock);
59735 task_unlock(current);
59736
59737@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59738
59739 int current_umask(void)
59740 {
59741- return current->fs->umask;
59742+ return current->fs->umask | gr_acl_umask();
59743 }
59744 EXPORT_SYMBOL(current_umask);
59745
59746 /* to be mentioned only in INIT_TASK */
59747 struct fs_struct init_fs = {
59748- .users = 1,
59749+ .users = ATOMIC_INIT(1),
59750 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59751 .seq = SEQCNT_ZERO(init_fs.seq),
59752 .umask = 0022,
59753diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59754index 29d7feb..303644d 100644
59755--- a/fs/fscache/cookie.c
59756+++ b/fs/fscache/cookie.c
59757@@ -19,7 +19,7 @@
59758
59759 struct kmem_cache *fscache_cookie_jar;
59760
59761-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59762+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59763
59764 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59765 static int fscache_alloc_object(struct fscache_cache *cache,
59766@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59767 parent ? (char *) parent->def->name : "<no-parent>",
59768 def->name, netfs_data, enable);
59769
59770- fscache_stat(&fscache_n_acquires);
59771+ fscache_stat_unchecked(&fscache_n_acquires);
59772
59773 /* if there's no parent cookie, then we don't create one here either */
59774 if (!parent) {
59775- fscache_stat(&fscache_n_acquires_null);
59776+ fscache_stat_unchecked(&fscache_n_acquires_null);
59777 _leave(" [no parent]");
59778 return NULL;
59779 }
59780@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59781 /* allocate and initialise a cookie */
59782 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59783 if (!cookie) {
59784- fscache_stat(&fscache_n_acquires_oom);
59785+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59786 _leave(" [ENOMEM]");
59787 return NULL;
59788 }
59789@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59790
59791 switch (cookie->def->type) {
59792 case FSCACHE_COOKIE_TYPE_INDEX:
59793- fscache_stat(&fscache_n_cookie_index);
59794+ fscache_stat_unchecked(&fscache_n_cookie_index);
59795 break;
59796 case FSCACHE_COOKIE_TYPE_DATAFILE:
59797- fscache_stat(&fscache_n_cookie_data);
59798+ fscache_stat_unchecked(&fscache_n_cookie_data);
59799 break;
59800 default:
59801- fscache_stat(&fscache_n_cookie_special);
59802+ fscache_stat_unchecked(&fscache_n_cookie_special);
59803 break;
59804 }
59805
59806@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59807 } else {
59808 atomic_dec(&parent->n_children);
59809 __fscache_cookie_put(cookie);
59810- fscache_stat(&fscache_n_acquires_nobufs);
59811+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59812 _leave(" = NULL");
59813 return NULL;
59814 }
59815@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59816 }
59817 }
59818
59819- fscache_stat(&fscache_n_acquires_ok);
59820+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59821 _leave(" = %p", cookie);
59822 return cookie;
59823 }
59824@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59825 cache = fscache_select_cache_for_object(cookie->parent);
59826 if (!cache) {
59827 up_read(&fscache_addremove_sem);
59828- fscache_stat(&fscache_n_acquires_no_cache);
59829+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59830 _leave(" = -ENOMEDIUM [no cache]");
59831 return -ENOMEDIUM;
59832 }
59833@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59834 object = cache->ops->alloc_object(cache, cookie);
59835 fscache_stat_d(&fscache_n_cop_alloc_object);
59836 if (IS_ERR(object)) {
59837- fscache_stat(&fscache_n_object_no_alloc);
59838+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59839 ret = PTR_ERR(object);
59840 goto error;
59841 }
59842
59843- fscache_stat(&fscache_n_object_alloc);
59844+ fscache_stat_unchecked(&fscache_n_object_alloc);
59845
59846- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59847+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59848
59849 _debug("ALLOC OBJ%x: %s {%lx}",
59850 object->debug_id, cookie->def->name, object->events);
59851@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59852
59853 _enter("{%s}", cookie->def->name);
59854
59855- fscache_stat(&fscache_n_invalidates);
59856+ fscache_stat_unchecked(&fscache_n_invalidates);
59857
59858 /* Only permit invalidation of data files. Invalidating an index will
59859 * require the caller to release all its attachments to the tree rooted
59860@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59861 {
59862 struct fscache_object *object;
59863
59864- fscache_stat(&fscache_n_updates);
59865+ fscache_stat_unchecked(&fscache_n_updates);
59866
59867 if (!cookie) {
59868- fscache_stat(&fscache_n_updates_null);
59869+ fscache_stat_unchecked(&fscache_n_updates_null);
59870 _leave(" [no cookie]");
59871 return;
59872 }
59873@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59874 */
59875 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59876 {
59877- fscache_stat(&fscache_n_relinquishes);
59878+ fscache_stat_unchecked(&fscache_n_relinquishes);
59879 if (retire)
59880- fscache_stat(&fscache_n_relinquishes_retire);
59881+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59882
59883 if (!cookie) {
59884- fscache_stat(&fscache_n_relinquishes_null);
59885+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59886 _leave(" [no cookie]");
59887 return;
59888 }
59889@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59890 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59891 goto inconsistent;
59892
59893- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59894+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59895
59896 __fscache_use_cookie(cookie);
59897 if (fscache_submit_op(object, op) < 0)
59898diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59899index 4226f66..0fb3f45 100644
59900--- a/fs/fscache/internal.h
59901+++ b/fs/fscache/internal.h
59902@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59903 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59904 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59905 struct fscache_operation *,
59906- atomic_t *,
59907- atomic_t *,
59908+ atomic_unchecked_t *,
59909+ atomic_unchecked_t *,
59910 void (*)(struct fscache_operation *));
59911 extern void fscache_invalidate_writes(struct fscache_cookie *);
59912
59913@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59914 * stats.c
59915 */
59916 #ifdef CONFIG_FSCACHE_STATS
59917-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59918-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59919+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59920+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59921
59922-extern atomic_t fscache_n_op_pend;
59923-extern atomic_t fscache_n_op_run;
59924-extern atomic_t fscache_n_op_enqueue;
59925-extern atomic_t fscache_n_op_deferred_release;
59926-extern atomic_t fscache_n_op_release;
59927-extern atomic_t fscache_n_op_gc;
59928-extern atomic_t fscache_n_op_cancelled;
59929-extern atomic_t fscache_n_op_rejected;
59930+extern atomic_unchecked_t fscache_n_op_pend;
59931+extern atomic_unchecked_t fscache_n_op_run;
59932+extern atomic_unchecked_t fscache_n_op_enqueue;
59933+extern atomic_unchecked_t fscache_n_op_deferred_release;
59934+extern atomic_unchecked_t fscache_n_op_release;
59935+extern atomic_unchecked_t fscache_n_op_gc;
59936+extern atomic_unchecked_t fscache_n_op_cancelled;
59937+extern atomic_unchecked_t fscache_n_op_rejected;
59938
59939-extern atomic_t fscache_n_attr_changed;
59940-extern atomic_t fscache_n_attr_changed_ok;
59941-extern atomic_t fscache_n_attr_changed_nobufs;
59942-extern atomic_t fscache_n_attr_changed_nomem;
59943-extern atomic_t fscache_n_attr_changed_calls;
59944+extern atomic_unchecked_t fscache_n_attr_changed;
59945+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59946+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59947+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59948+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59949
59950-extern atomic_t fscache_n_allocs;
59951-extern atomic_t fscache_n_allocs_ok;
59952-extern atomic_t fscache_n_allocs_wait;
59953-extern atomic_t fscache_n_allocs_nobufs;
59954-extern atomic_t fscache_n_allocs_intr;
59955-extern atomic_t fscache_n_allocs_object_dead;
59956-extern atomic_t fscache_n_alloc_ops;
59957-extern atomic_t fscache_n_alloc_op_waits;
59958+extern atomic_unchecked_t fscache_n_allocs;
59959+extern atomic_unchecked_t fscache_n_allocs_ok;
59960+extern atomic_unchecked_t fscache_n_allocs_wait;
59961+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59962+extern atomic_unchecked_t fscache_n_allocs_intr;
59963+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59964+extern atomic_unchecked_t fscache_n_alloc_ops;
59965+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59966
59967-extern atomic_t fscache_n_retrievals;
59968-extern atomic_t fscache_n_retrievals_ok;
59969-extern atomic_t fscache_n_retrievals_wait;
59970-extern atomic_t fscache_n_retrievals_nodata;
59971-extern atomic_t fscache_n_retrievals_nobufs;
59972-extern atomic_t fscache_n_retrievals_intr;
59973-extern atomic_t fscache_n_retrievals_nomem;
59974-extern atomic_t fscache_n_retrievals_object_dead;
59975-extern atomic_t fscache_n_retrieval_ops;
59976-extern atomic_t fscache_n_retrieval_op_waits;
59977+extern atomic_unchecked_t fscache_n_retrievals;
59978+extern atomic_unchecked_t fscache_n_retrievals_ok;
59979+extern atomic_unchecked_t fscache_n_retrievals_wait;
59980+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59981+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59982+extern atomic_unchecked_t fscache_n_retrievals_intr;
59983+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59984+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59985+extern atomic_unchecked_t fscache_n_retrieval_ops;
59986+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59987
59988-extern atomic_t fscache_n_stores;
59989-extern atomic_t fscache_n_stores_ok;
59990-extern atomic_t fscache_n_stores_again;
59991-extern atomic_t fscache_n_stores_nobufs;
59992-extern atomic_t fscache_n_stores_oom;
59993-extern atomic_t fscache_n_store_ops;
59994-extern atomic_t fscache_n_store_calls;
59995-extern atomic_t fscache_n_store_pages;
59996-extern atomic_t fscache_n_store_radix_deletes;
59997-extern atomic_t fscache_n_store_pages_over_limit;
59998+extern atomic_unchecked_t fscache_n_stores;
59999+extern atomic_unchecked_t fscache_n_stores_ok;
60000+extern atomic_unchecked_t fscache_n_stores_again;
60001+extern atomic_unchecked_t fscache_n_stores_nobufs;
60002+extern atomic_unchecked_t fscache_n_stores_oom;
60003+extern atomic_unchecked_t fscache_n_store_ops;
60004+extern atomic_unchecked_t fscache_n_store_calls;
60005+extern atomic_unchecked_t fscache_n_store_pages;
60006+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60007+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60008
60009-extern atomic_t fscache_n_store_vmscan_not_storing;
60010-extern atomic_t fscache_n_store_vmscan_gone;
60011-extern atomic_t fscache_n_store_vmscan_busy;
60012-extern atomic_t fscache_n_store_vmscan_cancelled;
60013-extern atomic_t fscache_n_store_vmscan_wait;
60014+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60015+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60016+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60017+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60018+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60019
60020-extern atomic_t fscache_n_marks;
60021-extern atomic_t fscache_n_uncaches;
60022+extern atomic_unchecked_t fscache_n_marks;
60023+extern atomic_unchecked_t fscache_n_uncaches;
60024
60025-extern atomic_t fscache_n_acquires;
60026-extern atomic_t fscache_n_acquires_null;
60027-extern atomic_t fscache_n_acquires_no_cache;
60028-extern atomic_t fscache_n_acquires_ok;
60029-extern atomic_t fscache_n_acquires_nobufs;
60030-extern atomic_t fscache_n_acquires_oom;
60031+extern atomic_unchecked_t fscache_n_acquires;
60032+extern atomic_unchecked_t fscache_n_acquires_null;
60033+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60034+extern atomic_unchecked_t fscache_n_acquires_ok;
60035+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60036+extern atomic_unchecked_t fscache_n_acquires_oom;
60037
60038-extern atomic_t fscache_n_invalidates;
60039-extern atomic_t fscache_n_invalidates_run;
60040+extern atomic_unchecked_t fscache_n_invalidates;
60041+extern atomic_unchecked_t fscache_n_invalidates_run;
60042
60043-extern atomic_t fscache_n_updates;
60044-extern atomic_t fscache_n_updates_null;
60045-extern atomic_t fscache_n_updates_run;
60046+extern atomic_unchecked_t fscache_n_updates;
60047+extern atomic_unchecked_t fscache_n_updates_null;
60048+extern atomic_unchecked_t fscache_n_updates_run;
60049
60050-extern atomic_t fscache_n_relinquishes;
60051-extern atomic_t fscache_n_relinquishes_null;
60052-extern atomic_t fscache_n_relinquishes_waitcrt;
60053-extern atomic_t fscache_n_relinquishes_retire;
60054+extern atomic_unchecked_t fscache_n_relinquishes;
60055+extern atomic_unchecked_t fscache_n_relinquishes_null;
60056+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60057+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60058
60059-extern atomic_t fscache_n_cookie_index;
60060-extern atomic_t fscache_n_cookie_data;
60061-extern atomic_t fscache_n_cookie_special;
60062+extern atomic_unchecked_t fscache_n_cookie_index;
60063+extern atomic_unchecked_t fscache_n_cookie_data;
60064+extern atomic_unchecked_t fscache_n_cookie_special;
60065
60066-extern atomic_t fscache_n_object_alloc;
60067-extern atomic_t fscache_n_object_no_alloc;
60068-extern atomic_t fscache_n_object_lookups;
60069-extern atomic_t fscache_n_object_lookups_negative;
60070-extern atomic_t fscache_n_object_lookups_positive;
60071-extern atomic_t fscache_n_object_lookups_timed_out;
60072-extern atomic_t fscache_n_object_created;
60073-extern atomic_t fscache_n_object_avail;
60074-extern atomic_t fscache_n_object_dead;
60075+extern atomic_unchecked_t fscache_n_object_alloc;
60076+extern atomic_unchecked_t fscache_n_object_no_alloc;
60077+extern atomic_unchecked_t fscache_n_object_lookups;
60078+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60079+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60080+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60081+extern atomic_unchecked_t fscache_n_object_created;
60082+extern atomic_unchecked_t fscache_n_object_avail;
60083+extern atomic_unchecked_t fscache_n_object_dead;
60084
60085-extern atomic_t fscache_n_checkaux_none;
60086-extern atomic_t fscache_n_checkaux_okay;
60087-extern atomic_t fscache_n_checkaux_update;
60088-extern atomic_t fscache_n_checkaux_obsolete;
60089+extern atomic_unchecked_t fscache_n_checkaux_none;
60090+extern atomic_unchecked_t fscache_n_checkaux_okay;
60091+extern atomic_unchecked_t fscache_n_checkaux_update;
60092+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60093
60094 extern atomic_t fscache_n_cop_alloc_object;
60095 extern atomic_t fscache_n_cop_lookup_object;
60096@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60097 atomic_inc(stat);
60098 }
60099
60100+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60101+{
60102+ atomic_inc_unchecked(stat);
60103+}
60104+
60105 static inline void fscache_stat_d(atomic_t *stat)
60106 {
60107 atomic_dec(stat);
60108@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60109
60110 #define __fscache_stat(stat) (NULL)
60111 #define fscache_stat(stat) do {} while (0)
60112+#define fscache_stat_unchecked(stat) do {} while (0)
60113 #define fscache_stat_d(stat) do {} while (0)
60114 #endif
60115
60116diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60117index d3b4539..ed0c659 100644
60118--- a/fs/fscache/object.c
60119+++ b/fs/fscache/object.c
60120@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60121 _debug("LOOKUP \"%s\" in \"%s\"",
60122 cookie->def->name, object->cache->tag->name);
60123
60124- fscache_stat(&fscache_n_object_lookups);
60125+ fscache_stat_unchecked(&fscache_n_object_lookups);
60126 fscache_stat(&fscache_n_cop_lookup_object);
60127 ret = object->cache->ops->lookup_object(object);
60128 fscache_stat_d(&fscache_n_cop_lookup_object);
60129@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60130 if (ret == -ETIMEDOUT) {
60131 /* probably stuck behind another object, so move this one to
60132 * the back of the queue */
60133- fscache_stat(&fscache_n_object_lookups_timed_out);
60134+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60135 _leave(" [timeout]");
60136 return NO_TRANSIT;
60137 }
60138@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60139 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60140
60141 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60142- fscache_stat(&fscache_n_object_lookups_negative);
60143+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60144
60145 /* Allow write requests to begin stacking up and read requests to begin
60146 * returning ENODATA.
60147@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60148 /* if we were still looking up, then we must have a positive lookup
60149 * result, in which case there may be data available */
60150 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60151- fscache_stat(&fscache_n_object_lookups_positive);
60152+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60153
60154 /* We do (presumably) have data */
60155 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60156@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60157 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60158 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60159 } else {
60160- fscache_stat(&fscache_n_object_created);
60161+ fscache_stat_unchecked(&fscache_n_object_created);
60162 }
60163
60164 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60165@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60166 fscache_stat_d(&fscache_n_cop_lookup_complete);
60167
60168 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60169- fscache_stat(&fscache_n_object_avail);
60170+ fscache_stat_unchecked(&fscache_n_object_avail);
60171
60172 _leave("");
60173 return transit_to(JUMPSTART_DEPS);
60174@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60175
60176 /* this just shifts the object release to the work processor */
60177 fscache_put_object(object);
60178- fscache_stat(&fscache_n_object_dead);
60179+ fscache_stat_unchecked(&fscache_n_object_dead);
60180
60181 _leave("");
60182 return transit_to(OBJECT_DEAD);
60183@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60184 enum fscache_checkaux result;
60185
60186 if (!object->cookie->def->check_aux) {
60187- fscache_stat(&fscache_n_checkaux_none);
60188+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60189 return FSCACHE_CHECKAUX_OKAY;
60190 }
60191
60192@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60193 switch (result) {
60194 /* entry okay as is */
60195 case FSCACHE_CHECKAUX_OKAY:
60196- fscache_stat(&fscache_n_checkaux_okay);
60197+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60198 break;
60199
60200 /* entry requires update */
60201 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60202- fscache_stat(&fscache_n_checkaux_update);
60203+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60204 break;
60205
60206 /* entry requires deletion */
60207 case FSCACHE_CHECKAUX_OBSOLETE:
60208- fscache_stat(&fscache_n_checkaux_obsolete);
60209+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60210 break;
60211
60212 default:
60213@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60214 {
60215 const struct fscache_state *s;
60216
60217- fscache_stat(&fscache_n_invalidates_run);
60218+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60219 fscache_stat(&fscache_n_cop_invalidate_object);
60220 s = _fscache_invalidate_object(object, event);
60221 fscache_stat_d(&fscache_n_cop_invalidate_object);
60222@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60223 {
60224 _enter("{OBJ%x},%d", object->debug_id, event);
60225
60226- fscache_stat(&fscache_n_updates_run);
60227+ fscache_stat_unchecked(&fscache_n_updates_run);
60228 fscache_stat(&fscache_n_cop_update_object);
60229 object->cache->ops->update_object(object);
60230 fscache_stat_d(&fscache_n_cop_update_object);
60231diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60232index 318071a..379938b 100644
60233--- a/fs/fscache/operation.c
60234+++ b/fs/fscache/operation.c
60235@@ -17,7 +17,7 @@
60236 #include <linux/slab.h>
60237 #include "internal.h"
60238
60239-atomic_t fscache_op_debug_id;
60240+atomic_unchecked_t fscache_op_debug_id;
60241 EXPORT_SYMBOL(fscache_op_debug_id);
60242
60243 /**
60244@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60245 ASSERTCMP(atomic_read(&op->usage), >, 0);
60246 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60247
60248- fscache_stat(&fscache_n_op_enqueue);
60249+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60250 switch (op->flags & FSCACHE_OP_TYPE) {
60251 case FSCACHE_OP_ASYNC:
60252 _debug("queue async");
60253@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60254 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60255 if (op->processor)
60256 fscache_enqueue_operation(op);
60257- fscache_stat(&fscache_n_op_run);
60258+ fscache_stat_unchecked(&fscache_n_op_run);
60259 }
60260
60261 /*
60262@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60263 if (object->n_in_progress > 0) {
60264 atomic_inc(&op->usage);
60265 list_add_tail(&op->pend_link, &object->pending_ops);
60266- fscache_stat(&fscache_n_op_pend);
60267+ fscache_stat_unchecked(&fscache_n_op_pend);
60268 } else if (!list_empty(&object->pending_ops)) {
60269 atomic_inc(&op->usage);
60270 list_add_tail(&op->pend_link, &object->pending_ops);
60271- fscache_stat(&fscache_n_op_pend);
60272+ fscache_stat_unchecked(&fscache_n_op_pend);
60273 fscache_start_operations(object);
60274 } else {
60275 ASSERTCMP(object->n_in_progress, ==, 0);
60276@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60277 object->n_exclusive++; /* reads and writes must wait */
60278 atomic_inc(&op->usage);
60279 list_add_tail(&op->pend_link, &object->pending_ops);
60280- fscache_stat(&fscache_n_op_pend);
60281+ fscache_stat_unchecked(&fscache_n_op_pend);
60282 ret = 0;
60283 } else {
60284 /* If we're in any other state, there must have been an I/O
60285@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60286 if (object->n_exclusive > 0) {
60287 atomic_inc(&op->usage);
60288 list_add_tail(&op->pend_link, &object->pending_ops);
60289- fscache_stat(&fscache_n_op_pend);
60290+ fscache_stat_unchecked(&fscache_n_op_pend);
60291 } else if (!list_empty(&object->pending_ops)) {
60292 atomic_inc(&op->usage);
60293 list_add_tail(&op->pend_link, &object->pending_ops);
60294- fscache_stat(&fscache_n_op_pend);
60295+ fscache_stat_unchecked(&fscache_n_op_pend);
60296 fscache_start_operations(object);
60297 } else {
60298 ASSERTCMP(object->n_exclusive, ==, 0);
60299@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60300 object->n_ops++;
60301 atomic_inc(&op->usage);
60302 list_add_tail(&op->pend_link, &object->pending_ops);
60303- fscache_stat(&fscache_n_op_pend);
60304+ fscache_stat_unchecked(&fscache_n_op_pend);
60305 ret = 0;
60306 } else if (fscache_object_is_dying(object)) {
60307- fscache_stat(&fscache_n_op_rejected);
60308+ fscache_stat_unchecked(&fscache_n_op_rejected);
60309 op->state = FSCACHE_OP_ST_CANCELLED;
60310 ret = -ENOBUFS;
60311 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60312@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60313 ret = -EBUSY;
60314 if (op->state == FSCACHE_OP_ST_PENDING) {
60315 ASSERT(!list_empty(&op->pend_link));
60316- fscache_stat(&fscache_n_op_cancelled);
60317+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60318 list_del_init(&op->pend_link);
60319 if (do_cancel)
60320 do_cancel(op);
60321@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60322 while (!list_empty(&object->pending_ops)) {
60323 op = list_entry(object->pending_ops.next,
60324 struct fscache_operation, pend_link);
60325- fscache_stat(&fscache_n_op_cancelled);
60326+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60327 list_del_init(&op->pend_link);
60328
60329 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60330@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60331 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60332 op->state = FSCACHE_OP_ST_DEAD;
60333
60334- fscache_stat(&fscache_n_op_release);
60335+ fscache_stat_unchecked(&fscache_n_op_release);
60336
60337 if (op->release) {
60338 op->release(op);
60339@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60340 * lock, and defer it otherwise */
60341 if (!spin_trylock(&object->lock)) {
60342 _debug("defer put");
60343- fscache_stat(&fscache_n_op_deferred_release);
60344+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60345
60346 cache = object->cache;
60347 spin_lock(&cache->op_gc_list_lock);
60348@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60349
60350 _debug("GC DEFERRED REL OBJ%x OP%x",
60351 object->debug_id, op->debug_id);
60352- fscache_stat(&fscache_n_op_gc);
60353+ fscache_stat_unchecked(&fscache_n_op_gc);
60354
60355 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60356 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60357diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60358index 7f5c658..6c1e164 100644
60359--- a/fs/fscache/page.c
60360+++ b/fs/fscache/page.c
60361@@ -61,7 +61,7 @@ try_again:
60362 val = radix_tree_lookup(&cookie->stores, page->index);
60363 if (!val) {
60364 rcu_read_unlock();
60365- fscache_stat(&fscache_n_store_vmscan_not_storing);
60366+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60367 __fscache_uncache_page(cookie, page);
60368 return true;
60369 }
60370@@ -91,11 +91,11 @@ try_again:
60371 spin_unlock(&cookie->stores_lock);
60372
60373 if (xpage) {
60374- fscache_stat(&fscache_n_store_vmscan_cancelled);
60375- fscache_stat(&fscache_n_store_radix_deletes);
60376+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60377+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60378 ASSERTCMP(xpage, ==, page);
60379 } else {
60380- fscache_stat(&fscache_n_store_vmscan_gone);
60381+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60382 }
60383
60384 wake_up_bit(&cookie->flags, 0);
60385@@ -110,11 +110,11 @@ page_busy:
60386 * sleeping on memory allocation, so we may need to impose a timeout
60387 * too. */
60388 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60389- fscache_stat(&fscache_n_store_vmscan_busy);
60390+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60391 return false;
60392 }
60393
60394- fscache_stat(&fscache_n_store_vmscan_wait);
60395+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60396 __fscache_wait_on_page_write(cookie, page);
60397 gfp &= ~__GFP_WAIT;
60398 goto try_again;
60399@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60400 FSCACHE_COOKIE_STORING_TAG);
60401 if (!radix_tree_tag_get(&cookie->stores, page->index,
60402 FSCACHE_COOKIE_PENDING_TAG)) {
60403- fscache_stat(&fscache_n_store_radix_deletes);
60404+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60405 xpage = radix_tree_delete(&cookie->stores, page->index);
60406 }
60407 spin_unlock(&cookie->stores_lock);
60408@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60409
60410 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60411
60412- fscache_stat(&fscache_n_attr_changed_calls);
60413+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60414
60415 if (fscache_object_is_active(object)) {
60416 fscache_stat(&fscache_n_cop_attr_changed);
60417@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60418
60419 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60420
60421- fscache_stat(&fscache_n_attr_changed);
60422+ fscache_stat_unchecked(&fscache_n_attr_changed);
60423
60424 op = kzalloc(sizeof(*op), GFP_KERNEL);
60425 if (!op) {
60426- fscache_stat(&fscache_n_attr_changed_nomem);
60427+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60428 _leave(" = -ENOMEM");
60429 return -ENOMEM;
60430 }
60431@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60432 if (fscache_submit_exclusive_op(object, op) < 0)
60433 goto nobufs;
60434 spin_unlock(&cookie->lock);
60435- fscache_stat(&fscache_n_attr_changed_ok);
60436+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60437 fscache_put_operation(op);
60438 _leave(" = 0");
60439 return 0;
60440@@ -225,7 +225,7 @@ nobufs:
60441 kfree(op);
60442 if (wake_cookie)
60443 __fscache_wake_unused_cookie(cookie);
60444- fscache_stat(&fscache_n_attr_changed_nobufs);
60445+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60446 _leave(" = %d", -ENOBUFS);
60447 return -ENOBUFS;
60448 }
60449@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60450 /* allocate a retrieval operation and attempt to submit it */
60451 op = kzalloc(sizeof(*op), GFP_NOIO);
60452 if (!op) {
60453- fscache_stat(&fscache_n_retrievals_nomem);
60454+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60455 return NULL;
60456 }
60457
60458@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60459 return 0;
60460 }
60461
60462- fscache_stat(&fscache_n_retrievals_wait);
60463+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60464
60465 jif = jiffies;
60466 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60467 fscache_wait_bit_interruptible,
60468 TASK_INTERRUPTIBLE) != 0) {
60469- fscache_stat(&fscache_n_retrievals_intr);
60470+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60471 _leave(" = -ERESTARTSYS");
60472 return -ERESTARTSYS;
60473 }
60474@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60475 */
60476 int fscache_wait_for_operation_activation(struct fscache_object *object,
60477 struct fscache_operation *op,
60478- atomic_t *stat_op_waits,
60479- atomic_t *stat_object_dead,
60480+ atomic_unchecked_t *stat_op_waits,
60481+ atomic_unchecked_t *stat_object_dead,
60482 void (*do_cancel)(struct fscache_operation *))
60483 {
60484 int ret;
60485@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60486
60487 _debug(">>> WT");
60488 if (stat_op_waits)
60489- fscache_stat(stat_op_waits);
60490+ fscache_stat_unchecked(stat_op_waits);
60491 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60492 fscache_wait_bit_interruptible,
60493 TASK_INTERRUPTIBLE) != 0) {
60494@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60495 check_if_dead:
60496 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60497 if (stat_object_dead)
60498- fscache_stat(stat_object_dead);
60499+ fscache_stat_unchecked(stat_object_dead);
60500 _leave(" = -ENOBUFS [cancelled]");
60501 return -ENOBUFS;
60502 }
60503@@ -366,7 +366,7 @@ check_if_dead:
60504 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60505 fscache_cancel_op(op, do_cancel);
60506 if (stat_object_dead)
60507- fscache_stat(stat_object_dead);
60508+ fscache_stat_unchecked(stat_object_dead);
60509 return -ENOBUFS;
60510 }
60511 return 0;
60512@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60513
60514 _enter("%p,%p,,,", cookie, page);
60515
60516- fscache_stat(&fscache_n_retrievals);
60517+ fscache_stat_unchecked(&fscache_n_retrievals);
60518
60519 if (hlist_empty(&cookie->backing_objects))
60520 goto nobufs;
60521@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60522 goto nobufs_unlock_dec;
60523 spin_unlock(&cookie->lock);
60524
60525- fscache_stat(&fscache_n_retrieval_ops);
60526+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60527
60528 /* pin the netfs read context in case we need to do the actual netfs
60529 * read because we've encountered a cache read failure */
60530@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60531
60532 error:
60533 if (ret == -ENOMEM)
60534- fscache_stat(&fscache_n_retrievals_nomem);
60535+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60536 else if (ret == -ERESTARTSYS)
60537- fscache_stat(&fscache_n_retrievals_intr);
60538+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60539 else if (ret == -ENODATA)
60540- fscache_stat(&fscache_n_retrievals_nodata);
60541+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60542 else if (ret < 0)
60543- fscache_stat(&fscache_n_retrievals_nobufs);
60544+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60545 else
60546- fscache_stat(&fscache_n_retrievals_ok);
60547+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60548
60549 fscache_put_retrieval(op);
60550 _leave(" = %d", ret);
60551@@ -490,7 +490,7 @@ nobufs_unlock:
60552 __fscache_wake_unused_cookie(cookie);
60553 kfree(op);
60554 nobufs:
60555- fscache_stat(&fscache_n_retrievals_nobufs);
60556+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60557 _leave(" = -ENOBUFS");
60558 return -ENOBUFS;
60559 }
60560@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60561
60562 _enter("%p,,%d,,,", cookie, *nr_pages);
60563
60564- fscache_stat(&fscache_n_retrievals);
60565+ fscache_stat_unchecked(&fscache_n_retrievals);
60566
60567 if (hlist_empty(&cookie->backing_objects))
60568 goto nobufs;
60569@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60570 goto nobufs_unlock_dec;
60571 spin_unlock(&cookie->lock);
60572
60573- fscache_stat(&fscache_n_retrieval_ops);
60574+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60575
60576 /* pin the netfs read context in case we need to do the actual netfs
60577 * read because we've encountered a cache read failure */
60578@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60579
60580 error:
60581 if (ret == -ENOMEM)
60582- fscache_stat(&fscache_n_retrievals_nomem);
60583+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60584 else if (ret == -ERESTARTSYS)
60585- fscache_stat(&fscache_n_retrievals_intr);
60586+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60587 else if (ret == -ENODATA)
60588- fscache_stat(&fscache_n_retrievals_nodata);
60589+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60590 else if (ret < 0)
60591- fscache_stat(&fscache_n_retrievals_nobufs);
60592+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60593 else
60594- fscache_stat(&fscache_n_retrievals_ok);
60595+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60596
60597 fscache_put_retrieval(op);
60598 _leave(" = %d", ret);
60599@@ -621,7 +621,7 @@ nobufs_unlock:
60600 if (wake_cookie)
60601 __fscache_wake_unused_cookie(cookie);
60602 nobufs:
60603- fscache_stat(&fscache_n_retrievals_nobufs);
60604+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60605 _leave(" = -ENOBUFS");
60606 return -ENOBUFS;
60607 }
60608@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60609
60610 _enter("%p,%p,,,", cookie, page);
60611
60612- fscache_stat(&fscache_n_allocs);
60613+ fscache_stat_unchecked(&fscache_n_allocs);
60614
60615 if (hlist_empty(&cookie->backing_objects))
60616 goto nobufs;
60617@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60618 goto nobufs_unlock_dec;
60619 spin_unlock(&cookie->lock);
60620
60621- fscache_stat(&fscache_n_alloc_ops);
60622+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60623
60624 ret = fscache_wait_for_operation_activation(
60625 object, &op->op,
60626@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60627
60628 error:
60629 if (ret == -ERESTARTSYS)
60630- fscache_stat(&fscache_n_allocs_intr);
60631+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60632 else if (ret < 0)
60633- fscache_stat(&fscache_n_allocs_nobufs);
60634+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60635 else
60636- fscache_stat(&fscache_n_allocs_ok);
60637+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60638
60639 fscache_put_retrieval(op);
60640 _leave(" = %d", ret);
60641@@ -715,7 +715,7 @@ nobufs_unlock:
60642 if (wake_cookie)
60643 __fscache_wake_unused_cookie(cookie);
60644 nobufs:
60645- fscache_stat(&fscache_n_allocs_nobufs);
60646+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60647 _leave(" = -ENOBUFS");
60648 return -ENOBUFS;
60649 }
60650@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60651
60652 spin_lock(&cookie->stores_lock);
60653
60654- fscache_stat(&fscache_n_store_calls);
60655+ fscache_stat_unchecked(&fscache_n_store_calls);
60656
60657 /* find a page to store */
60658 page = NULL;
60659@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60660 page = results[0];
60661 _debug("gang %d [%lx]", n, page->index);
60662 if (page->index > op->store_limit) {
60663- fscache_stat(&fscache_n_store_pages_over_limit);
60664+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60665 goto superseded;
60666 }
60667
60668@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60669 spin_unlock(&cookie->stores_lock);
60670 spin_unlock(&object->lock);
60671
60672- fscache_stat(&fscache_n_store_pages);
60673+ fscache_stat_unchecked(&fscache_n_store_pages);
60674 fscache_stat(&fscache_n_cop_write_page);
60675 ret = object->cache->ops->write_page(op, page);
60676 fscache_stat_d(&fscache_n_cop_write_page);
60677@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60678 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60679 ASSERT(PageFsCache(page));
60680
60681- fscache_stat(&fscache_n_stores);
60682+ fscache_stat_unchecked(&fscache_n_stores);
60683
60684 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60685 _leave(" = -ENOBUFS [invalidating]");
60686@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60687 spin_unlock(&cookie->stores_lock);
60688 spin_unlock(&object->lock);
60689
60690- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60691+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60692 op->store_limit = object->store_limit;
60693
60694 __fscache_use_cookie(cookie);
60695@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60696
60697 spin_unlock(&cookie->lock);
60698 radix_tree_preload_end();
60699- fscache_stat(&fscache_n_store_ops);
60700- fscache_stat(&fscache_n_stores_ok);
60701+ fscache_stat_unchecked(&fscache_n_store_ops);
60702+ fscache_stat_unchecked(&fscache_n_stores_ok);
60703
60704 /* the work queue now carries its own ref on the object */
60705 fscache_put_operation(&op->op);
60706@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60707 return 0;
60708
60709 already_queued:
60710- fscache_stat(&fscache_n_stores_again);
60711+ fscache_stat_unchecked(&fscache_n_stores_again);
60712 already_pending:
60713 spin_unlock(&cookie->stores_lock);
60714 spin_unlock(&object->lock);
60715 spin_unlock(&cookie->lock);
60716 radix_tree_preload_end();
60717 kfree(op);
60718- fscache_stat(&fscache_n_stores_ok);
60719+ fscache_stat_unchecked(&fscache_n_stores_ok);
60720 _leave(" = 0");
60721 return 0;
60722
60723@@ -1024,14 +1024,14 @@ nobufs:
60724 kfree(op);
60725 if (wake_cookie)
60726 __fscache_wake_unused_cookie(cookie);
60727- fscache_stat(&fscache_n_stores_nobufs);
60728+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60729 _leave(" = -ENOBUFS");
60730 return -ENOBUFS;
60731
60732 nomem_free:
60733 kfree(op);
60734 nomem:
60735- fscache_stat(&fscache_n_stores_oom);
60736+ fscache_stat_unchecked(&fscache_n_stores_oom);
60737 _leave(" = -ENOMEM");
60738 return -ENOMEM;
60739 }
60740@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60741 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60742 ASSERTCMP(page, !=, NULL);
60743
60744- fscache_stat(&fscache_n_uncaches);
60745+ fscache_stat_unchecked(&fscache_n_uncaches);
60746
60747 /* cache withdrawal may beat us to it */
60748 if (!PageFsCache(page))
60749@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60750 struct fscache_cookie *cookie = op->op.object->cookie;
60751
60752 #ifdef CONFIG_FSCACHE_STATS
60753- atomic_inc(&fscache_n_marks);
60754+ atomic_inc_unchecked(&fscache_n_marks);
60755 #endif
60756
60757 _debug("- mark %p{%lx}", page, page->index);
60758diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60759index 40d13c7..ddf52b9 100644
60760--- a/fs/fscache/stats.c
60761+++ b/fs/fscache/stats.c
60762@@ -18,99 +18,99 @@
60763 /*
60764 * operation counters
60765 */
60766-atomic_t fscache_n_op_pend;
60767-atomic_t fscache_n_op_run;
60768-atomic_t fscache_n_op_enqueue;
60769-atomic_t fscache_n_op_requeue;
60770-atomic_t fscache_n_op_deferred_release;
60771-atomic_t fscache_n_op_release;
60772-atomic_t fscache_n_op_gc;
60773-atomic_t fscache_n_op_cancelled;
60774-atomic_t fscache_n_op_rejected;
60775+atomic_unchecked_t fscache_n_op_pend;
60776+atomic_unchecked_t fscache_n_op_run;
60777+atomic_unchecked_t fscache_n_op_enqueue;
60778+atomic_unchecked_t fscache_n_op_requeue;
60779+atomic_unchecked_t fscache_n_op_deferred_release;
60780+atomic_unchecked_t fscache_n_op_release;
60781+atomic_unchecked_t fscache_n_op_gc;
60782+atomic_unchecked_t fscache_n_op_cancelled;
60783+atomic_unchecked_t fscache_n_op_rejected;
60784
60785-atomic_t fscache_n_attr_changed;
60786-atomic_t fscache_n_attr_changed_ok;
60787-atomic_t fscache_n_attr_changed_nobufs;
60788-atomic_t fscache_n_attr_changed_nomem;
60789-atomic_t fscache_n_attr_changed_calls;
60790+atomic_unchecked_t fscache_n_attr_changed;
60791+atomic_unchecked_t fscache_n_attr_changed_ok;
60792+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60793+atomic_unchecked_t fscache_n_attr_changed_nomem;
60794+atomic_unchecked_t fscache_n_attr_changed_calls;
60795
60796-atomic_t fscache_n_allocs;
60797-atomic_t fscache_n_allocs_ok;
60798-atomic_t fscache_n_allocs_wait;
60799-atomic_t fscache_n_allocs_nobufs;
60800-atomic_t fscache_n_allocs_intr;
60801-atomic_t fscache_n_allocs_object_dead;
60802-atomic_t fscache_n_alloc_ops;
60803-atomic_t fscache_n_alloc_op_waits;
60804+atomic_unchecked_t fscache_n_allocs;
60805+atomic_unchecked_t fscache_n_allocs_ok;
60806+atomic_unchecked_t fscache_n_allocs_wait;
60807+atomic_unchecked_t fscache_n_allocs_nobufs;
60808+atomic_unchecked_t fscache_n_allocs_intr;
60809+atomic_unchecked_t fscache_n_allocs_object_dead;
60810+atomic_unchecked_t fscache_n_alloc_ops;
60811+atomic_unchecked_t fscache_n_alloc_op_waits;
60812
60813-atomic_t fscache_n_retrievals;
60814-atomic_t fscache_n_retrievals_ok;
60815-atomic_t fscache_n_retrievals_wait;
60816-atomic_t fscache_n_retrievals_nodata;
60817-atomic_t fscache_n_retrievals_nobufs;
60818-atomic_t fscache_n_retrievals_intr;
60819-atomic_t fscache_n_retrievals_nomem;
60820-atomic_t fscache_n_retrievals_object_dead;
60821-atomic_t fscache_n_retrieval_ops;
60822-atomic_t fscache_n_retrieval_op_waits;
60823+atomic_unchecked_t fscache_n_retrievals;
60824+atomic_unchecked_t fscache_n_retrievals_ok;
60825+atomic_unchecked_t fscache_n_retrievals_wait;
60826+atomic_unchecked_t fscache_n_retrievals_nodata;
60827+atomic_unchecked_t fscache_n_retrievals_nobufs;
60828+atomic_unchecked_t fscache_n_retrievals_intr;
60829+atomic_unchecked_t fscache_n_retrievals_nomem;
60830+atomic_unchecked_t fscache_n_retrievals_object_dead;
60831+atomic_unchecked_t fscache_n_retrieval_ops;
60832+atomic_unchecked_t fscache_n_retrieval_op_waits;
60833
60834-atomic_t fscache_n_stores;
60835-atomic_t fscache_n_stores_ok;
60836-atomic_t fscache_n_stores_again;
60837-atomic_t fscache_n_stores_nobufs;
60838-atomic_t fscache_n_stores_oom;
60839-atomic_t fscache_n_store_ops;
60840-atomic_t fscache_n_store_calls;
60841-atomic_t fscache_n_store_pages;
60842-atomic_t fscache_n_store_radix_deletes;
60843-atomic_t fscache_n_store_pages_over_limit;
60844+atomic_unchecked_t fscache_n_stores;
60845+atomic_unchecked_t fscache_n_stores_ok;
60846+atomic_unchecked_t fscache_n_stores_again;
60847+atomic_unchecked_t fscache_n_stores_nobufs;
60848+atomic_unchecked_t fscache_n_stores_oom;
60849+atomic_unchecked_t fscache_n_store_ops;
60850+atomic_unchecked_t fscache_n_store_calls;
60851+atomic_unchecked_t fscache_n_store_pages;
60852+atomic_unchecked_t fscache_n_store_radix_deletes;
60853+atomic_unchecked_t fscache_n_store_pages_over_limit;
60854
60855-atomic_t fscache_n_store_vmscan_not_storing;
60856-atomic_t fscache_n_store_vmscan_gone;
60857-atomic_t fscache_n_store_vmscan_busy;
60858-atomic_t fscache_n_store_vmscan_cancelled;
60859-atomic_t fscache_n_store_vmscan_wait;
60860+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60861+atomic_unchecked_t fscache_n_store_vmscan_gone;
60862+atomic_unchecked_t fscache_n_store_vmscan_busy;
60863+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60864+atomic_unchecked_t fscache_n_store_vmscan_wait;
60865
60866-atomic_t fscache_n_marks;
60867-atomic_t fscache_n_uncaches;
60868+atomic_unchecked_t fscache_n_marks;
60869+atomic_unchecked_t fscache_n_uncaches;
60870
60871-atomic_t fscache_n_acquires;
60872-atomic_t fscache_n_acquires_null;
60873-atomic_t fscache_n_acquires_no_cache;
60874-atomic_t fscache_n_acquires_ok;
60875-atomic_t fscache_n_acquires_nobufs;
60876-atomic_t fscache_n_acquires_oom;
60877+atomic_unchecked_t fscache_n_acquires;
60878+atomic_unchecked_t fscache_n_acquires_null;
60879+atomic_unchecked_t fscache_n_acquires_no_cache;
60880+atomic_unchecked_t fscache_n_acquires_ok;
60881+atomic_unchecked_t fscache_n_acquires_nobufs;
60882+atomic_unchecked_t fscache_n_acquires_oom;
60883
60884-atomic_t fscache_n_invalidates;
60885-atomic_t fscache_n_invalidates_run;
60886+atomic_unchecked_t fscache_n_invalidates;
60887+atomic_unchecked_t fscache_n_invalidates_run;
60888
60889-atomic_t fscache_n_updates;
60890-atomic_t fscache_n_updates_null;
60891-atomic_t fscache_n_updates_run;
60892+atomic_unchecked_t fscache_n_updates;
60893+atomic_unchecked_t fscache_n_updates_null;
60894+atomic_unchecked_t fscache_n_updates_run;
60895
60896-atomic_t fscache_n_relinquishes;
60897-atomic_t fscache_n_relinquishes_null;
60898-atomic_t fscache_n_relinquishes_waitcrt;
60899-atomic_t fscache_n_relinquishes_retire;
60900+atomic_unchecked_t fscache_n_relinquishes;
60901+atomic_unchecked_t fscache_n_relinquishes_null;
60902+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60903+atomic_unchecked_t fscache_n_relinquishes_retire;
60904
60905-atomic_t fscache_n_cookie_index;
60906-atomic_t fscache_n_cookie_data;
60907-atomic_t fscache_n_cookie_special;
60908+atomic_unchecked_t fscache_n_cookie_index;
60909+atomic_unchecked_t fscache_n_cookie_data;
60910+atomic_unchecked_t fscache_n_cookie_special;
60911
60912-atomic_t fscache_n_object_alloc;
60913-atomic_t fscache_n_object_no_alloc;
60914-atomic_t fscache_n_object_lookups;
60915-atomic_t fscache_n_object_lookups_negative;
60916-atomic_t fscache_n_object_lookups_positive;
60917-atomic_t fscache_n_object_lookups_timed_out;
60918-atomic_t fscache_n_object_created;
60919-atomic_t fscache_n_object_avail;
60920-atomic_t fscache_n_object_dead;
60921+atomic_unchecked_t fscache_n_object_alloc;
60922+atomic_unchecked_t fscache_n_object_no_alloc;
60923+atomic_unchecked_t fscache_n_object_lookups;
60924+atomic_unchecked_t fscache_n_object_lookups_negative;
60925+atomic_unchecked_t fscache_n_object_lookups_positive;
60926+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60927+atomic_unchecked_t fscache_n_object_created;
60928+atomic_unchecked_t fscache_n_object_avail;
60929+atomic_unchecked_t fscache_n_object_dead;
60930
60931-atomic_t fscache_n_checkaux_none;
60932-atomic_t fscache_n_checkaux_okay;
60933-atomic_t fscache_n_checkaux_update;
60934-atomic_t fscache_n_checkaux_obsolete;
60935+atomic_unchecked_t fscache_n_checkaux_none;
60936+atomic_unchecked_t fscache_n_checkaux_okay;
60937+atomic_unchecked_t fscache_n_checkaux_update;
60938+atomic_unchecked_t fscache_n_checkaux_obsolete;
60939
60940 atomic_t fscache_n_cop_alloc_object;
60941 atomic_t fscache_n_cop_lookup_object;
60942@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60943 seq_puts(m, "FS-Cache statistics\n");
60944
60945 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60946- atomic_read(&fscache_n_cookie_index),
60947- atomic_read(&fscache_n_cookie_data),
60948- atomic_read(&fscache_n_cookie_special));
60949+ atomic_read_unchecked(&fscache_n_cookie_index),
60950+ atomic_read_unchecked(&fscache_n_cookie_data),
60951+ atomic_read_unchecked(&fscache_n_cookie_special));
60952
60953 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60954- atomic_read(&fscache_n_object_alloc),
60955- atomic_read(&fscache_n_object_no_alloc),
60956- atomic_read(&fscache_n_object_avail),
60957- atomic_read(&fscache_n_object_dead));
60958+ atomic_read_unchecked(&fscache_n_object_alloc),
60959+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60960+ atomic_read_unchecked(&fscache_n_object_avail),
60961+ atomic_read_unchecked(&fscache_n_object_dead));
60962 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60963- atomic_read(&fscache_n_checkaux_none),
60964- atomic_read(&fscache_n_checkaux_okay),
60965- atomic_read(&fscache_n_checkaux_update),
60966- atomic_read(&fscache_n_checkaux_obsolete));
60967+ atomic_read_unchecked(&fscache_n_checkaux_none),
60968+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60969+ atomic_read_unchecked(&fscache_n_checkaux_update),
60970+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60971
60972 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60973- atomic_read(&fscache_n_marks),
60974- atomic_read(&fscache_n_uncaches));
60975+ atomic_read_unchecked(&fscache_n_marks),
60976+ atomic_read_unchecked(&fscache_n_uncaches));
60977
60978 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60979 " oom=%u\n",
60980- atomic_read(&fscache_n_acquires),
60981- atomic_read(&fscache_n_acquires_null),
60982- atomic_read(&fscache_n_acquires_no_cache),
60983- atomic_read(&fscache_n_acquires_ok),
60984- atomic_read(&fscache_n_acquires_nobufs),
60985- atomic_read(&fscache_n_acquires_oom));
60986+ atomic_read_unchecked(&fscache_n_acquires),
60987+ atomic_read_unchecked(&fscache_n_acquires_null),
60988+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60989+ atomic_read_unchecked(&fscache_n_acquires_ok),
60990+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60991+ atomic_read_unchecked(&fscache_n_acquires_oom));
60992
60993 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60994- atomic_read(&fscache_n_object_lookups),
60995- atomic_read(&fscache_n_object_lookups_negative),
60996- atomic_read(&fscache_n_object_lookups_positive),
60997- atomic_read(&fscache_n_object_created),
60998- atomic_read(&fscache_n_object_lookups_timed_out));
60999+ atomic_read_unchecked(&fscache_n_object_lookups),
61000+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61001+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61002+ atomic_read_unchecked(&fscache_n_object_created),
61003+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61004
61005 seq_printf(m, "Invals : n=%u run=%u\n",
61006- atomic_read(&fscache_n_invalidates),
61007- atomic_read(&fscache_n_invalidates_run));
61008+ atomic_read_unchecked(&fscache_n_invalidates),
61009+ atomic_read_unchecked(&fscache_n_invalidates_run));
61010
61011 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61012- atomic_read(&fscache_n_updates),
61013- atomic_read(&fscache_n_updates_null),
61014- atomic_read(&fscache_n_updates_run));
61015+ atomic_read_unchecked(&fscache_n_updates),
61016+ atomic_read_unchecked(&fscache_n_updates_null),
61017+ atomic_read_unchecked(&fscache_n_updates_run));
61018
61019 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61020- atomic_read(&fscache_n_relinquishes),
61021- atomic_read(&fscache_n_relinquishes_null),
61022- atomic_read(&fscache_n_relinquishes_waitcrt),
61023- atomic_read(&fscache_n_relinquishes_retire));
61024+ atomic_read_unchecked(&fscache_n_relinquishes),
61025+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61026+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61027+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61028
61029 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61030- atomic_read(&fscache_n_attr_changed),
61031- atomic_read(&fscache_n_attr_changed_ok),
61032- atomic_read(&fscache_n_attr_changed_nobufs),
61033- atomic_read(&fscache_n_attr_changed_nomem),
61034- atomic_read(&fscache_n_attr_changed_calls));
61035+ atomic_read_unchecked(&fscache_n_attr_changed),
61036+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61037+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61038+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61039+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61040
61041 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61042- atomic_read(&fscache_n_allocs),
61043- atomic_read(&fscache_n_allocs_ok),
61044- atomic_read(&fscache_n_allocs_wait),
61045- atomic_read(&fscache_n_allocs_nobufs),
61046- atomic_read(&fscache_n_allocs_intr));
61047+ atomic_read_unchecked(&fscache_n_allocs),
61048+ atomic_read_unchecked(&fscache_n_allocs_ok),
61049+ atomic_read_unchecked(&fscache_n_allocs_wait),
61050+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61051+ atomic_read_unchecked(&fscache_n_allocs_intr));
61052 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61053- atomic_read(&fscache_n_alloc_ops),
61054- atomic_read(&fscache_n_alloc_op_waits),
61055- atomic_read(&fscache_n_allocs_object_dead));
61056+ atomic_read_unchecked(&fscache_n_alloc_ops),
61057+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61058+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61059
61060 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61061 " int=%u oom=%u\n",
61062- atomic_read(&fscache_n_retrievals),
61063- atomic_read(&fscache_n_retrievals_ok),
61064- atomic_read(&fscache_n_retrievals_wait),
61065- atomic_read(&fscache_n_retrievals_nodata),
61066- atomic_read(&fscache_n_retrievals_nobufs),
61067- atomic_read(&fscache_n_retrievals_intr),
61068- atomic_read(&fscache_n_retrievals_nomem));
61069+ atomic_read_unchecked(&fscache_n_retrievals),
61070+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61071+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61072+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61073+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61074+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61075+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61076 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61077- atomic_read(&fscache_n_retrieval_ops),
61078- atomic_read(&fscache_n_retrieval_op_waits),
61079- atomic_read(&fscache_n_retrievals_object_dead));
61080+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61081+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61082+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61083
61084 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61085- atomic_read(&fscache_n_stores),
61086- atomic_read(&fscache_n_stores_ok),
61087- atomic_read(&fscache_n_stores_again),
61088- atomic_read(&fscache_n_stores_nobufs),
61089- atomic_read(&fscache_n_stores_oom));
61090+ atomic_read_unchecked(&fscache_n_stores),
61091+ atomic_read_unchecked(&fscache_n_stores_ok),
61092+ atomic_read_unchecked(&fscache_n_stores_again),
61093+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61094+ atomic_read_unchecked(&fscache_n_stores_oom));
61095 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61096- atomic_read(&fscache_n_store_ops),
61097- atomic_read(&fscache_n_store_calls),
61098- atomic_read(&fscache_n_store_pages),
61099- atomic_read(&fscache_n_store_radix_deletes),
61100- atomic_read(&fscache_n_store_pages_over_limit));
61101+ atomic_read_unchecked(&fscache_n_store_ops),
61102+ atomic_read_unchecked(&fscache_n_store_calls),
61103+ atomic_read_unchecked(&fscache_n_store_pages),
61104+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61105+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61106
61107 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61108- atomic_read(&fscache_n_store_vmscan_not_storing),
61109- atomic_read(&fscache_n_store_vmscan_gone),
61110- atomic_read(&fscache_n_store_vmscan_busy),
61111- atomic_read(&fscache_n_store_vmscan_cancelled),
61112- atomic_read(&fscache_n_store_vmscan_wait));
61113+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61114+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61115+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61116+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61117+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61118
61119 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61120- atomic_read(&fscache_n_op_pend),
61121- atomic_read(&fscache_n_op_run),
61122- atomic_read(&fscache_n_op_enqueue),
61123- atomic_read(&fscache_n_op_cancelled),
61124- atomic_read(&fscache_n_op_rejected));
61125+ atomic_read_unchecked(&fscache_n_op_pend),
61126+ atomic_read_unchecked(&fscache_n_op_run),
61127+ atomic_read_unchecked(&fscache_n_op_enqueue),
61128+ atomic_read_unchecked(&fscache_n_op_cancelled),
61129+ atomic_read_unchecked(&fscache_n_op_rejected));
61130 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61131- atomic_read(&fscache_n_op_deferred_release),
61132- atomic_read(&fscache_n_op_release),
61133- atomic_read(&fscache_n_op_gc));
61134+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61135+ atomic_read_unchecked(&fscache_n_op_release),
61136+ atomic_read_unchecked(&fscache_n_op_gc));
61137
61138 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61139 atomic_read(&fscache_n_cop_alloc_object),
61140diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61141index b96a49b..9bfdc47 100644
61142--- a/fs/fuse/cuse.c
61143+++ b/fs/fuse/cuse.c
61144@@ -606,10 +606,12 @@ static int __init cuse_init(void)
61145 INIT_LIST_HEAD(&cuse_conntbl[i]);
61146
61147 /* inherit and extend fuse_dev_operations */
61148- cuse_channel_fops = fuse_dev_operations;
61149- cuse_channel_fops.owner = THIS_MODULE;
61150- cuse_channel_fops.open = cuse_channel_open;
61151- cuse_channel_fops.release = cuse_channel_release;
61152+ pax_open_kernel();
61153+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61154+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61155+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61156+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61157+ pax_close_kernel();
61158
61159 cuse_class = class_create(THIS_MODULE, "cuse");
61160 if (IS_ERR(cuse_class))
61161diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61162index 0a648bb..8d463f1 100644
61163--- a/fs/fuse/dev.c
61164+++ b/fs/fuse/dev.c
61165@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61166 ret = 0;
61167 pipe_lock(pipe);
61168
61169- if (!pipe->readers) {
61170+ if (!atomic_read(&pipe->readers)) {
61171 send_sig(SIGPIPE, current, 0);
61172 if (!ret)
61173 ret = -EPIPE;
61174@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61175 page_nr++;
61176 ret += buf->len;
61177
61178- if (pipe->files)
61179+ if (atomic_read(&pipe->files))
61180 do_wakeup = 1;
61181 }
61182
61183diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61184index 1d1292c..bba17ea 100644
61185--- a/fs/fuse/dir.c
61186+++ b/fs/fuse/dir.c
61187@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61188 return link;
61189 }
61190
61191-static void free_link(char *link)
61192+static void free_link(const char *link)
61193 {
61194 if (!IS_ERR(link))
61195 free_page((unsigned long) link);
61196diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61197index fe649d3..c679164 100644
61198--- a/fs/hostfs/hostfs_kern.c
61199+++ b/fs/hostfs/hostfs_kern.c
61200@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61201
61202 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61203 {
61204- char *s = nd_get_link(nd);
61205+ const char *s = nd_get_link(nd);
61206 if (!IS_ERR(s))
61207 __putname(s);
61208 }
61209diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61210index d19b30a..ef89c36 100644
61211--- a/fs/hugetlbfs/inode.c
61212+++ b/fs/hugetlbfs/inode.c
61213@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61214 struct mm_struct *mm = current->mm;
61215 struct vm_area_struct *vma;
61216 struct hstate *h = hstate_file(file);
61217+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61218 struct vm_unmapped_area_info info;
61219
61220 if (len & ~huge_page_mask(h))
61221@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61222 return addr;
61223 }
61224
61225+#ifdef CONFIG_PAX_RANDMMAP
61226+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61227+#endif
61228+
61229 if (addr) {
61230 addr = ALIGN(addr, huge_page_size(h));
61231 vma = find_vma(mm, addr);
61232- if (TASK_SIZE - len >= addr &&
61233- (!vma || addr + len <= vma->vm_start))
61234+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61235 return addr;
61236 }
61237
61238 info.flags = 0;
61239 info.length = len;
61240 info.low_limit = TASK_UNMAPPED_BASE;
61241+
61242+#ifdef CONFIG_PAX_RANDMMAP
61243+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61244+ info.low_limit += mm->delta_mmap;
61245+#endif
61246+
61247 info.high_limit = TASK_SIZE;
61248 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61249 info.align_offset = 0;
61250@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61251 };
61252 MODULE_ALIAS_FS("hugetlbfs");
61253
61254-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61255+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61256
61257 static int can_do_hugetlb_shm(void)
61258 {
61259diff --git a/fs/inode.c b/fs/inode.c
61260index 4bcdad3..1883822 100644
61261--- a/fs/inode.c
61262+++ b/fs/inode.c
61263@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61264
61265 #ifdef CONFIG_SMP
61266 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61267- static atomic_t shared_last_ino;
61268- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61269+ static atomic_unchecked_t shared_last_ino;
61270+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61271
61272 res = next - LAST_INO_BATCH;
61273 }
61274diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61275index 4a6cf28..d3a29d3 100644
61276--- a/fs/jffs2/erase.c
61277+++ b/fs/jffs2/erase.c
61278@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61279 struct jffs2_unknown_node marker = {
61280 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61281 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61282- .totlen = cpu_to_je32(c->cleanmarker_size)
61283+ .totlen = cpu_to_je32(c->cleanmarker_size),
61284+ .hdr_crc = cpu_to_je32(0)
61285 };
61286
61287 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61288diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61289index a6597d6..41b30ec 100644
61290--- a/fs/jffs2/wbuf.c
61291+++ b/fs/jffs2/wbuf.c
61292@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61293 {
61294 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61295 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61296- .totlen = constant_cpu_to_je32(8)
61297+ .totlen = constant_cpu_to_je32(8),
61298+ .hdr_crc = constant_cpu_to_je32(0)
61299 };
61300
61301 /*
61302diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61303index e2b7483..855bca3 100644
61304--- a/fs/jfs/super.c
61305+++ b/fs/jfs/super.c
61306@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61307
61308 jfs_inode_cachep =
61309 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61310- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61311+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61312 init_once);
61313 if (jfs_inode_cachep == NULL)
61314 return -ENOMEM;
61315diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61316index 39c0143..d54fad4 100644
61317--- a/fs/kernfs/dir.c
61318+++ b/fs/kernfs/dir.c
61319@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61320 *
61321 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61322 */
61323-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61324+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61325 {
61326 unsigned long hash = init_name_hash();
61327 unsigned int len = strlen(name);
61328diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61329index dbf397b..d624b48 100644
61330--- a/fs/kernfs/file.c
61331+++ b/fs/kernfs/file.c
61332@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61333
61334 struct kernfs_open_node {
61335 atomic_t refcnt;
61336- atomic_t event;
61337+ atomic_unchecked_t event;
61338 wait_queue_head_t poll;
61339 struct list_head files; /* goes through kernfs_open_file.list */
61340 };
61341@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61342 {
61343 struct kernfs_open_file *of = sf->private;
61344
61345- of->event = atomic_read(&of->kn->attr.open->event);
61346+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61347
61348 return of->kn->attr.ops->seq_show(sf, v);
61349 }
61350@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61351 return ret;
61352 }
61353
61354-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61355- void *buf, int len, int write)
61356+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61357+ void *buf, size_t len, int write)
61358 {
61359 struct file *file = vma->vm_file;
61360 struct kernfs_open_file *of = kernfs_of(file);
61361- int ret;
61362+ ssize_t ret;
61363
61364 if (!of->vm_ops)
61365 return -EINVAL;
61366@@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61367 return -ENOMEM;
61368
61369 atomic_set(&new_on->refcnt, 0);
61370- atomic_set(&new_on->event, 1);
61371+ atomic_set_unchecked(&new_on->event, 1);
61372 init_waitqueue_head(&new_on->poll);
61373 INIT_LIST_HEAD(&new_on->files);
61374 goto retry;
61375@@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61376
61377 kernfs_put_active(kn);
61378
61379- if (of->event != atomic_read(&on->event))
61380+ if (of->event != atomic_read_unchecked(&on->event))
61381 goto trigger;
61382
61383 return DEFAULT_POLLMASK;
61384@@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61385 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61386 on = kn->attr.open;
61387 if (on) {
61388- atomic_inc(&on->event);
61389+ atomic_inc_unchecked(&on->event);
61390 wake_up_interruptible(&on->poll);
61391 }
61392 }
61393diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61394index 4d45705..b35e0bd 100644
61395--- a/fs/kernfs/symlink.c
61396+++ b/fs/kernfs/symlink.c
61397@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61398 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61399 void *cookie)
61400 {
61401- char *page = nd_get_link(nd);
61402+ const char *page = nd_get_link(nd);
61403 if (!IS_ERR(page))
61404 free_page((unsigned long)page);
61405 }
61406diff --git a/fs/libfs.c b/fs/libfs.c
61407index a184424..944ddce 100644
61408--- a/fs/libfs.c
61409+++ b/fs/libfs.c
61410@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61411
61412 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61413 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61414+ char d_name[sizeof(next->d_iname)];
61415+ const unsigned char *name;
61416+
61417 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61418 if (!simple_positive(next)) {
61419 spin_unlock(&next->d_lock);
61420@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61421
61422 spin_unlock(&next->d_lock);
61423 spin_unlock(&dentry->d_lock);
61424- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61425+ name = next->d_name.name;
61426+ if (name == next->d_iname) {
61427+ memcpy(d_name, name, next->d_name.len);
61428+ name = d_name;
61429+ }
61430+ if (!dir_emit(ctx, name, next->d_name.len,
61431 next->d_inode->i_ino, dt_type(next->d_inode)))
61432 return 0;
61433 spin_lock(&dentry->d_lock);
61434@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61435 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61436 void *cookie)
61437 {
61438- char *s = nd_get_link(nd);
61439+ const char *s = nd_get_link(nd);
61440 if (!IS_ERR(s))
61441 kfree(s);
61442 }
61443diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61444index acd3947..1f896e2 100644
61445--- a/fs/lockd/clntproc.c
61446+++ b/fs/lockd/clntproc.c
61447@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61448 /*
61449 * Cookie counter for NLM requests
61450 */
61451-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61452+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61453
61454 void nlmclnt_next_cookie(struct nlm_cookie *c)
61455 {
61456- u32 cookie = atomic_inc_return(&nlm_cookie);
61457+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61458
61459 memcpy(c->data, &cookie, 4);
61460 c->len=4;
61461diff --git a/fs/locks.c b/fs/locks.c
61462index 92a0f0a..45a48f0 100644
61463--- a/fs/locks.c
61464+++ b/fs/locks.c
61465@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61466 return;
61467
61468 if (filp->f_op->flock) {
61469- struct file_lock fl = {
61470+ struct file_lock flock = {
61471 .fl_pid = current->tgid,
61472 .fl_file = filp,
61473 .fl_flags = FL_FLOCK,
61474 .fl_type = F_UNLCK,
61475 .fl_end = OFFSET_MAX,
61476 };
61477- filp->f_op->flock(filp, F_SETLKW, &fl);
61478- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61479- fl.fl_ops->fl_release_private(&fl);
61480+ filp->f_op->flock(filp, F_SETLKW, &flock);
61481+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61482+ flock.fl_ops->fl_release_private(&flock);
61483 }
61484
61485 spin_lock(&inode->i_lock);
61486diff --git a/fs/mount.h b/fs/mount.h
61487index b29e42f..5ea7fdf 100644
61488--- a/fs/mount.h
61489+++ b/fs/mount.h
61490@@ -11,7 +11,7 @@ struct mnt_namespace {
61491 u64 seq; /* Sequence number to prevent loops */
61492 wait_queue_head_t poll;
61493 int event;
61494-};
61495+} __randomize_layout;
61496
61497 struct mnt_pcp {
61498 int mnt_count;
61499@@ -57,7 +57,7 @@ struct mount {
61500 int mnt_expiry_mark; /* true if marked for expiry */
61501 int mnt_pinned;
61502 struct path mnt_ex_mountpoint;
61503-};
61504+} __randomize_layout;
61505
61506 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61507
61508diff --git a/fs/namei.c b/fs/namei.c
61509index 4b491b4..a0166f9 100644
61510--- a/fs/namei.c
61511+++ b/fs/namei.c
61512@@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61513 if (ret != -EACCES)
61514 return ret;
61515
61516+#ifdef CONFIG_GRKERNSEC
61517+ /* we'll block if we have to log due to a denied capability use */
61518+ if (mask & MAY_NOT_BLOCK)
61519+ return -ECHILD;
61520+#endif
61521+
61522 if (S_ISDIR(inode->i_mode)) {
61523 /* DACs are overridable for directories */
61524- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61525- return 0;
61526 if (!(mask & MAY_WRITE))
61527- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61528+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61529+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61530 return 0;
61531+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61532+ return 0;
61533 return -EACCES;
61534 }
61535 /*
61536+ * Searching includes executable on directories, else just read.
61537+ */
61538+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61539+ if (mask == MAY_READ)
61540+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61541+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61542+ return 0;
61543+
61544+ /*
61545 * Read/write DACs are always overridable.
61546 * Executable DACs are overridable when there is
61547 * at least one exec bit set.
61548@@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61549 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61550 return 0;
61551
61552- /*
61553- * Searching includes executable on directories, else just read.
61554- */
61555- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61556- if (mask == MAY_READ)
61557- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61558- return 0;
61559-
61560 return -EACCES;
61561 }
61562
61563@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61564 {
61565 struct dentry *dentry = link->dentry;
61566 int error;
61567- char *s;
61568+ const char *s;
61569
61570 BUG_ON(nd->flags & LOOKUP_RCU);
61571
61572@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61573 if (error)
61574 goto out_put_nd_path;
61575
61576+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61577+ dentry->d_inode, dentry, nd->path.mnt)) {
61578+ error = -EACCES;
61579+ goto out_put_nd_path;
61580+ }
61581+
61582 nd->last_type = LAST_BIND;
61583 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61584 error = PTR_ERR(*p);
61585@@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61586 if (res)
61587 break;
61588 res = walk_component(nd, path, LOOKUP_FOLLOW);
61589+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61590+ res = -EACCES;
61591 put_link(nd, &link, cookie);
61592 } while (res > 0);
61593
61594@@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61595 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61596 {
61597 unsigned long a, b, adata, bdata, mask, hash, len;
61598- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61599+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61600
61601 hash = a = 0;
61602 len = -sizeof(unsigned long);
61603@@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61604 if (err)
61605 break;
61606 err = lookup_last(nd, &path);
61607+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61608+ err = -EACCES;
61609 put_link(nd, &link, cookie);
61610 }
61611 }
61612@@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61613 if (!err)
61614 err = complete_walk(nd);
61615
61616+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61617+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61618+ path_put(&nd->path);
61619+ err = -ENOENT;
61620+ }
61621+ }
61622+
61623 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61624 if (!d_is_directory(nd->path.dentry)) {
61625 path_put(&nd->path);
61626@@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61627 retval = path_lookupat(dfd, name->name,
61628 flags | LOOKUP_REVAL, nd);
61629
61630- if (likely(!retval))
61631+ if (likely(!retval)) {
61632 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61633+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61634+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61635+ path_put(&nd->path);
61636+ return -ENOENT;
61637+ }
61638+ }
61639+ }
61640 return retval;
61641 }
61642
61643@@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61644 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61645 return -EPERM;
61646
61647+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61648+ return -EPERM;
61649+ if (gr_handle_rawio(inode))
61650+ return -EPERM;
61651+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61652+ return -EACCES;
61653+
61654 return 0;
61655 }
61656
61657@@ -2787,7 +2826,7 @@ looked_up:
61658 * cleared otherwise prior to returning.
61659 */
61660 static int lookup_open(struct nameidata *nd, struct path *path,
61661- struct file *file,
61662+ struct path *link, struct file *file,
61663 const struct open_flags *op,
61664 bool got_write, int *opened)
61665 {
61666@@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61667 /* Negative dentry, just create the file */
61668 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61669 umode_t mode = op->mode;
61670+
61671+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61672+ error = -EACCES;
61673+ goto out_dput;
61674+ }
61675+
61676+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61677+ error = -EACCES;
61678+ goto out_dput;
61679+ }
61680+
61681 if (!IS_POSIXACL(dir->d_inode))
61682 mode &= ~current_umask();
61683 /*
61684@@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61685 nd->flags & LOOKUP_EXCL);
61686 if (error)
61687 goto out_dput;
61688+ else
61689+ gr_handle_create(dentry, nd->path.mnt);
61690 }
61691 out_no_open:
61692 path->dentry = dentry;
61693@@ -2857,7 +2909,7 @@ out_dput:
61694 /*
61695 * Handle the last step of open()
61696 */
61697-static int do_last(struct nameidata *nd, struct path *path,
61698+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61699 struct file *file, const struct open_flags *op,
61700 int *opened, struct filename *name)
61701 {
61702@@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61703 if (error)
61704 return error;
61705
61706+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61707+ error = -ENOENT;
61708+ goto out;
61709+ }
61710+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61711+ error = -EACCES;
61712+ goto out;
61713+ }
61714+
61715 audit_inode(name, dir, LOOKUP_PARENT);
61716 error = -EISDIR;
61717 /* trailing slashes? */
61718@@ -2926,7 +2987,7 @@ retry_lookup:
61719 */
61720 }
61721 mutex_lock(&dir->d_inode->i_mutex);
61722- error = lookup_open(nd, path, file, op, got_write, opened);
61723+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61724 mutex_unlock(&dir->d_inode->i_mutex);
61725
61726 if (error <= 0) {
61727@@ -2950,11 +3011,28 @@ retry_lookup:
61728 goto finish_open_created;
61729 }
61730
61731+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61732+ error = -ENOENT;
61733+ goto exit_dput;
61734+ }
61735+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61736+ error = -EACCES;
61737+ goto exit_dput;
61738+ }
61739+
61740 /*
61741 * create/update audit record if it already exists.
61742 */
61743- if (d_is_positive(path->dentry))
61744+ if (d_is_positive(path->dentry)) {
61745+ /* only check if O_CREAT is specified, all other checks need to go
61746+ into may_open */
61747+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61748+ error = -EACCES;
61749+ goto exit_dput;
61750+ }
61751+
61752 audit_inode(name, path->dentry, 0);
61753+ }
61754
61755 /*
61756 * If atomic_open() acquired write access it is dropped now due to
61757@@ -2995,6 +3073,11 @@ finish_lookup:
61758 }
61759 }
61760 BUG_ON(inode != path->dentry->d_inode);
61761+ /* if we're resolving a symlink to another symlink */
61762+ if (link && gr_handle_symlink_owner(link, inode)) {
61763+ error = -EACCES;
61764+ goto out;
61765+ }
61766 return 1;
61767 }
61768
61769@@ -3004,7 +3087,6 @@ finish_lookup:
61770 save_parent.dentry = nd->path.dentry;
61771 save_parent.mnt = mntget(path->mnt);
61772 nd->path.dentry = path->dentry;
61773-
61774 }
61775 nd->inode = inode;
61776 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61777@@ -3014,7 +3096,18 @@ finish_open:
61778 path_put(&save_parent);
61779 return error;
61780 }
61781+
61782+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61783+ error = -ENOENT;
61784+ goto out;
61785+ }
61786+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61787+ error = -EACCES;
61788+ goto out;
61789+ }
61790+
61791 audit_inode(name, nd->path.dentry, 0);
61792+
61793 error = -EISDIR;
61794 if ((open_flag & O_CREAT) &&
61795 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61796@@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61797 if (unlikely(error))
61798 goto out;
61799
61800- error = do_last(nd, &path, file, op, &opened, pathname);
61801+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61802 while (unlikely(error > 0)) { /* trailing symlink */
61803 struct path link = path;
61804 void *cookie;
61805@@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61806 error = follow_link(&link, nd, &cookie);
61807 if (unlikely(error))
61808 break;
61809- error = do_last(nd, &path, file, op, &opened, pathname);
61810+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61811 put_link(nd, &link, cookie);
61812 }
61813 out:
61814@@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61815 goto unlock;
61816
61817 error = -EEXIST;
61818- if (d_is_positive(dentry))
61819+ if (d_is_positive(dentry)) {
61820+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61821+ error = -ENOENT;
61822 goto fail;
61823-
61824+ }
61825 /*
61826 * Special case - lookup gave negative, but... we had foo/bar/
61827 * From the vfs_mknod() POV we just have a negative dentry -
61828@@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61829 }
61830 EXPORT_SYMBOL(user_path_create);
61831
61832+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61833+{
61834+ struct filename *tmp = getname(pathname);
61835+ struct dentry *res;
61836+ if (IS_ERR(tmp))
61837+ return ERR_CAST(tmp);
61838+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61839+ if (IS_ERR(res))
61840+ putname(tmp);
61841+ else
61842+ *to = tmp;
61843+ return res;
61844+}
61845+
61846 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61847 {
61848 int error = may_create(dir, dentry);
61849@@ -3412,6 +3521,17 @@ retry:
61850
61851 if (!IS_POSIXACL(path.dentry->d_inode))
61852 mode &= ~current_umask();
61853+
61854+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61855+ error = -EPERM;
61856+ goto out;
61857+ }
61858+
61859+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61860+ error = -EACCES;
61861+ goto out;
61862+ }
61863+
61864 error = security_path_mknod(&path, dentry, mode, dev);
61865 if (error)
61866 goto out;
61867@@ -3428,6 +3548,8 @@ retry:
61868 break;
61869 }
61870 out:
61871+ if (!error)
61872+ gr_handle_create(dentry, path.mnt);
61873 done_path_create(&path, dentry);
61874 if (retry_estale(error, lookup_flags)) {
61875 lookup_flags |= LOOKUP_REVAL;
61876@@ -3480,9 +3602,16 @@ retry:
61877
61878 if (!IS_POSIXACL(path.dentry->d_inode))
61879 mode &= ~current_umask();
61880+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61881+ error = -EACCES;
61882+ goto out;
61883+ }
61884 error = security_path_mkdir(&path, dentry, mode);
61885 if (!error)
61886 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61887+ if (!error)
61888+ gr_handle_create(dentry, path.mnt);
61889+out:
61890 done_path_create(&path, dentry);
61891 if (retry_estale(error, lookup_flags)) {
61892 lookup_flags |= LOOKUP_REVAL;
61893@@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61894 struct filename *name;
61895 struct dentry *dentry;
61896 struct nameidata nd;
61897+ ino_t saved_ino = 0;
61898+ dev_t saved_dev = 0;
61899 unsigned int lookup_flags = 0;
61900 retry:
61901 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61902@@ -3595,10 +3726,21 @@ retry:
61903 error = -ENOENT;
61904 goto exit3;
61905 }
61906+
61907+ saved_ino = dentry->d_inode->i_ino;
61908+ saved_dev = gr_get_dev_from_dentry(dentry);
61909+
61910+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61911+ error = -EACCES;
61912+ goto exit3;
61913+ }
61914+
61915 error = security_path_rmdir(&nd.path, dentry);
61916 if (error)
61917 goto exit3;
61918 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61919+ if (!error && (saved_dev || saved_ino))
61920+ gr_handle_delete(saved_ino, saved_dev);
61921 exit3:
61922 dput(dentry);
61923 exit2:
61924@@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61925 struct nameidata nd;
61926 struct inode *inode = NULL;
61927 struct inode *delegated_inode = NULL;
61928+ ino_t saved_ino = 0;
61929+ dev_t saved_dev = 0;
61930 unsigned int lookup_flags = 0;
61931 retry:
61932 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61933@@ -3714,10 +3858,22 @@ retry_deleg:
61934 if (d_is_negative(dentry))
61935 goto slashes;
61936 ihold(inode);
61937+
61938+ if (inode->i_nlink <= 1) {
61939+ saved_ino = inode->i_ino;
61940+ saved_dev = gr_get_dev_from_dentry(dentry);
61941+ }
61942+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61943+ error = -EACCES;
61944+ goto exit2;
61945+ }
61946+
61947 error = security_path_unlink(&nd.path, dentry);
61948 if (error)
61949 goto exit2;
61950 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61951+ if (!error && (saved_ino || saved_dev))
61952+ gr_handle_delete(saved_ino, saved_dev);
61953 exit2:
61954 dput(dentry);
61955 }
61956@@ -3805,9 +3961,17 @@ retry:
61957 if (IS_ERR(dentry))
61958 goto out_putname;
61959
61960+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61961+ error = -EACCES;
61962+ goto out;
61963+ }
61964+
61965 error = security_path_symlink(&path, dentry, from->name);
61966 if (!error)
61967 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61968+ if (!error)
61969+ gr_handle_create(dentry, path.mnt);
61970+out:
61971 done_path_create(&path, dentry);
61972 if (retry_estale(error, lookup_flags)) {
61973 lookup_flags |= LOOKUP_REVAL;
61974@@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61975 struct dentry *new_dentry;
61976 struct path old_path, new_path;
61977 struct inode *delegated_inode = NULL;
61978+ struct filename *to = NULL;
61979 int how = 0;
61980 int error;
61981
61982@@ -3933,7 +4098,7 @@ retry:
61983 if (error)
61984 return error;
61985
61986- new_dentry = user_path_create(newdfd, newname, &new_path,
61987+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61988 (how & LOOKUP_REVAL));
61989 error = PTR_ERR(new_dentry);
61990 if (IS_ERR(new_dentry))
61991@@ -3945,11 +4110,28 @@ retry:
61992 error = may_linkat(&old_path);
61993 if (unlikely(error))
61994 goto out_dput;
61995+
61996+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61997+ old_path.dentry->d_inode,
61998+ old_path.dentry->d_inode->i_mode, to)) {
61999+ error = -EACCES;
62000+ goto out_dput;
62001+ }
62002+
62003+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62004+ old_path.dentry, old_path.mnt, to)) {
62005+ error = -EACCES;
62006+ goto out_dput;
62007+ }
62008+
62009 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62010 if (error)
62011 goto out_dput;
62012 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62013+ if (!error)
62014+ gr_handle_create(new_dentry, new_path.mnt);
62015 out_dput:
62016+ putname(to);
62017 done_path_create(&new_path, new_dentry);
62018 if (delegated_inode) {
62019 error = break_deleg_wait(&delegated_inode);
62020@@ -4236,6 +4418,12 @@ retry_deleg:
62021 if (new_dentry == trap)
62022 goto exit5;
62023
62024+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62025+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62026+ to);
62027+ if (error)
62028+ goto exit5;
62029+
62030 error = security_path_rename(&oldnd.path, old_dentry,
62031 &newnd.path, new_dentry);
62032 if (error)
62033@@ -4243,6 +4431,9 @@ retry_deleg:
62034 error = vfs_rename(old_dir->d_inode, old_dentry,
62035 new_dir->d_inode, new_dentry,
62036 &delegated_inode);
62037+ if (!error)
62038+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62039+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
62040 exit5:
62041 dput(new_dentry);
62042 exit4:
62043@@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62044
62045 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
62046 {
62047+ char tmpbuf[64];
62048+ const char *newlink;
62049 int len;
62050
62051 len = PTR_ERR(link);
62052@@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
62053 len = strlen(link);
62054 if (len > (unsigned) buflen)
62055 len = buflen;
62056- if (copy_to_user(buffer, link, len))
62057+
62058+ if (len < sizeof(tmpbuf)) {
62059+ memcpy(tmpbuf, link, len);
62060+ newlink = tmpbuf;
62061+ } else
62062+ newlink = link;
62063+
62064+ if (copy_to_user(buffer, newlink, len))
62065 len = -EFAULT;
62066 out:
62067 return len;
62068diff --git a/fs/namespace.c b/fs/namespace.c
62069index 65233a5..82ac953 100644
62070--- a/fs/namespace.c
62071+++ b/fs/namespace.c
62072@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
62073 if (!(sb->s_flags & MS_RDONLY))
62074 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62075 up_write(&sb->s_umount);
62076+
62077+ gr_log_remount(mnt->mnt_devname, retval);
62078+
62079 return retval;
62080 }
62081
62082@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62083 }
62084 unlock_mount_hash();
62085 namespace_unlock();
62086+
62087+ gr_log_unmount(mnt->mnt_devname, retval);
62088+
62089 return retval;
62090 }
62091
62092@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62093 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62094 */
62095
62096-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62097+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62098 {
62099 struct path path;
62100 struct mount *mnt;
62101@@ -1422,7 +1428,7 @@ out:
62102 /*
62103 * The 2.0 compatible umount. No flags.
62104 */
62105-SYSCALL_DEFINE1(oldumount, char __user *, name)
62106+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62107 {
62108 return sys_umount(name, 0);
62109 }
62110@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62111 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62112 MS_STRICTATIME);
62113
62114+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62115+ retval = -EPERM;
62116+ goto dput_out;
62117+ }
62118+
62119+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62120+ retval = -EPERM;
62121+ goto dput_out;
62122+ }
62123+
62124 if (flags & MS_REMOUNT)
62125 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62126 data_page);
62127@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62128 dev_name, data_page);
62129 dput_out:
62130 path_put(&path);
62131+
62132+ gr_log_mount(dev_name, dir_name, retval);
62133+
62134 return retval;
62135 }
62136
62137@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62138 * number incrementing at 10Ghz will take 12,427 years to wrap which
62139 * is effectively never, so we can ignore the possibility.
62140 */
62141-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62142+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62143
62144 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62145 {
62146@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62147 kfree(new_ns);
62148 return ERR_PTR(ret);
62149 }
62150- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62151+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62152 atomic_set(&new_ns->count, 1);
62153 new_ns->root = NULL;
62154 INIT_LIST_HEAD(&new_ns->list);
62155@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62156 return new_ns;
62157 }
62158
62159-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62160+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62161 struct user_namespace *user_ns, struct fs_struct *new_fs)
62162 {
62163 struct mnt_namespace *new_ns;
62164@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62165 }
62166 EXPORT_SYMBOL(mount_subtree);
62167
62168-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62169- char __user *, type, unsigned long, flags, void __user *, data)
62170+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62171+ const char __user *, type, unsigned long, flags, void __user *, data)
62172 {
62173 int ret;
62174 char *kernel_type;
62175@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62176 if (error)
62177 goto out2;
62178
62179+ if (gr_handle_chroot_pivot()) {
62180+ error = -EPERM;
62181+ goto out2;
62182+ }
62183+
62184 get_fs_root(current->fs, &root);
62185 old_mp = lock_mount(&old);
62186 error = PTR_ERR(old_mp);
62187@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62188 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62189 return -EPERM;
62190
62191- if (fs->users != 1)
62192+ if (atomic_read(&fs->users) != 1)
62193 return -EINVAL;
62194
62195 get_mnt_ns(mnt_ns);
62196diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62197index f4ccfe6..a5cf064 100644
62198--- a/fs/nfs/callback_xdr.c
62199+++ b/fs/nfs/callback_xdr.c
62200@@ -51,7 +51,7 @@ struct callback_op {
62201 callback_decode_arg_t decode_args;
62202 callback_encode_res_t encode_res;
62203 long res_maxsize;
62204-};
62205+} __do_const;
62206
62207 static struct callback_op callback_ops[];
62208
62209diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62210index 360114a..ac6e265 100644
62211--- a/fs/nfs/inode.c
62212+++ b/fs/nfs/inode.c
62213@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62214 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62215 }
62216
62217-static atomic_long_t nfs_attr_generation_counter;
62218+static atomic_long_unchecked_t nfs_attr_generation_counter;
62219
62220 static unsigned long nfs_read_attr_generation_counter(void)
62221 {
62222- return atomic_long_read(&nfs_attr_generation_counter);
62223+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62224 }
62225
62226 unsigned long nfs_inc_attr_generation_counter(void)
62227 {
62228- return atomic_long_inc_return(&nfs_attr_generation_counter);
62229+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62230 }
62231
62232 void nfs_fattr_init(struct nfs_fattr *fattr)
62233diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62234index 9a914e8..e89c0ea 100644
62235--- a/fs/nfsd/nfs4proc.c
62236+++ b/fs/nfsd/nfs4proc.c
62237@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62238 nfsd4op_rsize op_rsize_bop;
62239 stateid_getter op_get_currentstateid;
62240 stateid_setter op_set_currentstateid;
62241-};
62242+} __do_const;
62243
62244 static struct nfsd4_operation nfsd4_ops[];
62245
62246diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62247index 16e8fa7..b0803f6 100644
62248--- a/fs/nfsd/nfs4xdr.c
62249+++ b/fs/nfsd/nfs4xdr.c
62250@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62251
62252 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62253
62254-static nfsd4_dec nfsd4_dec_ops[] = {
62255+static const nfsd4_dec nfsd4_dec_ops[] = {
62256 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62257 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62258 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62259diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62260index f8f060f..c4ba09a 100644
62261--- a/fs/nfsd/nfscache.c
62262+++ b/fs/nfsd/nfscache.c
62263@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62264 {
62265 struct svc_cacherep *rp = rqstp->rq_cacherep;
62266 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62267- int len;
62268+ long len;
62269 size_t bufsize = 0;
62270
62271 if (!rp)
62272 return;
62273
62274- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62275- len >>= 2;
62276+ if (statp) {
62277+ len = (char*)statp - (char*)resv->iov_base;
62278+ len = resv->iov_len - len;
62279+ len >>= 2;
62280+ }
62281
62282 /* Don't cache excessive amounts of data and XDR failures */
62283 if (!statp || len > (256 >> 2)) {
62284diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62285index eea5ad1..5a84ac7 100644
62286--- a/fs/nfsd/vfs.c
62287+++ b/fs/nfsd/vfs.c
62288@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62289 } else {
62290 oldfs = get_fs();
62291 set_fs(KERNEL_DS);
62292- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62293+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62294 set_fs(oldfs);
62295 }
62296
62297@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62298
62299 /* Write the data. */
62300 oldfs = get_fs(); set_fs(KERNEL_DS);
62301- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62302+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62303 set_fs(oldfs);
62304 if (host_err < 0)
62305 goto out_nfserr;
62306@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62307 */
62308
62309 oldfs = get_fs(); set_fs(KERNEL_DS);
62310- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62311+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62312 set_fs(oldfs);
62313
62314 if (host_err < 0)
62315diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62316index 52ccd34..43a53b1 100644
62317--- a/fs/nls/nls_base.c
62318+++ b/fs/nls/nls_base.c
62319@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62320
62321 int __register_nls(struct nls_table *nls, struct module *owner)
62322 {
62323- struct nls_table ** tmp = &tables;
62324+ struct nls_table *tmp = tables;
62325
62326 if (nls->next)
62327 return -EBUSY;
62328
62329- nls->owner = owner;
62330+ pax_open_kernel();
62331+ *(void **)&nls->owner = owner;
62332+ pax_close_kernel();
62333 spin_lock(&nls_lock);
62334- while (*tmp) {
62335- if (nls == *tmp) {
62336+ while (tmp) {
62337+ if (nls == tmp) {
62338 spin_unlock(&nls_lock);
62339 return -EBUSY;
62340 }
62341- tmp = &(*tmp)->next;
62342+ tmp = tmp->next;
62343 }
62344- nls->next = tables;
62345+ pax_open_kernel();
62346+ *(struct nls_table **)&nls->next = tables;
62347+ pax_close_kernel();
62348 tables = nls;
62349 spin_unlock(&nls_lock);
62350 return 0;
62351@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62352
62353 int unregister_nls(struct nls_table * nls)
62354 {
62355- struct nls_table ** tmp = &tables;
62356+ struct nls_table * const * tmp = &tables;
62357
62358 spin_lock(&nls_lock);
62359 while (*tmp) {
62360 if (nls == *tmp) {
62361- *tmp = nls->next;
62362+ pax_open_kernel();
62363+ *(struct nls_table **)tmp = nls->next;
62364+ pax_close_kernel();
62365 spin_unlock(&nls_lock);
62366 return 0;
62367 }
62368diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62369index 162b3f1..6076a7c 100644
62370--- a/fs/nls/nls_euc-jp.c
62371+++ b/fs/nls/nls_euc-jp.c
62372@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62373 p_nls = load_nls("cp932");
62374
62375 if (p_nls) {
62376- table.charset2upper = p_nls->charset2upper;
62377- table.charset2lower = p_nls->charset2lower;
62378+ pax_open_kernel();
62379+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62380+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62381+ pax_close_kernel();
62382 return register_nls(&table);
62383 }
62384
62385diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62386index a80a741..7b96e1b 100644
62387--- a/fs/nls/nls_koi8-ru.c
62388+++ b/fs/nls/nls_koi8-ru.c
62389@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62390 p_nls = load_nls("koi8-u");
62391
62392 if (p_nls) {
62393- table.charset2upper = p_nls->charset2upper;
62394- table.charset2lower = p_nls->charset2lower;
62395+ pax_open_kernel();
62396+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62397+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62398+ pax_close_kernel();
62399 return register_nls(&table);
62400 }
62401
62402diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62403index 287a22c..4e56e4e 100644
62404--- a/fs/notify/fanotify/fanotify_user.c
62405+++ b/fs/notify/fanotify/fanotify_user.c
62406@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62407
62408 fd = fanotify_event_metadata.fd;
62409 ret = -EFAULT;
62410- if (copy_to_user(buf, &fanotify_event_metadata,
62411- fanotify_event_metadata.event_len))
62412+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62413+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62414 goto out_close_fd;
62415
62416 ret = prepare_for_access_response(group, event, fd);
62417@@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62418 oevent->path.mnt = NULL;
62419 oevent->path.dentry = NULL;
62420
62421+ if (force_o_largefile())
62422+ event_f_flags |= O_LARGEFILE;
62423 group->fanotify_data.f_flags = event_f_flags;
62424 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62425 oevent->response = 0;
62426diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62427index 1e58402..bb2d6f4 100644
62428--- a/fs/notify/notification.c
62429+++ b/fs/notify/notification.c
62430@@ -48,7 +48,7 @@
62431 #include <linux/fsnotify_backend.h>
62432 #include "fsnotify.h"
62433
62434-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62435+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62436
62437 /**
62438 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62439@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62440 */
62441 u32 fsnotify_get_cookie(void)
62442 {
62443- return atomic_inc_return(&fsnotify_sync_cookie);
62444+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62445 }
62446 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62447
62448diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62449index 9e38daf..5727cae 100644
62450--- a/fs/ntfs/dir.c
62451+++ b/fs/ntfs/dir.c
62452@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62453 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62454 ~(s64)(ndir->itype.index.block_size - 1)));
62455 /* Bounds checks. */
62456- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62457+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62458 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62459 "inode 0x%lx or driver bug.", vdir->i_ino);
62460 goto err_out;
62461diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62462index db9bd8a..8338fb6 100644
62463--- a/fs/ntfs/file.c
62464+++ b/fs/ntfs/file.c
62465@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62466 char *addr;
62467 size_t total = 0;
62468 unsigned len;
62469- int left;
62470+ unsigned left;
62471
62472 do {
62473 len = PAGE_CACHE_SIZE - ofs;
62474diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62475index 82650d5..db37dcf 100644
62476--- a/fs/ntfs/super.c
62477+++ b/fs/ntfs/super.c
62478@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62479 if (!silent)
62480 ntfs_error(sb, "Primary boot sector is invalid.");
62481 } else if (!silent)
62482- ntfs_error(sb, read_err_str, "primary");
62483+ ntfs_error(sb, read_err_str, "%s", "primary");
62484 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62485 if (bh_primary)
62486 brelse(bh_primary);
62487@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62488 goto hotfix_primary_boot_sector;
62489 brelse(bh_backup);
62490 } else if (!silent)
62491- ntfs_error(sb, read_err_str, "backup");
62492+ ntfs_error(sb, read_err_str, "%s", "backup");
62493 /* Try to read NT3.51- backup boot sector. */
62494 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62495 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62496@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62497 "sector.");
62498 brelse(bh_backup);
62499 } else if (!silent)
62500- ntfs_error(sb, read_err_str, "backup");
62501+ ntfs_error(sb, read_err_str, "%s", "backup");
62502 /* We failed. Cleanup and return. */
62503 if (bh_primary)
62504 brelse(bh_primary);
62505diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62506index 0440134..d52c93a 100644
62507--- a/fs/ocfs2/localalloc.c
62508+++ b/fs/ocfs2/localalloc.c
62509@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62510 goto bail;
62511 }
62512
62513- atomic_inc(&osb->alloc_stats.moves);
62514+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62515
62516 bail:
62517 if (handle)
62518diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62519index 553f53c..aaf5133 100644
62520--- a/fs/ocfs2/ocfs2.h
62521+++ b/fs/ocfs2/ocfs2.h
62522@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62523
62524 struct ocfs2_alloc_stats
62525 {
62526- atomic_t moves;
62527- atomic_t local_data;
62528- atomic_t bitmap_data;
62529- atomic_t bg_allocs;
62530- atomic_t bg_extends;
62531+ atomic_unchecked_t moves;
62532+ atomic_unchecked_t local_data;
62533+ atomic_unchecked_t bitmap_data;
62534+ atomic_unchecked_t bg_allocs;
62535+ atomic_unchecked_t bg_extends;
62536 };
62537
62538 enum ocfs2_local_alloc_state
62539diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62540index 47ae266..6e8b793 100644
62541--- a/fs/ocfs2/suballoc.c
62542+++ b/fs/ocfs2/suballoc.c
62543@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62544 mlog_errno(status);
62545 goto bail;
62546 }
62547- atomic_inc(&osb->alloc_stats.bg_extends);
62548+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62549
62550 /* You should never ask for this much metadata */
62551 BUG_ON(bits_wanted >
62552@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62553 mlog_errno(status);
62554 goto bail;
62555 }
62556- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62557+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62558
62559 *suballoc_loc = res.sr_bg_blkno;
62560 *suballoc_bit_start = res.sr_bit_offset;
62561@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62562 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62563 res->sr_bits);
62564
62565- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62566+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62567
62568 BUG_ON(res->sr_bits != 1);
62569
62570@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62571 mlog_errno(status);
62572 goto bail;
62573 }
62574- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62575+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62576
62577 BUG_ON(res.sr_bits != 1);
62578
62579@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62580 cluster_start,
62581 num_clusters);
62582 if (!status)
62583- atomic_inc(&osb->alloc_stats.local_data);
62584+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62585 } else {
62586 if (min_clusters > (osb->bitmap_cpg - 1)) {
62587 /* The only paths asking for contiguousness
62588@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62589 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62590 res.sr_bg_blkno,
62591 res.sr_bit_offset);
62592- atomic_inc(&osb->alloc_stats.bitmap_data);
62593+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62594 *num_clusters = res.sr_bits;
62595 }
62596 }
62597diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62598index 49d84f8..4807e0b 100644
62599--- a/fs/ocfs2/super.c
62600+++ b/fs/ocfs2/super.c
62601@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62602 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62603 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62604 "Stats",
62605- atomic_read(&osb->alloc_stats.bitmap_data),
62606- atomic_read(&osb->alloc_stats.local_data),
62607- atomic_read(&osb->alloc_stats.bg_allocs),
62608- atomic_read(&osb->alloc_stats.moves),
62609- atomic_read(&osb->alloc_stats.bg_extends));
62610+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62611+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62612+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62613+ atomic_read_unchecked(&osb->alloc_stats.moves),
62614+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62615
62616 out += snprintf(buf + out, len - out,
62617 "%10s => State: %u Descriptor: %llu Size: %u bits "
62618@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62619 spin_lock_init(&osb->osb_xattr_lock);
62620 ocfs2_init_steal_slots(osb);
62621
62622- atomic_set(&osb->alloc_stats.moves, 0);
62623- atomic_set(&osb->alloc_stats.local_data, 0);
62624- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62625- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62626- atomic_set(&osb->alloc_stats.bg_extends, 0);
62627+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62628+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62629+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62630+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62631+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62632
62633 /* Copy the blockcheck stats from the superblock probe */
62634 osb->osb_ecc_stats = *stats;
62635diff --git a/fs/open.c b/fs/open.c
62636index b9ed8b2..0d5c7a0 100644
62637--- a/fs/open.c
62638+++ b/fs/open.c
62639@@ -32,6 +32,8 @@
62640 #include <linux/dnotify.h>
62641 #include <linux/compat.h>
62642
62643+#define CREATE_TRACE_POINTS
62644+#include <trace/events/fs.h>
62645 #include "internal.h"
62646
62647 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62648@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62649 error = locks_verify_truncate(inode, NULL, length);
62650 if (!error)
62651 error = security_path_truncate(path);
62652+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62653+ error = -EACCES;
62654 if (!error)
62655 error = do_truncate(path->dentry, length, 0, NULL);
62656
62657@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62658 error = locks_verify_truncate(inode, f.file, length);
62659 if (!error)
62660 error = security_path_truncate(&f.file->f_path);
62661+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62662+ error = -EACCES;
62663 if (!error)
62664 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62665 sb_end_write(inode->i_sb);
62666@@ -361,6 +367,9 @@ retry:
62667 if (__mnt_is_readonly(path.mnt))
62668 res = -EROFS;
62669
62670+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62671+ res = -EACCES;
62672+
62673 out_path_release:
62674 path_put(&path);
62675 if (retry_estale(res, lookup_flags)) {
62676@@ -392,6 +401,8 @@ retry:
62677 if (error)
62678 goto dput_and_out;
62679
62680+ gr_log_chdir(path.dentry, path.mnt);
62681+
62682 set_fs_pwd(current->fs, &path);
62683
62684 dput_and_out:
62685@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62686 goto out_putf;
62687
62688 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62689+
62690+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62691+ error = -EPERM;
62692+
62693+ if (!error)
62694+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62695+
62696 if (!error)
62697 set_fs_pwd(current->fs, &f.file->f_path);
62698 out_putf:
62699@@ -450,7 +468,13 @@ retry:
62700 if (error)
62701 goto dput_and_out;
62702
62703+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62704+ goto dput_and_out;
62705+
62706 set_fs_root(current->fs, &path);
62707+
62708+ gr_handle_chroot_chdir(&path);
62709+
62710 error = 0;
62711 dput_and_out:
62712 path_put(&path);
62713@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62714 return error;
62715 retry_deleg:
62716 mutex_lock(&inode->i_mutex);
62717+
62718+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62719+ error = -EACCES;
62720+ goto out_unlock;
62721+ }
62722+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62723+ error = -EACCES;
62724+ goto out_unlock;
62725+ }
62726+
62727 error = security_path_chmod(path, mode);
62728 if (error)
62729 goto out_unlock;
62730@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62731 uid = make_kuid(current_user_ns(), user);
62732 gid = make_kgid(current_user_ns(), group);
62733
62734+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62735+ return -EACCES;
62736+
62737 newattrs.ia_valid = ATTR_CTIME;
62738 if (user != (uid_t) -1) {
62739 if (!uid_valid(uid))
62740@@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62741 } else {
62742 fsnotify_open(f);
62743 fd_install(fd, f);
62744+ trace_do_sys_open(tmp->name, flags, mode);
62745 }
62746 }
62747 putname(tmp);
62748diff --git a/fs/pipe.c b/fs/pipe.c
62749index 78fd0d0..f71fc09 100644
62750--- a/fs/pipe.c
62751+++ b/fs/pipe.c
62752@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62753
62754 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62755 {
62756- if (pipe->files)
62757+ if (atomic_read(&pipe->files))
62758 mutex_lock_nested(&pipe->mutex, subclass);
62759 }
62760
62761@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62762
62763 void pipe_unlock(struct pipe_inode_info *pipe)
62764 {
62765- if (pipe->files)
62766+ if (atomic_read(&pipe->files))
62767 mutex_unlock(&pipe->mutex);
62768 }
62769 EXPORT_SYMBOL(pipe_unlock);
62770@@ -449,9 +449,9 @@ redo:
62771 }
62772 if (bufs) /* More to do? */
62773 continue;
62774- if (!pipe->writers)
62775+ if (!atomic_read(&pipe->writers))
62776 break;
62777- if (!pipe->waiting_writers) {
62778+ if (!atomic_read(&pipe->waiting_writers)) {
62779 /* syscall merging: Usually we must not sleep
62780 * if O_NONBLOCK is set, or if we got some data.
62781 * But if a writer sleeps in kernel space, then
62782@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62783 ret = 0;
62784 __pipe_lock(pipe);
62785
62786- if (!pipe->readers) {
62787+ if (!atomic_read(&pipe->readers)) {
62788 send_sig(SIGPIPE, current, 0);
62789 ret = -EPIPE;
62790 goto out;
62791@@ -562,7 +562,7 @@ redo1:
62792 for (;;) {
62793 int bufs;
62794
62795- if (!pipe->readers) {
62796+ if (!atomic_read(&pipe->readers)) {
62797 send_sig(SIGPIPE, current, 0);
62798 if (!ret)
62799 ret = -EPIPE;
62800@@ -653,9 +653,9 @@ redo2:
62801 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62802 do_wakeup = 0;
62803 }
62804- pipe->waiting_writers++;
62805+ atomic_inc(&pipe->waiting_writers);
62806 pipe_wait(pipe);
62807- pipe->waiting_writers--;
62808+ atomic_dec(&pipe->waiting_writers);
62809 }
62810 out:
62811 __pipe_unlock(pipe);
62812@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62813 mask = 0;
62814 if (filp->f_mode & FMODE_READ) {
62815 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62816- if (!pipe->writers && filp->f_version != pipe->w_counter)
62817+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62818 mask |= POLLHUP;
62819 }
62820
62821@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62822 * Most Unices do not set POLLERR for FIFOs but on Linux they
62823 * behave exactly like pipes for poll().
62824 */
62825- if (!pipe->readers)
62826+ if (!atomic_read(&pipe->readers))
62827 mask |= POLLERR;
62828 }
62829
62830@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62831 int kill = 0;
62832
62833 spin_lock(&inode->i_lock);
62834- if (!--pipe->files) {
62835+ if (atomic_dec_and_test(&pipe->files)) {
62836 inode->i_pipe = NULL;
62837 kill = 1;
62838 }
62839@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
62840
62841 __pipe_lock(pipe);
62842 if (file->f_mode & FMODE_READ)
62843- pipe->readers--;
62844+ atomic_dec(&pipe->readers);
62845 if (file->f_mode & FMODE_WRITE)
62846- pipe->writers--;
62847+ atomic_dec(&pipe->writers);
62848
62849- if (pipe->readers || pipe->writers) {
62850+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62851 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62852 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62853 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62854@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62855 kfree(pipe);
62856 }
62857
62858-static struct vfsmount *pipe_mnt __read_mostly;
62859+struct vfsmount *pipe_mnt __read_mostly;
62860
62861 /*
62862 * pipefs_dname() is called from d_path().
62863@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
62864 goto fail_iput;
62865
62866 inode->i_pipe = pipe;
62867- pipe->files = 2;
62868- pipe->readers = pipe->writers = 1;
62869+ atomic_set(&pipe->files, 2);
62870+ atomic_set(&pipe->readers, 1);
62871+ atomic_set(&pipe->writers, 1);
62872 inode->i_fop = &pipefifo_fops;
62873
62874 /*
62875@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62876 spin_lock(&inode->i_lock);
62877 if (inode->i_pipe) {
62878 pipe = inode->i_pipe;
62879- pipe->files++;
62880+ atomic_inc(&pipe->files);
62881 spin_unlock(&inode->i_lock);
62882 } else {
62883 spin_unlock(&inode->i_lock);
62884 pipe = alloc_pipe_info();
62885 if (!pipe)
62886 return -ENOMEM;
62887- pipe->files = 1;
62888+ atomic_set(&pipe->files, 1);
62889 spin_lock(&inode->i_lock);
62890 if (unlikely(inode->i_pipe)) {
62891- inode->i_pipe->files++;
62892+ atomic_inc(&inode->i_pipe->files);
62893 spin_unlock(&inode->i_lock);
62894 free_pipe_info(pipe);
62895 pipe = inode->i_pipe;
62896@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62897 * opened, even when there is no process writing the FIFO.
62898 */
62899 pipe->r_counter++;
62900- if (pipe->readers++ == 0)
62901+ if (atomic_inc_return(&pipe->readers) == 1)
62902 wake_up_partner(pipe);
62903
62904- if (!is_pipe && !pipe->writers) {
62905+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62906 if ((filp->f_flags & O_NONBLOCK)) {
62907 /* suppress POLLHUP until we have
62908 * seen a writer */
62909@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62910 * errno=ENXIO when there is no process reading the FIFO.
62911 */
62912 ret = -ENXIO;
62913- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62914+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62915 goto err;
62916
62917 pipe->w_counter++;
62918- if (!pipe->writers++)
62919+ if (atomic_inc_return(&pipe->writers) == 1)
62920 wake_up_partner(pipe);
62921
62922- if (!is_pipe && !pipe->readers) {
62923+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62924 if (wait_for_partner(pipe, &pipe->r_counter))
62925 goto err_wr;
62926 }
62927@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62928 * the process can at least talk to itself.
62929 */
62930
62931- pipe->readers++;
62932- pipe->writers++;
62933+ atomic_inc(&pipe->readers);
62934+ atomic_inc(&pipe->writers);
62935 pipe->r_counter++;
62936 pipe->w_counter++;
62937- if (pipe->readers == 1 || pipe->writers == 1)
62938+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62939 wake_up_partner(pipe);
62940 break;
62941
62942@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62943 return 0;
62944
62945 err_rd:
62946- if (!--pipe->readers)
62947+ if (atomic_dec_and_test(&pipe->readers))
62948 wake_up_interruptible(&pipe->wait);
62949 ret = -ERESTARTSYS;
62950 goto err;
62951
62952 err_wr:
62953- if (!--pipe->writers)
62954+ if (atomic_dec_and_test(&pipe->writers))
62955 wake_up_interruptible(&pipe->wait);
62956 ret = -ERESTARTSYS;
62957 goto err;
62958diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62959index 9e363e4..d936d15 100644
62960--- a/fs/posix_acl.c
62961+++ b/fs/posix_acl.c
62962@@ -20,6 +20,7 @@
62963 #include <linux/xattr.h>
62964 #include <linux/export.h>
62965 #include <linux/user_namespace.h>
62966+#include <linux/grsecurity.h>
62967
62968 struct posix_acl **acl_by_type(struct inode *inode, int type)
62969 {
62970@@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62971 }
62972 }
62973 if (mode_p)
62974- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62975+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62976 return not_equiv;
62977 }
62978 EXPORT_SYMBOL(posix_acl_equiv_mode);
62979@@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62980 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62981 }
62982
62983- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62984+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62985 return not_equiv;
62986 }
62987
62988@@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62989 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62990 int err = -ENOMEM;
62991 if (clone) {
62992+ *mode_p &= ~gr_acl_umask();
62993+
62994 err = posix_acl_create_masq(clone, mode_p);
62995 if (err < 0) {
62996 posix_acl_release(clone);
62997@@ -653,11 +656,12 @@ struct posix_acl *
62998 posix_acl_from_xattr(struct user_namespace *user_ns,
62999 const void *value, size_t size)
63000 {
63001- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63002- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63003+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63004+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63005 int count;
63006 struct posix_acl *acl;
63007 struct posix_acl_entry *acl_e;
63008+ umode_t umask = gr_acl_umask();
63009
63010 if (!value)
63011 return NULL;
63012@@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63013
63014 switch(acl_e->e_tag) {
63015 case ACL_USER_OBJ:
63016+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63017+ break;
63018 case ACL_GROUP_OBJ:
63019 case ACL_MASK:
63020+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63021+ break;
63022 case ACL_OTHER:
63023+ acl_e->e_perm &= ~(umask & S_IRWXO);
63024 break;
63025
63026 case ACL_USER:
63027+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63028 acl_e->e_uid =
63029 make_kuid(user_ns,
63030 le32_to_cpu(entry->e_id));
63031@@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63032 goto fail;
63033 break;
63034 case ACL_GROUP:
63035+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63036 acl_e->e_gid =
63037 make_kgid(user_ns,
63038 le32_to_cpu(entry->e_id));
63039diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63040index 2183fcf..3c32a98 100644
63041--- a/fs/proc/Kconfig
63042+++ b/fs/proc/Kconfig
63043@@ -30,7 +30,7 @@ config PROC_FS
63044
63045 config PROC_KCORE
63046 bool "/proc/kcore support" if !ARM
63047- depends on PROC_FS && MMU
63048+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63049 help
63050 Provides a virtual ELF core file of the live kernel. This can
63051 be read with gdb and other ELF tools. No modifications can be
63052@@ -38,8 +38,8 @@ config PROC_KCORE
63053
63054 config PROC_VMCORE
63055 bool "/proc/vmcore support"
63056- depends on PROC_FS && CRASH_DUMP
63057- default y
63058+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63059+ default n
63060 help
63061 Exports the dump image of crashed kernel in ELF format.
63062
63063@@ -63,8 +63,8 @@ config PROC_SYSCTL
63064 limited in memory.
63065
63066 config PROC_PAGE_MONITOR
63067- default y
63068- depends on PROC_FS && MMU
63069+ default n
63070+ depends on PROC_FS && MMU && !GRKERNSEC
63071 bool "Enable /proc page monitoring" if EXPERT
63072 help
63073 Various /proc files exist to monitor process memory utilization:
63074diff --git a/fs/proc/array.c b/fs/proc/array.c
63075index 656e401..b5b86b9 100644
63076--- a/fs/proc/array.c
63077+++ b/fs/proc/array.c
63078@@ -60,6 +60,7 @@
63079 #include <linux/tty.h>
63080 #include <linux/string.h>
63081 #include <linux/mman.h>
63082+#include <linux/grsecurity.h>
63083 #include <linux/proc_fs.h>
63084 #include <linux/ioport.h>
63085 #include <linux/uaccess.h>
63086@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63087 seq_putc(m, '\n');
63088 }
63089
63090+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63091+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63092+{
63093+ if (p->mm)
63094+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63095+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63096+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63097+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63098+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63099+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63100+ else
63101+ seq_printf(m, "PaX:\t-----\n");
63102+}
63103+#endif
63104+
63105 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63106 struct pid *pid, struct task_struct *task)
63107 {
63108@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63109 task_cpus_allowed(m, task);
63110 cpuset_task_status_allowed(m, task);
63111 task_context_switch_counts(m, task);
63112+
63113+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63114+ task_pax(m, task);
63115+#endif
63116+
63117+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63118+ task_grsec_rbac(m, task);
63119+#endif
63120+
63121 return 0;
63122 }
63123
63124+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63125+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63126+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63127+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63128+#endif
63129+
63130 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63131 struct pid *pid, struct task_struct *task, int whole)
63132 {
63133@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63134 char tcomm[sizeof(task->comm)];
63135 unsigned long flags;
63136
63137+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63138+ if (current->exec_id != m->exec_id) {
63139+ gr_log_badprocpid("stat");
63140+ return 0;
63141+ }
63142+#endif
63143+
63144 state = *get_task_state(task);
63145 vsize = eip = esp = 0;
63146 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63147@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63148 gtime = task_gtime(task);
63149 }
63150
63151+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63152+ if (PAX_RAND_FLAGS(mm)) {
63153+ eip = 0;
63154+ esp = 0;
63155+ wchan = 0;
63156+ }
63157+#endif
63158+#ifdef CONFIG_GRKERNSEC_HIDESYM
63159+ wchan = 0;
63160+ eip =0;
63161+ esp =0;
63162+#endif
63163+
63164 /* scale priority and nice values from timeslices to -20..20 */
63165 /* to make it look like a "normal" Unix priority/nice value */
63166 priority = task_prio(task);
63167@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63168 seq_put_decimal_ull(m, ' ', vsize);
63169 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63170 seq_put_decimal_ull(m, ' ', rsslim);
63171+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63172+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63173+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63174+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63175+#else
63176 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63177 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63178 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63179+#endif
63180 seq_put_decimal_ull(m, ' ', esp);
63181 seq_put_decimal_ull(m, ' ', eip);
63182 /* The signal information here is obsolete.
63183@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63184 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63185 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63186
63187- if (mm && permitted) {
63188+ if (mm && permitted
63189+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63190+ && !PAX_RAND_FLAGS(mm)
63191+#endif
63192+ ) {
63193 seq_put_decimal_ull(m, ' ', mm->start_data);
63194 seq_put_decimal_ull(m, ' ', mm->end_data);
63195 seq_put_decimal_ull(m, ' ', mm->start_brk);
63196@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63197 struct pid *pid, struct task_struct *task)
63198 {
63199 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63200- struct mm_struct *mm = get_task_mm(task);
63201+ struct mm_struct *mm;
63202
63203+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63204+ if (current->exec_id != m->exec_id) {
63205+ gr_log_badprocpid("statm");
63206+ return 0;
63207+ }
63208+#endif
63209+ mm = get_task_mm(task);
63210 if (mm) {
63211 size = task_statm(mm, &shared, &text, &data, &resident);
63212 mmput(mm);
63213@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63214 return 0;
63215 }
63216
63217+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63218+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63219+{
63220+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63221+}
63222+#endif
63223+
63224 #ifdef CONFIG_CHECKPOINT_RESTORE
63225 static struct pid *
63226 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63227diff --git a/fs/proc/base.c b/fs/proc/base.c
63228index b976062..584d0bc 100644
63229--- a/fs/proc/base.c
63230+++ b/fs/proc/base.c
63231@@ -113,6 +113,14 @@ struct pid_entry {
63232 union proc_op op;
63233 };
63234
63235+struct getdents_callback {
63236+ struct linux_dirent __user * current_dir;
63237+ struct linux_dirent __user * previous;
63238+ struct file * file;
63239+ int count;
63240+ int error;
63241+};
63242+
63243 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63244 .name = (NAME), \
63245 .len = sizeof(NAME) - 1, \
63246@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63247 if (!mm->arg_end)
63248 goto out_mm; /* Shh! No looking before we're done */
63249
63250+ if (gr_acl_handle_procpidmem(task))
63251+ goto out_mm;
63252+
63253 len = mm->arg_end - mm->arg_start;
63254
63255 if (len > PAGE_SIZE)
63256@@ -237,12 +248,28 @@ out:
63257 return res;
63258 }
63259
63260+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63261+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63262+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63263+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63264+#endif
63265+
63266 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63267 {
63268 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63269 int res = PTR_ERR(mm);
63270 if (mm && !IS_ERR(mm)) {
63271 unsigned int nwords = 0;
63272+
63273+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63274+ /* allow if we're currently ptracing this task */
63275+ if (PAX_RAND_FLAGS(mm) &&
63276+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63277+ mmput(mm);
63278+ return 0;
63279+ }
63280+#endif
63281+
63282 do {
63283 nwords += 2;
63284 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63285@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63286 }
63287
63288
63289-#ifdef CONFIG_KALLSYMS
63290+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63291 /*
63292 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63293 * Returns the resolved symbol. If that fails, simply return the address.
63294@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63295 mutex_unlock(&task->signal->cred_guard_mutex);
63296 }
63297
63298-#ifdef CONFIG_STACKTRACE
63299+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63300
63301 #define MAX_STACK_TRACE_DEPTH 64
63302
63303@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63304 return count;
63305 }
63306
63307-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63308+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63309 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63310 {
63311 long nr;
63312@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63313 /************************************************************************/
63314
63315 /* permission checks */
63316-static int proc_fd_access_allowed(struct inode *inode)
63317+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63318 {
63319 struct task_struct *task;
63320 int allowed = 0;
63321@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63322 */
63323 task = get_proc_task(inode);
63324 if (task) {
63325- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63326+ if (log)
63327+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63328+ else
63329+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63330 put_task_struct(task);
63331 }
63332 return allowed;
63333@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63334 struct task_struct *task,
63335 int hide_pid_min)
63336 {
63337+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63338+ return false;
63339+
63340+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63341+ rcu_read_lock();
63342+ {
63343+ const struct cred *tmpcred = current_cred();
63344+ const struct cred *cred = __task_cred(task);
63345+
63346+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63347+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63348+ || in_group_p(grsec_proc_gid)
63349+#endif
63350+ ) {
63351+ rcu_read_unlock();
63352+ return true;
63353+ }
63354+ }
63355+ rcu_read_unlock();
63356+
63357+ if (!pid->hide_pid)
63358+ return false;
63359+#endif
63360+
63361 if (pid->hide_pid < hide_pid_min)
63362 return true;
63363 if (in_group_p(pid->pid_gid))
63364 return true;
63365+
63366 return ptrace_may_access(task, PTRACE_MODE_READ);
63367 }
63368
63369@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63370 put_task_struct(task);
63371
63372 if (!has_perms) {
63373+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63374+ {
63375+#else
63376 if (pid->hide_pid == 2) {
63377+#endif
63378 /*
63379 * Let's make getdents(), stat(), and open()
63380 * consistent with each other. If a process
63381@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63382 if (!task)
63383 return -ESRCH;
63384
63385+ if (gr_acl_handle_procpidmem(task)) {
63386+ put_task_struct(task);
63387+ return -EPERM;
63388+ }
63389+
63390 mm = mm_access(task, mode);
63391 put_task_struct(task);
63392
63393@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63394
63395 file->private_data = mm;
63396
63397+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63398+ file->f_version = current->exec_id;
63399+#endif
63400+
63401 return 0;
63402 }
63403
63404@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63405 ssize_t copied;
63406 char *page;
63407
63408+#ifdef CONFIG_GRKERNSEC
63409+ if (write)
63410+ return -EPERM;
63411+#endif
63412+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63413+ if (file->f_version != current->exec_id) {
63414+ gr_log_badprocpid("mem");
63415+ return 0;
63416+ }
63417+#endif
63418+
63419 if (!mm)
63420 return 0;
63421
63422@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63423 goto free;
63424
63425 while (count > 0) {
63426- int this_len = min_t(int, count, PAGE_SIZE);
63427+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63428
63429 if (write && copy_from_user(page, buf, this_len)) {
63430 copied = -EFAULT;
63431@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63432 if (!mm)
63433 return 0;
63434
63435+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63436+ if (file->f_version != current->exec_id) {
63437+ gr_log_badprocpid("environ");
63438+ return 0;
63439+ }
63440+#endif
63441+
63442 page = (char *)__get_free_page(GFP_TEMPORARY);
63443 if (!page)
63444 return -ENOMEM;
63445@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63446 goto free;
63447 while (count > 0) {
63448 size_t this_len, max_len;
63449- int retval;
63450+ ssize_t retval;
63451
63452 if (src >= (mm->env_end - mm->env_start))
63453 break;
63454@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63455 int error = -EACCES;
63456
63457 /* Are we allowed to snoop on the tasks file descriptors? */
63458- if (!proc_fd_access_allowed(inode))
63459+ if (!proc_fd_access_allowed(inode, 0))
63460 goto out;
63461
63462 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63463@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63464 struct path path;
63465
63466 /* Are we allowed to snoop on the tasks file descriptors? */
63467- if (!proc_fd_access_allowed(inode))
63468- goto out;
63469+ /* logging this is needed for learning on chromium to work properly,
63470+ but we don't want to flood the logs from 'ps' which does a readlink
63471+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63472+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63473+ */
63474+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63475+ if (!proc_fd_access_allowed(inode,0))
63476+ goto out;
63477+ } else {
63478+ if (!proc_fd_access_allowed(inode,1))
63479+ goto out;
63480+ }
63481
63482 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63483 if (error)
63484@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63485 rcu_read_lock();
63486 cred = __task_cred(task);
63487 inode->i_uid = cred->euid;
63488+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63489+ inode->i_gid = grsec_proc_gid;
63490+#else
63491 inode->i_gid = cred->egid;
63492+#endif
63493 rcu_read_unlock();
63494 }
63495 security_task_to_inode(task, inode);
63496@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63497 return -ENOENT;
63498 }
63499 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63500+#ifdef CONFIG_GRKERNSEC_PROC_USER
63501+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63502+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63503+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63504+#endif
63505 task_dumpable(task)) {
63506 cred = __task_cred(task);
63507 stat->uid = cred->euid;
63508+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63509+ stat->gid = grsec_proc_gid;
63510+#else
63511 stat->gid = cred->egid;
63512+#endif
63513 }
63514 }
63515 rcu_read_unlock();
63516@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63517
63518 if (task) {
63519 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63520+#ifdef CONFIG_GRKERNSEC_PROC_USER
63521+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63522+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63523+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63524+#endif
63525 task_dumpable(task)) {
63526 rcu_read_lock();
63527 cred = __task_cred(task);
63528 inode->i_uid = cred->euid;
63529+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63530+ inode->i_gid = grsec_proc_gid;
63531+#else
63532 inode->i_gid = cred->egid;
63533+#endif
63534 rcu_read_unlock();
63535 } else {
63536 inode->i_uid = GLOBAL_ROOT_UID;
63537@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63538 if (!task)
63539 goto out_no_task;
63540
63541+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63542+ goto out;
63543+
63544 /*
63545 * Yes, it does not scale. And it should not. Don't add
63546 * new entries into /proc/<tgid>/ without very good reasons.
63547@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63548 if (!task)
63549 return -ENOENT;
63550
63551+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63552+ goto out;
63553+
63554 if (!dir_emit_dots(file, ctx))
63555 goto out;
63556
63557@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63558 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63559 #endif
63560 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63561-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63562+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63563 INF("syscall", S_IRUGO, proc_pid_syscall),
63564 #endif
63565 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63566@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63567 #ifdef CONFIG_SECURITY
63568 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63569 #endif
63570-#ifdef CONFIG_KALLSYMS
63571+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63572 INF("wchan", S_IRUGO, proc_pid_wchan),
63573 #endif
63574-#ifdef CONFIG_STACKTRACE
63575+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63576 ONE("stack", S_IRUGO, proc_pid_stack),
63577 #endif
63578 #ifdef CONFIG_SCHEDSTATS
63579@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63580 #ifdef CONFIG_HARDWALL
63581 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63582 #endif
63583+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63584+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63585+#endif
63586 #ifdef CONFIG_USER_NS
63587 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63588 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63589@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63590 if (!inode)
63591 goto out;
63592
63593+#ifdef CONFIG_GRKERNSEC_PROC_USER
63594+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63595+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63596+ inode->i_gid = grsec_proc_gid;
63597+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63598+#else
63599 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63600+#endif
63601 inode->i_op = &proc_tgid_base_inode_operations;
63602 inode->i_fop = &proc_tgid_base_operations;
63603 inode->i_flags|=S_IMMUTABLE;
63604@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63605 if (!task)
63606 goto out;
63607
63608+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63609+ goto out_put_task;
63610+
63611 result = proc_pid_instantiate(dir, dentry, task, NULL);
63612+out_put_task:
63613 put_task_struct(task);
63614 out:
63615 return ERR_PTR(result);
63616@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63617 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63618 #endif
63619 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63620-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63621+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63622 INF("syscall", S_IRUGO, proc_pid_syscall),
63623 #endif
63624 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63625@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63626 #ifdef CONFIG_SECURITY
63627 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63628 #endif
63629-#ifdef CONFIG_KALLSYMS
63630+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63631 INF("wchan", S_IRUGO, proc_pid_wchan),
63632 #endif
63633-#ifdef CONFIG_STACKTRACE
63634+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63635 ONE("stack", S_IRUGO, proc_pid_stack),
63636 #endif
63637 #ifdef CONFIG_SCHEDSTATS
63638diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63639index cbd82df..c0407d2 100644
63640--- a/fs/proc/cmdline.c
63641+++ b/fs/proc/cmdline.c
63642@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63643
63644 static int __init proc_cmdline_init(void)
63645 {
63646+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63647+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63648+#else
63649 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63650+#endif
63651 return 0;
63652 }
63653 fs_initcall(proc_cmdline_init);
63654diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63655index 50493ed..248166b 100644
63656--- a/fs/proc/devices.c
63657+++ b/fs/proc/devices.c
63658@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63659
63660 static int __init proc_devices_init(void)
63661 {
63662+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63663+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63664+#else
63665 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63666+#endif
63667 return 0;
63668 }
63669 fs_initcall(proc_devices_init);
63670diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63671index 985ea88..d118a0a 100644
63672--- a/fs/proc/fd.c
63673+++ b/fs/proc/fd.c
63674@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63675 if (!task)
63676 return -ENOENT;
63677
63678- files = get_files_struct(task);
63679+ if (!gr_acl_handle_procpidmem(task))
63680+ files = get_files_struct(task);
63681 put_task_struct(task);
63682
63683 if (files) {
63684@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63685 */
63686 int proc_fd_permission(struct inode *inode, int mask)
63687 {
63688+ struct task_struct *task;
63689 int rv = generic_permission(inode, mask);
63690- if (rv == 0)
63691- return 0;
63692+
63693 if (task_tgid(current) == proc_pid(inode))
63694 rv = 0;
63695+
63696+ task = get_proc_task(inode);
63697+ if (task == NULL)
63698+ return rv;
63699+
63700+ if (gr_acl_handle_procpidmem(task))
63701+ rv = -EACCES;
63702+
63703+ put_task_struct(task);
63704+
63705 return rv;
63706 }
63707
63708diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63709index b7f268e..3bea6b7 100644
63710--- a/fs/proc/generic.c
63711+++ b/fs/proc/generic.c
63712@@ -23,6 +23,7 @@
63713 #include <linux/bitops.h>
63714 #include <linux/spinlock.h>
63715 #include <linux/completion.h>
63716+#include <linux/grsecurity.h>
63717 #include <asm/uaccess.h>
63718
63719 #include "internal.h"
63720@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63721 return proc_lookup_de(PDE(dir), dir, dentry);
63722 }
63723
63724+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63725+ unsigned int flags)
63726+{
63727+ if (gr_proc_is_restricted())
63728+ return ERR_PTR(-EACCES);
63729+
63730+ return proc_lookup_de(PDE(dir), dir, dentry);
63731+}
63732+
63733 /*
63734 * This returns non-zero if at EOF, so that the /proc
63735 * root directory can use this and check if it should
63736@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63737 return proc_readdir_de(PDE(inode), file, ctx);
63738 }
63739
63740+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63741+{
63742+ struct inode *inode = file_inode(file);
63743+
63744+ if (gr_proc_is_restricted())
63745+ return -EACCES;
63746+
63747+ return proc_readdir_de(PDE(inode), file, ctx);
63748+}
63749+
63750 /*
63751 * These are the generic /proc directory operations. They
63752 * use the in-memory "struct proc_dir_entry" tree to parse
63753@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63754 .iterate = proc_readdir,
63755 };
63756
63757+static const struct file_operations proc_dir_restricted_operations = {
63758+ .llseek = generic_file_llseek,
63759+ .read = generic_read_dir,
63760+ .iterate = proc_readdir_restrict,
63761+};
63762+
63763 /*
63764 * proc directories can do almost nothing..
63765 */
63766@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63767 .setattr = proc_notify_change,
63768 };
63769
63770+static const struct inode_operations proc_dir_restricted_inode_operations = {
63771+ .lookup = proc_lookup_restrict,
63772+ .getattr = proc_getattr,
63773+ .setattr = proc_notify_change,
63774+};
63775+
63776 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63777 {
63778 struct proc_dir_entry *tmp;
63779@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63780 return ret;
63781
63782 if (S_ISDIR(dp->mode)) {
63783- dp->proc_fops = &proc_dir_operations;
63784- dp->proc_iops = &proc_dir_inode_operations;
63785+ if (dp->restricted) {
63786+ dp->proc_fops = &proc_dir_restricted_operations;
63787+ dp->proc_iops = &proc_dir_restricted_inode_operations;
63788+ } else {
63789+ dp->proc_fops = &proc_dir_operations;
63790+ dp->proc_iops = &proc_dir_inode_operations;
63791+ }
63792 dir->nlink++;
63793 } else if (S_ISLNK(dp->mode)) {
63794 dp->proc_iops = &proc_link_inode_operations;
63795@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63796 }
63797 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63798
63799+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63800+ struct proc_dir_entry *parent, void *data)
63801+{
63802+ struct proc_dir_entry *ent;
63803+
63804+ if (mode == 0)
63805+ mode = S_IRUGO | S_IXUGO;
63806+
63807+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63808+ if (ent) {
63809+ ent->data = data;
63810+ ent->restricted = 1;
63811+ if (proc_register(parent, ent) < 0) {
63812+ kfree(ent);
63813+ ent = NULL;
63814+ }
63815+ }
63816+ return ent;
63817+}
63818+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63819+
63820 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63821 struct proc_dir_entry *parent)
63822 {
63823@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63824 }
63825 EXPORT_SYMBOL(proc_mkdir);
63826
63827+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63828+ struct proc_dir_entry *parent)
63829+{
63830+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
63831+}
63832+EXPORT_SYMBOL(proc_mkdir_restrict);
63833+
63834 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63835 struct proc_dir_entry *parent,
63836 const struct file_operations *proc_fops,
63837diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63838index 124fc43..8afbb02 100644
63839--- a/fs/proc/inode.c
63840+++ b/fs/proc/inode.c
63841@@ -23,11 +23,17 @@
63842 #include <linux/slab.h>
63843 #include <linux/mount.h>
63844 #include <linux/magic.h>
63845+#include <linux/grsecurity.h>
63846
63847 #include <asm/uaccess.h>
63848
63849 #include "internal.h"
63850
63851+#ifdef CONFIG_PROC_SYSCTL
63852+extern const struct inode_operations proc_sys_inode_operations;
63853+extern const struct inode_operations proc_sys_dir_operations;
63854+#endif
63855+
63856 static void proc_evict_inode(struct inode *inode)
63857 {
63858 struct proc_dir_entry *de;
63859@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63860 ns = PROC_I(inode)->ns.ns;
63861 if (ns_ops && ns)
63862 ns_ops->put(ns);
63863+
63864+#ifdef CONFIG_PROC_SYSCTL
63865+ if (inode->i_op == &proc_sys_inode_operations ||
63866+ inode->i_op == &proc_sys_dir_operations)
63867+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63868+#endif
63869+
63870 }
63871
63872 static struct kmem_cache * proc_inode_cachep;
63873@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63874 if (de->mode) {
63875 inode->i_mode = de->mode;
63876 inode->i_uid = de->uid;
63877+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63878+ inode->i_gid = grsec_proc_gid;
63879+#else
63880 inode->i_gid = de->gid;
63881+#endif
63882 }
63883 if (de->size)
63884 inode->i_size = de->size;
63885diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63886index 651d09a..6a4b495 100644
63887--- a/fs/proc/internal.h
63888+++ b/fs/proc/internal.h
63889@@ -46,9 +46,10 @@ struct proc_dir_entry {
63890 struct completion *pde_unload_completion;
63891 struct list_head pde_openers; /* who did ->open, but not ->release */
63892 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63893+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
63894 u8 namelen;
63895 char name[];
63896-};
63897+} __randomize_layout;
63898
63899 union proc_op {
63900 int (*proc_get_link)(struct dentry *, struct path *);
63901@@ -67,7 +68,7 @@ struct proc_inode {
63902 struct ctl_table *sysctl_entry;
63903 struct proc_ns ns;
63904 struct inode vfs_inode;
63905-};
63906+} __randomize_layout;
63907
63908 /*
63909 * General functions
63910@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63911 struct pid *, struct task_struct *);
63912 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63913 struct pid *, struct task_struct *);
63914+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63915+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63916+#endif
63917
63918 /*
63919 * base.c
63920@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
63921 extern spinlock_t proc_subdir_lock;
63922
63923 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
63924+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
63925 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
63926 struct dentry *);
63927 extern int proc_readdir(struct file *, struct dir_context *);
63928+extern int proc_readdir_restrict(struct file *, struct dir_context *);
63929 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
63930
63931 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
63932diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63933index a352d57..cb94a5c 100644
63934--- a/fs/proc/interrupts.c
63935+++ b/fs/proc/interrupts.c
63936@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63937
63938 static int __init proc_interrupts_init(void)
63939 {
63940+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63941+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63942+#else
63943 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63944+#endif
63945 return 0;
63946 }
63947 fs_initcall(proc_interrupts_init);
63948diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63949index 39e6ef3..2f9cb5e 100644
63950--- a/fs/proc/kcore.c
63951+++ b/fs/proc/kcore.c
63952@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63953 * the addresses in the elf_phdr on our list.
63954 */
63955 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63956- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63957+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63958+ if (tsz > buflen)
63959 tsz = buflen;
63960-
63961+
63962 while (buflen) {
63963 struct kcore_list *m;
63964
63965@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63966 kfree(elf_buf);
63967 } else {
63968 if (kern_addr_valid(start)) {
63969- unsigned long n;
63970+ char *elf_buf;
63971+ mm_segment_t oldfs;
63972
63973- n = copy_to_user(buffer, (char *)start, tsz);
63974- /*
63975- * We cannot distinguish between fault on source
63976- * and fault on destination. When this happens
63977- * we clear too and hope it will trigger the
63978- * EFAULT again.
63979- */
63980- if (n) {
63981- if (clear_user(buffer + tsz - n,
63982- n))
63983+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63984+ if (!elf_buf)
63985+ return -ENOMEM;
63986+ oldfs = get_fs();
63987+ set_fs(KERNEL_DS);
63988+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63989+ set_fs(oldfs);
63990+ if (copy_to_user(buffer, elf_buf, tsz)) {
63991+ kfree(elf_buf);
63992 return -EFAULT;
63993+ }
63994 }
63995+ set_fs(oldfs);
63996+ kfree(elf_buf);
63997 } else {
63998 if (clear_user(buffer, tsz))
63999 return -EFAULT;
64000@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64001
64002 static int open_kcore(struct inode *inode, struct file *filp)
64003 {
64004+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64005+ return -EPERM;
64006+#endif
64007 if (!capable(CAP_SYS_RAWIO))
64008 return -EPERM;
64009 if (kcore_need_update)
64010diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64011index 136e548..1f88922 100644
64012--- a/fs/proc/meminfo.c
64013+++ b/fs/proc/meminfo.c
64014@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64015 vmi.used >> 10,
64016 vmi.largest_chunk >> 10
64017 #ifdef CONFIG_MEMORY_FAILURE
64018- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64019+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64020 #endif
64021 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64022 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64023diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64024index d4a3574..b421ce9 100644
64025--- a/fs/proc/nommu.c
64026+++ b/fs/proc/nommu.c
64027@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64028
64029 if (file) {
64030 seq_pad(m, ' ');
64031- seq_path(m, &file->f_path, "");
64032+ seq_path(m, &file->f_path, "\n\\");
64033 }
64034
64035 seq_putc(m, '\n');
64036diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64037index 4677bb7..94067cd 100644
64038--- a/fs/proc/proc_net.c
64039+++ b/fs/proc/proc_net.c
64040@@ -23,6 +23,7 @@
64041 #include <linux/nsproxy.h>
64042 #include <net/net_namespace.h>
64043 #include <linux/seq_file.h>
64044+#include <linux/grsecurity.h>
64045
64046 #include "internal.h"
64047
64048@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64049 return maybe_get_net(PDE_NET(PDE(inode)));
64050 }
64051
64052+extern const struct seq_operations dev_seq_ops;
64053+
64054 int seq_open_net(struct inode *ino, struct file *f,
64055 const struct seq_operations *ops, int size)
64056 {
64057@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64058
64059 BUG_ON(size < sizeof(*p));
64060
64061+ /* only permit access to /proc/net/dev */
64062+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
64063+ return -EACCES;
64064+
64065 net = get_proc_net(ino);
64066 if (net == NULL)
64067 return -ENXIO;
64068@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64069 int err;
64070 struct net *net;
64071
64072+ if (gr_proc_is_restricted())
64073+ return -EACCES;
64074+
64075 err = -ENXIO;
64076 net = get_proc_net(inode);
64077 if (net == NULL)
64078diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64079index 7129046..6914844 100644
64080--- a/fs/proc/proc_sysctl.c
64081+++ b/fs/proc/proc_sysctl.c
64082@@ -11,13 +11,21 @@
64083 #include <linux/namei.h>
64084 #include <linux/mm.h>
64085 #include <linux/module.h>
64086+#include <linux/nsproxy.h>
64087+#ifdef CONFIG_GRKERNSEC
64088+#include <net/net_namespace.h>
64089+#endif
64090 #include "internal.h"
64091
64092+extern int gr_handle_chroot_sysctl(const int op);
64093+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64094+ const int op);
64095+
64096 static const struct dentry_operations proc_sys_dentry_operations;
64097 static const struct file_operations proc_sys_file_operations;
64098-static const struct inode_operations proc_sys_inode_operations;
64099+const struct inode_operations proc_sys_inode_operations;
64100 static const struct file_operations proc_sys_dir_file_operations;
64101-static const struct inode_operations proc_sys_dir_operations;
64102+const struct inode_operations proc_sys_dir_operations;
64103
64104 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64105 {
64106@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64107
64108 err = NULL;
64109 d_set_d_op(dentry, &proc_sys_dentry_operations);
64110+
64111+ gr_handle_proc_create(dentry, inode);
64112+
64113 d_add(dentry, inode);
64114
64115 out:
64116@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64117 struct inode *inode = file_inode(filp);
64118 struct ctl_table_header *head = grab_header(inode);
64119 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64120+ int op = write ? MAY_WRITE : MAY_READ;
64121 ssize_t error;
64122 size_t res;
64123
64124@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64125 * and won't be until we finish.
64126 */
64127 error = -EPERM;
64128- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64129+ if (sysctl_perm(head, table, op))
64130 goto out;
64131
64132 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64133@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64134 if (!table->proc_handler)
64135 goto out;
64136
64137+#ifdef CONFIG_GRKERNSEC
64138+ error = -EPERM;
64139+ if (gr_handle_chroot_sysctl(op))
64140+ goto out;
64141+ dget(filp->f_path.dentry);
64142+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64143+ dput(filp->f_path.dentry);
64144+ goto out;
64145+ }
64146+ dput(filp->f_path.dentry);
64147+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64148+ goto out;
64149+ if (write) {
64150+ if (current->nsproxy->net_ns != table->extra2) {
64151+ if (!capable(CAP_SYS_ADMIN))
64152+ goto out;
64153+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64154+ goto out;
64155+ }
64156+#endif
64157+
64158 /* careful: calling conventions are nasty here */
64159 res = count;
64160 error = table->proc_handler(table, write, buf, &res, ppos);
64161@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64162 return false;
64163 } else {
64164 d_set_d_op(child, &proc_sys_dentry_operations);
64165+
64166+ gr_handle_proc_create(child, inode);
64167+
64168 d_add(child, inode);
64169 }
64170 } else {
64171@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64172 if ((*pos)++ < ctx->pos)
64173 return true;
64174
64175+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64176+ return 0;
64177+
64178 if (unlikely(S_ISLNK(table->mode)))
64179 res = proc_sys_link_fill_cache(file, ctx, head, table);
64180 else
64181@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64182 if (IS_ERR(head))
64183 return PTR_ERR(head);
64184
64185+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64186+ return -ENOENT;
64187+
64188 generic_fillattr(inode, stat);
64189 if (table)
64190 stat->mode = (stat->mode & S_IFMT) | table->mode;
64191@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64192 .llseek = generic_file_llseek,
64193 };
64194
64195-static const struct inode_operations proc_sys_inode_operations = {
64196+const struct inode_operations proc_sys_inode_operations = {
64197 .permission = proc_sys_permission,
64198 .setattr = proc_sys_setattr,
64199 .getattr = proc_sys_getattr,
64200 };
64201
64202-static const struct inode_operations proc_sys_dir_operations = {
64203+const struct inode_operations proc_sys_dir_operations = {
64204 .lookup = proc_sys_lookup,
64205 .permission = proc_sys_permission,
64206 .setattr = proc_sys_setattr,
64207@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64208 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64209 const char *name, int namelen)
64210 {
64211- struct ctl_table *table;
64212+ ctl_table_no_const *table;
64213 struct ctl_dir *new;
64214 struct ctl_node *node;
64215 char *new_name;
64216@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64217 return NULL;
64218
64219 node = (struct ctl_node *)(new + 1);
64220- table = (struct ctl_table *)(node + 1);
64221+ table = (ctl_table_no_const *)(node + 1);
64222 new_name = (char *)(table + 2);
64223 memcpy(new_name, name, namelen);
64224 new_name[namelen] = '\0';
64225@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64226 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64227 struct ctl_table_root *link_root)
64228 {
64229- struct ctl_table *link_table, *entry, *link;
64230+ ctl_table_no_const *link_table, *link;
64231+ struct ctl_table *entry;
64232 struct ctl_table_header *links;
64233 struct ctl_node *node;
64234 char *link_name;
64235@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64236 return NULL;
64237
64238 node = (struct ctl_node *)(links + 1);
64239- link_table = (struct ctl_table *)(node + nr_entries);
64240+ link_table = (ctl_table_no_const *)(node + nr_entries);
64241 link_name = (char *)&link_table[nr_entries + 1];
64242
64243 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64244@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64245 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64246 struct ctl_table *table)
64247 {
64248- struct ctl_table *ctl_table_arg = NULL;
64249- struct ctl_table *entry, *files;
64250+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64251+ struct ctl_table *entry;
64252 int nr_files = 0;
64253 int nr_dirs = 0;
64254 int err = -ENOMEM;
64255@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64256 nr_files++;
64257 }
64258
64259- files = table;
64260 /* If there are mixed files and directories we need a new table */
64261 if (nr_dirs && nr_files) {
64262- struct ctl_table *new;
64263+ ctl_table_no_const *new;
64264 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64265 GFP_KERNEL);
64266 if (!files)
64267@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64268 /* Register everything except a directory full of subdirectories */
64269 if (nr_files || !nr_dirs) {
64270 struct ctl_table_header *header;
64271- header = __register_sysctl_table(set, path, files);
64272+ header = __register_sysctl_table(set, path, files ? files : table);
64273 if (!header) {
64274 kfree(ctl_table_arg);
64275 goto out;
64276diff --git a/fs/proc/root.c b/fs/proc/root.c
64277index 87dbcbe..55e1b4d 100644
64278--- a/fs/proc/root.c
64279+++ b/fs/proc/root.c
64280@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64281 #ifdef CONFIG_PROC_DEVICETREE
64282 proc_device_tree_init();
64283 #endif
64284+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64285+#ifdef CONFIG_GRKERNSEC_PROC_USER
64286+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64287+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64288+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64289+#endif
64290+#else
64291 proc_mkdir("bus", NULL);
64292+#endif
64293 proc_sys_init();
64294 }
64295
64296diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64297index 6f599c6..bd00271 100644
64298--- a/fs/proc/stat.c
64299+++ b/fs/proc/stat.c
64300@@ -11,6 +11,7 @@
64301 #include <linux/irqnr.h>
64302 #include <asm/cputime.h>
64303 #include <linux/tick.h>
64304+#include <linux/grsecurity.h>
64305
64306 #ifndef arch_irq_stat_cpu
64307 #define arch_irq_stat_cpu(cpu) 0
64308@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64309 u64 sum_softirq = 0;
64310 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64311 struct timespec boottime;
64312+ int unrestricted = 1;
64313+
64314+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64315+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64316+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64317+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64318+ && !in_group_p(grsec_proc_gid)
64319+#endif
64320+ )
64321+ unrestricted = 0;
64322+#endif
64323+#endif
64324
64325 user = nice = system = idle = iowait =
64326 irq = softirq = steal = 0;
64327@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64328 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64329 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64330 idle += get_idle_time(i);
64331- iowait += get_iowait_time(i);
64332- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64333- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64334- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64335- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64336- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64337- sum += kstat_cpu_irqs_sum(i);
64338- sum += arch_irq_stat_cpu(i);
64339+ if (unrestricted) {
64340+ iowait += get_iowait_time(i);
64341+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64342+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64343+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64344+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64345+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64346+ sum += kstat_cpu_irqs_sum(i);
64347+ sum += arch_irq_stat_cpu(i);
64348+ for (j = 0; j < NR_SOFTIRQS; j++) {
64349+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64350
64351- for (j = 0; j < NR_SOFTIRQS; j++) {
64352- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64353-
64354- per_softirq_sums[j] += softirq_stat;
64355- sum_softirq += softirq_stat;
64356+ per_softirq_sums[j] += softirq_stat;
64357+ sum_softirq += softirq_stat;
64358+ }
64359 }
64360 }
64361- sum += arch_irq_stat();
64362+ if (unrestricted)
64363+ sum += arch_irq_stat();
64364
64365 seq_puts(p, "cpu ");
64366 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64367@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64368 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64369 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64370 idle = get_idle_time(i);
64371- iowait = get_iowait_time(i);
64372- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64373- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64374- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64375- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64376- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64377+ if (unrestricted) {
64378+ iowait = get_iowait_time(i);
64379+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64380+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64381+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64382+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64383+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64384+ }
64385 seq_printf(p, "cpu%d", i);
64386 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64387 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64388@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64389
64390 /* sum again ? it could be updated? */
64391 for_each_irq_nr(j)
64392- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64393+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64394
64395 seq_printf(p,
64396 "\nctxt %llu\n"
64397@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64398 "processes %lu\n"
64399 "procs_running %lu\n"
64400 "procs_blocked %lu\n",
64401- nr_context_switches(),
64402+ unrestricted ? nr_context_switches() : 0ULL,
64403 (unsigned long)jif,
64404- total_forks,
64405- nr_running(),
64406- nr_iowait());
64407+ unrestricted ? total_forks : 0UL,
64408+ unrestricted ? nr_running() : 0UL,
64409+ unrestricted ? nr_iowait() : 0UL);
64410
64411 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64412
64413diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64414index fb52b54..5fc7c14 100644
64415--- a/fs/proc/task_mmu.c
64416+++ b/fs/proc/task_mmu.c
64417@@ -12,12 +12,19 @@
64418 #include <linux/swap.h>
64419 #include <linux/swapops.h>
64420 #include <linux/mmu_notifier.h>
64421+#include <linux/grsecurity.h>
64422
64423 #include <asm/elf.h>
64424 #include <asm/uaccess.h>
64425 #include <asm/tlbflush.h>
64426 #include "internal.h"
64427
64428+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64429+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64430+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64431+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64432+#endif
64433+
64434 void task_mem(struct seq_file *m, struct mm_struct *mm)
64435 {
64436 unsigned long data, text, lib, swap;
64437@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64438 "VmExe:\t%8lu kB\n"
64439 "VmLib:\t%8lu kB\n"
64440 "VmPTE:\t%8lu kB\n"
64441- "VmSwap:\t%8lu kB\n",
64442- hiwater_vm << (PAGE_SHIFT-10),
64443+ "VmSwap:\t%8lu kB\n"
64444+
64445+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64446+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64447+#endif
64448+
64449+ ,hiwater_vm << (PAGE_SHIFT-10),
64450 total_vm << (PAGE_SHIFT-10),
64451 mm->locked_vm << (PAGE_SHIFT-10),
64452 mm->pinned_vm << (PAGE_SHIFT-10),
64453@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64454 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64455 (PTRS_PER_PTE * sizeof(pte_t) *
64456 atomic_long_read(&mm->nr_ptes)) >> 10,
64457- swap << (PAGE_SHIFT-10));
64458+ swap << (PAGE_SHIFT-10)
64459+
64460+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64461+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64462+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64463+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64464+#else
64465+ , mm->context.user_cs_base
64466+ , mm->context.user_cs_limit
64467+#endif
64468+#endif
64469+
64470+ );
64471 }
64472
64473 unsigned long task_vsize(struct mm_struct *mm)
64474@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64475 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64476 }
64477
64478- /* We don't show the stack guard page in /proc/maps */
64479+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64480+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64481+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64482+#else
64483 start = vma->vm_start;
64484- if (stack_guard_page_start(vma, start))
64485- start += PAGE_SIZE;
64486 end = vma->vm_end;
64487- if (stack_guard_page_end(vma, end))
64488- end -= PAGE_SIZE;
64489+#endif
64490
64491 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64492 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64493@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64494 flags & VM_WRITE ? 'w' : '-',
64495 flags & VM_EXEC ? 'x' : '-',
64496 flags & VM_MAYSHARE ? 's' : 'p',
64497+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64498+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64499+#else
64500 pgoff,
64501+#endif
64502 MAJOR(dev), MINOR(dev), ino);
64503
64504 /*
64505@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64506 */
64507 if (file) {
64508 seq_pad(m, ' ');
64509- seq_path(m, &file->f_path, "\n");
64510+ seq_path(m, &file->f_path, "\n\\");
64511 goto done;
64512 }
64513
64514@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64515 * Thread stack in /proc/PID/task/TID/maps or
64516 * the main process stack.
64517 */
64518- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64519- vma->vm_end >= mm->start_stack)) {
64520+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64521+ (vma->vm_start <= mm->start_stack &&
64522+ vma->vm_end >= mm->start_stack)) {
64523 name = "[stack]";
64524 } else {
64525 /* Thread stack in /proc/PID/maps */
64526@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64527 struct proc_maps_private *priv = m->private;
64528 struct task_struct *task = priv->task;
64529
64530+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64531+ if (current->exec_id != m->exec_id) {
64532+ gr_log_badprocpid("maps");
64533+ return 0;
64534+ }
64535+#endif
64536+
64537 show_map_vma(m, vma, is_pid);
64538
64539 if (m->count < m->size) /* vma is copied successfully */
64540@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64541 .private = &mss,
64542 };
64543
64544+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64545+ if (current->exec_id != m->exec_id) {
64546+ gr_log_badprocpid("smaps");
64547+ return 0;
64548+ }
64549+#endif
64550 memset(&mss, 0, sizeof mss);
64551- mss.vma = vma;
64552- /* mmap_sem is held in m_start */
64553- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64554- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64555-
64556+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64557+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64558+#endif
64559+ mss.vma = vma;
64560+ /* mmap_sem is held in m_start */
64561+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64562+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64563+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64564+ }
64565+#endif
64566 show_map_vma(m, vma, is_pid);
64567
64568 seq_printf(m,
64569@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64570 "KernelPageSize: %8lu kB\n"
64571 "MMUPageSize: %8lu kB\n"
64572 "Locked: %8lu kB\n",
64573+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64574+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64575+#else
64576 (vma->vm_end - vma->vm_start) >> 10,
64577+#endif
64578 mss.resident >> 10,
64579 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64580 mss.shared_clean >> 10,
64581@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64582 char buffer[64];
64583 int nid;
64584
64585+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64586+ if (current->exec_id != m->exec_id) {
64587+ gr_log_badprocpid("numa_maps");
64588+ return 0;
64589+ }
64590+#endif
64591+
64592 if (!mm)
64593 return 0;
64594
64595@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64596 mpol_to_str(buffer, sizeof(buffer), pol);
64597 mpol_cond_put(pol);
64598
64599+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64600+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64601+#else
64602 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64603+#endif
64604
64605 if (file) {
64606 seq_printf(m, " file=");
64607- seq_path(m, &file->f_path, "\n\t= ");
64608+ seq_path(m, &file->f_path, "\n\t\\= ");
64609 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64610 seq_printf(m, " heap");
64611 } else {
64612diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64613index 678455d..ebd3245 100644
64614--- a/fs/proc/task_nommu.c
64615+++ b/fs/proc/task_nommu.c
64616@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64617 else
64618 bytes += kobjsize(mm);
64619
64620- if (current->fs && current->fs->users > 1)
64621+ if (current->fs && atomic_read(&current->fs->users) > 1)
64622 sbytes += kobjsize(current->fs);
64623 else
64624 bytes += kobjsize(current->fs);
64625@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64626
64627 if (file) {
64628 seq_pad(m, ' ');
64629- seq_path(m, &file->f_path, "");
64630+ seq_path(m, &file->f_path, "\n\\");
64631 } else if (mm) {
64632 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64633
64634diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64635index 88d4585..c10bfeb 100644
64636--- a/fs/proc/vmcore.c
64637+++ b/fs/proc/vmcore.c
64638@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64639 nr_bytes = count;
64640
64641 /* If pfn is not ram, return zeros for sparse dump files */
64642- if (pfn_is_ram(pfn) == 0)
64643- memset(buf, 0, nr_bytes);
64644- else {
64645+ if (pfn_is_ram(pfn) == 0) {
64646+ if (userbuf) {
64647+ if (clear_user((char __force_user *)buf, nr_bytes))
64648+ return -EFAULT;
64649+ } else
64650+ memset(buf, 0, nr_bytes);
64651+ } else {
64652 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64653 offset, userbuf);
64654 if (tmp < 0)
64655@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64656 static int copy_to(void *target, void *src, size_t size, int userbuf)
64657 {
64658 if (userbuf) {
64659- if (copy_to_user((char __user *) target, src, size))
64660+ if (copy_to_user((char __force_user *) target, src, size))
64661 return -EFAULT;
64662 } else {
64663 memcpy(target, src, size);
64664@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64665 if (*fpos < m->offset + m->size) {
64666 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64667 start = m->paddr + *fpos - m->offset;
64668- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64669+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64670 if (tmp < 0)
64671 return tmp;
64672 buflen -= tsz;
64673@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64674 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64675 size_t buflen, loff_t *fpos)
64676 {
64677- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64678+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64679 }
64680
64681 /*
64682diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64683index b00fcc9..e0c6381 100644
64684--- a/fs/qnx6/qnx6.h
64685+++ b/fs/qnx6/qnx6.h
64686@@ -74,7 +74,7 @@ enum {
64687 BYTESEX_BE,
64688 };
64689
64690-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64691+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64692 {
64693 if (sbi->s_bytesex == BYTESEX_LE)
64694 return le64_to_cpu((__force __le64)n);
64695@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64696 return (__force __fs64)cpu_to_be64(n);
64697 }
64698
64699-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64700+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64701 {
64702 if (sbi->s_bytesex == BYTESEX_LE)
64703 return le32_to_cpu((__force __le32)n);
64704diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64705index 72d2917..c917c12 100644
64706--- a/fs/quota/netlink.c
64707+++ b/fs/quota/netlink.c
64708@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64709 void quota_send_warning(struct kqid qid, dev_t dev,
64710 const char warntype)
64711 {
64712- static atomic_t seq;
64713+ static atomic_unchecked_t seq;
64714 struct sk_buff *skb;
64715 void *msg_head;
64716 int ret;
64717@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64718 "VFS: Not enough memory to send quota warning.\n");
64719 return;
64720 }
64721- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64722+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64723 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64724 if (!msg_head) {
64725 printk(KERN_ERR
64726diff --git a/fs/read_write.c b/fs/read_write.c
64727index 28cc9c8..208e4fb 100644
64728--- a/fs/read_write.c
64729+++ b/fs/read_write.c
64730@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64731
64732 old_fs = get_fs();
64733 set_fs(get_ds());
64734- p = (__force const char __user *)buf;
64735+ p = (const char __force_user *)buf;
64736 if (count > MAX_RW_COUNT)
64737 count = MAX_RW_COUNT;
64738 if (file->f_op->write)
64739diff --git a/fs/readdir.c b/fs/readdir.c
64740index 5b53d99..a6c3049 100644
64741--- a/fs/readdir.c
64742+++ b/fs/readdir.c
64743@@ -17,6 +17,7 @@
64744 #include <linux/security.h>
64745 #include <linux/syscalls.h>
64746 #include <linux/unistd.h>
64747+#include <linux/namei.h>
64748
64749 #include <asm/uaccess.h>
64750
64751@@ -69,6 +70,7 @@ struct old_linux_dirent {
64752 struct readdir_callback {
64753 struct dir_context ctx;
64754 struct old_linux_dirent __user * dirent;
64755+ struct file * file;
64756 int result;
64757 };
64758
64759@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64760 buf->result = -EOVERFLOW;
64761 return -EOVERFLOW;
64762 }
64763+
64764+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64765+ return 0;
64766+
64767 buf->result++;
64768 dirent = buf->dirent;
64769 if (!access_ok(VERIFY_WRITE, dirent,
64770@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64771 if (!f.file)
64772 return -EBADF;
64773
64774+ buf.file = f.file;
64775 error = iterate_dir(f.file, &buf.ctx);
64776 if (buf.result)
64777 error = buf.result;
64778@@ -142,6 +149,7 @@ struct getdents_callback {
64779 struct dir_context ctx;
64780 struct linux_dirent __user * current_dir;
64781 struct linux_dirent __user * previous;
64782+ struct file * file;
64783 int count;
64784 int error;
64785 };
64786@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64787 buf->error = -EOVERFLOW;
64788 return -EOVERFLOW;
64789 }
64790+
64791+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64792+ return 0;
64793+
64794 dirent = buf->previous;
64795 if (dirent) {
64796 if (__put_user(offset, &dirent->d_off))
64797@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64798 if (!f.file)
64799 return -EBADF;
64800
64801+ buf.file = f.file;
64802 error = iterate_dir(f.file, &buf.ctx);
64803 if (error >= 0)
64804 error = buf.error;
64805@@ -226,6 +239,7 @@ struct getdents_callback64 {
64806 struct dir_context ctx;
64807 struct linux_dirent64 __user * current_dir;
64808 struct linux_dirent64 __user * previous;
64809+ struct file *file;
64810 int count;
64811 int error;
64812 };
64813@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64814 buf->error = -EINVAL; /* only used if we fail.. */
64815 if (reclen > buf->count)
64816 return -EINVAL;
64817+
64818+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64819+ return 0;
64820+
64821 dirent = buf->previous;
64822 if (dirent) {
64823 if (__put_user(offset, &dirent->d_off))
64824@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64825 if (!f.file)
64826 return -EBADF;
64827
64828+ buf.file = f.file;
64829 error = iterate_dir(f.file, &buf.ctx);
64830 if (error >= 0)
64831 error = buf.error;
64832diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64833index 9a3c68c..767933e 100644
64834--- a/fs/reiserfs/do_balan.c
64835+++ b/fs/reiserfs/do_balan.c
64836@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64837 return;
64838 }
64839
64840- atomic_inc(&(fs_generation(tb->tb_sb)));
64841+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64842 do_balance_starts(tb);
64843
64844 /* balance leaf returns 0 except if combining L R and S into
64845diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64846index ee382ef..f4eb6eb5 100644
64847--- a/fs/reiserfs/item_ops.c
64848+++ b/fs/reiserfs/item_ops.c
64849@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64850 }
64851
64852 static struct item_operations errcatch_ops = {
64853- errcatch_bytes_number,
64854- errcatch_decrement_key,
64855- errcatch_is_left_mergeable,
64856- errcatch_print_item,
64857- errcatch_check_item,
64858+ .bytes_number = errcatch_bytes_number,
64859+ .decrement_key = errcatch_decrement_key,
64860+ .is_left_mergeable = errcatch_is_left_mergeable,
64861+ .print_item = errcatch_print_item,
64862+ .check_item = errcatch_check_item,
64863
64864- errcatch_create_vi,
64865- errcatch_check_left,
64866- errcatch_check_right,
64867- errcatch_part_size,
64868- errcatch_unit_num,
64869- errcatch_print_vi
64870+ .create_vi = errcatch_create_vi,
64871+ .check_left = errcatch_check_left,
64872+ .check_right = errcatch_check_right,
64873+ .part_size = errcatch_part_size,
64874+ .unit_num = errcatch_unit_num,
64875+ .print_vi = errcatch_print_vi
64876 };
64877
64878 //////////////////////////////////////////////////////////////////////////////
64879diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64880index 02b0b7d..c85018b 100644
64881--- a/fs/reiserfs/procfs.c
64882+++ b/fs/reiserfs/procfs.c
64883@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64884 "SMALL_TAILS " : "NO_TAILS ",
64885 replay_only(sb) ? "REPLAY_ONLY " : "",
64886 convert_reiserfs(sb) ? "CONV " : "",
64887- atomic_read(&r->s_generation_counter),
64888+ atomic_read_unchecked(&r->s_generation_counter),
64889 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64890 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64891 SF(s_good_search_by_key_reada), SF(s_bmaps),
64892diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64893index 8d06adf..7e1c9f8 100644
64894--- a/fs/reiserfs/reiserfs.h
64895+++ b/fs/reiserfs/reiserfs.h
64896@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64897 /* Comment? -Hans */
64898 wait_queue_head_t s_wait;
64899 /* To be obsoleted soon by per buffer seals.. -Hans */
64900- atomic_t s_generation_counter; // increased by one every time the
64901+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64902 // tree gets re-balanced
64903 unsigned long s_properties; /* File system properties. Currently holds
64904 on-disk FS format */
64905@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64906 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64907
64908 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64909-#define get_generation(s) atomic_read (&fs_generation(s))
64910+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64911 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64912 #define __fs_changed(gen,s) (gen != get_generation (s))
64913 #define fs_changed(gen,s) \
64914diff --git a/fs/select.c b/fs/select.c
64915index 467bb1c..cf9d65a 100644
64916--- a/fs/select.c
64917+++ b/fs/select.c
64918@@ -20,6 +20,7 @@
64919 #include <linux/export.h>
64920 #include <linux/slab.h>
64921 #include <linux/poll.h>
64922+#include <linux/security.h>
64923 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64924 #include <linux/file.h>
64925 #include <linux/fdtable.h>
64926@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64927 struct poll_list *walk = head;
64928 unsigned long todo = nfds;
64929
64930+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64931 if (nfds > rlimit(RLIMIT_NOFILE))
64932 return -EINVAL;
64933
64934diff --git a/fs/seq_file.c b/fs/seq_file.c
64935index 1d641bb..c2f4743 100644
64936--- a/fs/seq_file.c
64937+++ b/fs/seq_file.c
64938@@ -10,6 +10,8 @@
64939 #include <linux/seq_file.h>
64940 #include <linux/slab.h>
64941 #include <linux/cred.h>
64942+#include <linux/sched.h>
64943+#include <linux/grsecurity.h>
64944
64945 #include <asm/uaccess.h>
64946 #include <asm/page.h>
64947@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64948 #ifdef CONFIG_USER_NS
64949 p->user_ns = file->f_cred->user_ns;
64950 #endif
64951+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64952+ p->exec_id = current->exec_id;
64953+#endif
64954
64955 /*
64956 * Wrappers around seq_open(e.g. swaps_open) need to be
64957@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
64958 }
64959 EXPORT_SYMBOL(seq_open);
64960
64961+
64962+int seq_open_restrict(struct file *file, const struct seq_operations *op)
64963+{
64964+ if (gr_proc_is_restricted())
64965+ return -EACCES;
64966+
64967+ return seq_open(file, op);
64968+}
64969+EXPORT_SYMBOL(seq_open_restrict);
64970+
64971 static int traverse(struct seq_file *m, loff_t offset)
64972 {
64973 loff_t pos = 0, index;
64974@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64975 return 0;
64976 }
64977 if (!m->buf) {
64978- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64979+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64980 if (!m->buf)
64981 return -ENOMEM;
64982 }
64983@@ -137,7 +152,7 @@ Eoverflow:
64984 m->op->stop(m, p);
64985 kfree(m->buf);
64986 m->count = 0;
64987- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64988+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64989 return !m->buf ? -ENOMEM : -EAGAIN;
64990 }
64991
64992@@ -153,7 +168,7 @@ Eoverflow:
64993 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64994 {
64995 struct seq_file *m = file->private_data;
64996- size_t copied = 0;
64997+ ssize_t copied = 0;
64998 loff_t pos;
64999 size_t n;
65000 void *p;
65001@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65002
65003 /* grab buffer if we didn't have one */
65004 if (!m->buf) {
65005- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65006+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65007 if (!m->buf)
65008 goto Enomem;
65009 }
65010@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65011 m->op->stop(m, p);
65012 kfree(m->buf);
65013 m->count = 0;
65014- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65015+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65016 if (!m->buf)
65017 goto Enomem;
65018 m->version = 0;
65019@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65020 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65021 void *data)
65022 {
65023- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65024+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65025 int res = -ENOMEM;
65026
65027 if (op) {
65028@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65029 }
65030 EXPORT_SYMBOL(single_open_size);
65031
65032+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65033+ void *data)
65034+{
65035+ if (gr_proc_is_restricted())
65036+ return -EACCES;
65037+
65038+ return single_open(file, show, data);
65039+}
65040+EXPORT_SYMBOL(single_open_restrict);
65041+
65042+
65043 int single_release(struct inode *inode, struct file *file)
65044 {
65045 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65046diff --git a/fs/splice.c b/fs/splice.c
65047index 12028fa..a6f2619 100644
65048--- a/fs/splice.c
65049+++ b/fs/splice.c
65050@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65051 pipe_lock(pipe);
65052
65053 for (;;) {
65054- if (!pipe->readers) {
65055+ if (!atomic_read(&pipe->readers)) {
65056 send_sig(SIGPIPE, current, 0);
65057 if (!ret)
65058 ret = -EPIPE;
65059@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65060 page_nr++;
65061 ret += buf->len;
65062
65063- if (pipe->files)
65064+ if (atomic_read(&pipe->files))
65065 do_wakeup = 1;
65066
65067 if (!--spd->nr_pages)
65068@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65069 do_wakeup = 0;
65070 }
65071
65072- pipe->waiting_writers++;
65073+ atomic_inc(&pipe->waiting_writers);
65074 pipe_wait(pipe);
65075- pipe->waiting_writers--;
65076+ atomic_dec(&pipe->waiting_writers);
65077 }
65078
65079 pipe_unlock(pipe);
65080@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65081 old_fs = get_fs();
65082 set_fs(get_ds());
65083 /* The cast to a user pointer is valid due to the set_fs() */
65084- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65085+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65086 set_fs(old_fs);
65087
65088 return res;
65089@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65090 old_fs = get_fs();
65091 set_fs(get_ds());
65092 /* The cast to a user pointer is valid due to the set_fs() */
65093- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65094+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65095 set_fs(old_fs);
65096
65097 return res;
65098@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65099 goto err;
65100
65101 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65102- vec[i].iov_base = (void __user *) page_address(page);
65103+ vec[i].iov_base = (void __force_user *) page_address(page);
65104 vec[i].iov_len = this_len;
65105 spd.pages[i] = page;
65106 spd.nr_pages++;
65107@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65108 ops->release(pipe, buf);
65109 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65110 pipe->nrbufs--;
65111- if (pipe->files)
65112+ if (atomic_read(&pipe->files))
65113 sd->need_wakeup = true;
65114 }
65115
65116@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65117 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65118 {
65119 while (!pipe->nrbufs) {
65120- if (!pipe->writers)
65121+ if (!atomic_read(&pipe->writers))
65122 return 0;
65123
65124- if (!pipe->waiting_writers && sd->num_spliced)
65125+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65126 return 0;
65127
65128 if (sd->flags & SPLICE_F_NONBLOCK)
65129@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65130 * out of the pipe right after the splice_to_pipe(). So set
65131 * PIPE_READERS appropriately.
65132 */
65133- pipe->readers = 1;
65134+ atomic_set(&pipe->readers, 1);
65135
65136 current->splice_pipe = pipe;
65137 }
65138@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65139
65140 partial[buffers].offset = off;
65141 partial[buffers].len = plen;
65142+ partial[buffers].private = 0;
65143
65144 off = 0;
65145 len -= plen;
65146@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65147 ret = -ERESTARTSYS;
65148 break;
65149 }
65150- if (!pipe->writers)
65151+ if (!atomic_read(&pipe->writers))
65152 break;
65153- if (!pipe->waiting_writers) {
65154+ if (!atomic_read(&pipe->waiting_writers)) {
65155 if (flags & SPLICE_F_NONBLOCK) {
65156 ret = -EAGAIN;
65157 break;
65158@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65159 pipe_lock(pipe);
65160
65161 while (pipe->nrbufs >= pipe->buffers) {
65162- if (!pipe->readers) {
65163+ if (!atomic_read(&pipe->readers)) {
65164 send_sig(SIGPIPE, current, 0);
65165 ret = -EPIPE;
65166 break;
65167@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65168 ret = -ERESTARTSYS;
65169 break;
65170 }
65171- pipe->waiting_writers++;
65172+ atomic_inc(&pipe->waiting_writers);
65173 pipe_wait(pipe);
65174- pipe->waiting_writers--;
65175+ atomic_dec(&pipe->waiting_writers);
65176 }
65177
65178 pipe_unlock(pipe);
65179@@ -1880,14 +1881,14 @@ retry:
65180 pipe_double_lock(ipipe, opipe);
65181
65182 do {
65183- if (!opipe->readers) {
65184+ if (!atomic_read(&opipe->readers)) {
65185 send_sig(SIGPIPE, current, 0);
65186 if (!ret)
65187 ret = -EPIPE;
65188 break;
65189 }
65190
65191- if (!ipipe->nrbufs && !ipipe->writers)
65192+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65193 break;
65194
65195 /*
65196@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65197 pipe_double_lock(ipipe, opipe);
65198
65199 do {
65200- if (!opipe->readers) {
65201+ if (!atomic_read(&opipe->readers)) {
65202 send_sig(SIGPIPE, current, 0);
65203 if (!ret)
65204 ret = -EPIPE;
65205@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65206 * return EAGAIN if we have the potential of some data in the
65207 * future, otherwise just return 0
65208 */
65209- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65210+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65211 ret = -EAGAIN;
65212
65213 pipe_unlock(ipipe);
65214diff --git a/fs/stat.c b/fs/stat.c
65215index ae0c3ce..9ee641c 100644
65216--- a/fs/stat.c
65217+++ b/fs/stat.c
65218@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65219 stat->gid = inode->i_gid;
65220 stat->rdev = inode->i_rdev;
65221 stat->size = i_size_read(inode);
65222- stat->atime = inode->i_atime;
65223- stat->mtime = inode->i_mtime;
65224+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65225+ stat->atime = inode->i_ctime;
65226+ stat->mtime = inode->i_ctime;
65227+ } else {
65228+ stat->atime = inode->i_atime;
65229+ stat->mtime = inode->i_mtime;
65230+ }
65231 stat->ctime = inode->i_ctime;
65232 stat->blksize = (1 << inode->i_blkbits);
65233 stat->blocks = inode->i_blocks;
65234@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65235 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65236 {
65237 struct inode *inode = path->dentry->d_inode;
65238+ int retval;
65239
65240- if (inode->i_op->getattr)
65241- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65242+ if (inode->i_op->getattr) {
65243+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65244+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65245+ stat->atime = stat->ctime;
65246+ stat->mtime = stat->ctime;
65247+ }
65248+ return retval;
65249+ }
65250
65251 generic_fillattr(inode, stat);
65252 return 0;
65253diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65254index ee0d761..b346c58 100644
65255--- a/fs/sysfs/dir.c
65256+++ b/fs/sysfs/dir.c
65257@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65258 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65259 {
65260 struct kernfs_node *parent, *kn;
65261+ const char *name;
65262+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65263+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65264+ const char *parent_name;
65265+#endif
65266
65267 BUG_ON(!kobj);
65268
65269+ name = kobject_name(kobj);
65270+
65271 if (kobj->parent)
65272 parent = kobj->parent->sd;
65273 else
65274@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65275 if (!parent)
65276 return -ENOENT;
65277
65278- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65279- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65280+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65281+ parent_name = parent->name;
65282+ mode = S_IRWXU;
65283+
65284+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65285+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65286+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65287+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65288+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65289+#endif
65290+
65291+ kn = kernfs_create_dir_ns(parent, name,
65292+ mode, kobj, ns);
65293 if (IS_ERR(kn)) {
65294 if (PTR_ERR(kn) == -EEXIST)
65295- sysfs_warn_dup(parent, kobject_name(kobj));
65296+ sysfs_warn_dup(parent, name);
65297 return PTR_ERR(kn);
65298 }
65299
65300diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65301index 69d4889..a810bd4 100644
65302--- a/fs/sysv/sysv.h
65303+++ b/fs/sysv/sysv.h
65304@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65305 #endif
65306 }
65307
65308-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65309+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65310 {
65311 if (sbi->s_bytesex == BYTESEX_PDP)
65312 return PDP_swab((__force __u32)n);
65313diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65314index e18b988..f1d4ad0f 100644
65315--- a/fs/ubifs/io.c
65316+++ b/fs/ubifs/io.c
65317@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65318 return err;
65319 }
65320
65321-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65322+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65323 {
65324 int err;
65325
65326diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65327index c175b4d..8f36a16 100644
65328--- a/fs/udf/misc.c
65329+++ b/fs/udf/misc.c
65330@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65331
65332 u8 udf_tag_checksum(const struct tag *t)
65333 {
65334- u8 *data = (u8 *)t;
65335+ const u8 *data = (const u8 *)t;
65336 u8 checksum = 0;
65337 int i;
65338 for (i = 0; i < sizeof(struct tag); ++i)
65339diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65340index 8d974c4..b82f6ec 100644
65341--- a/fs/ufs/swab.h
65342+++ b/fs/ufs/swab.h
65343@@ -22,7 +22,7 @@ enum {
65344 BYTESEX_BE
65345 };
65346
65347-static inline u64
65348+static inline u64 __intentional_overflow(-1)
65349 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65350 {
65351 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65352@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65353 return (__force __fs64)cpu_to_be64(n);
65354 }
65355
65356-static inline u32
65357+static inline u32 __intentional_overflow(-1)
65358 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65359 {
65360 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65361diff --git a/fs/utimes.c b/fs/utimes.c
65362index aa138d6..5f3a811 100644
65363--- a/fs/utimes.c
65364+++ b/fs/utimes.c
65365@@ -1,6 +1,7 @@
65366 #include <linux/compiler.h>
65367 #include <linux/file.h>
65368 #include <linux/fs.h>
65369+#include <linux/security.h>
65370 #include <linux/linkage.h>
65371 #include <linux/mount.h>
65372 #include <linux/namei.h>
65373@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65374 }
65375 }
65376 retry_deleg:
65377+
65378+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65379+ error = -EACCES;
65380+ goto mnt_drop_write_and_out;
65381+ }
65382+
65383 mutex_lock(&inode->i_mutex);
65384 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65385 mutex_unlock(&inode->i_mutex);
65386diff --git a/fs/xattr.c b/fs/xattr.c
65387index 3377dff..f394815 100644
65388--- a/fs/xattr.c
65389+++ b/fs/xattr.c
65390@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65391 return rc;
65392 }
65393
65394+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65395+ssize_t
65396+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65397+{
65398+ struct inode *inode = dentry->d_inode;
65399+ ssize_t error;
65400+
65401+ error = inode_permission(inode, MAY_EXEC);
65402+ if (error)
65403+ return error;
65404+
65405+ if (inode->i_op->getxattr)
65406+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65407+ else
65408+ error = -EOPNOTSUPP;
65409+
65410+ return error;
65411+}
65412+EXPORT_SYMBOL(pax_getxattr);
65413+#endif
65414+
65415 ssize_t
65416 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65417 {
65418@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65419 * Extended attribute SET operations
65420 */
65421 static long
65422-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65423+setxattr(struct path *path, const char __user *name, const void __user *value,
65424 size_t size, int flags)
65425 {
65426 int error;
65427@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65428 posix_acl_fix_xattr_from_user(kvalue, size);
65429 }
65430
65431- error = vfs_setxattr(d, kname, kvalue, size, flags);
65432+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65433+ error = -EACCES;
65434+ goto out;
65435+ }
65436+
65437+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65438 out:
65439 if (vvalue)
65440 vfree(vvalue);
65441@@ -377,7 +403,7 @@ retry:
65442 return error;
65443 error = mnt_want_write(path.mnt);
65444 if (!error) {
65445- error = setxattr(path.dentry, name, value, size, flags);
65446+ error = setxattr(&path, name, value, size, flags);
65447 mnt_drop_write(path.mnt);
65448 }
65449 path_put(&path);
65450@@ -401,7 +427,7 @@ retry:
65451 return error;
65452 error = mnt_want_write(path.mnt);
65453 if (!error) {
65454- error = setxattr(path.dentry, name, value, size, flags);
65455+ error = setxattr(&path, name, value, size, flags);
65456 mnt_drop_write(path.mnt);
65457 }
65458 path_put(&path);
65459@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65460 const void __user *,value, size_t, size, int, flags)
65461 {
65462 struct fd f = fdget(fd);
65463- struct dentry *dentry;
65464 int error = -EBADF;
65465
65466 if (!f.file)
65467 return error;
65468- dentry = f.file->f_path.dentry;
65469- audit_inode(NULL, dentry, 0);
65470+ audit_inode(NULL, f.file->f_path.dentry, 0);
65471 error = mnt_want_write_file(f.file);
65472 if (!error) {
65473- error = setxattr(dentry, name, value, size, flags);
65474+ error = setxattr(&f.file->f_path, name, value, size, flags);
65475 mnt_drop_write_file(f.file);
65476 }
65477 fdput(f);
65478@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65479 * Extended attribute REMOVE operations
65480 */
65481 static long
65482-removexattr(struct dentry *d, const char __user *name)
65483+removexattr(struct path *path, const char __user *name)
65484 {
65485 int error;
65486 char kname[XATTR_NAME_MAX + 1];
65487@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65488 if (error < 0)
65489 return error;
65490
65491- return vfs_removexattr(d, kname);
65492+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65493+ return -EACCES;
65494+
65495+ return vfs_removexattr(path->dentry, kname);
65496 }
65497
65498 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65499@@ -652,7 +679,7 @@ retry:
65500 return error;
65501 error = mnt_want_write(path.mnt);
65502 if (!error) {
65503- error = removexattr(path.dentry, name);
65504+ error = removexattr(&path, name);
65505 mnt_drop_write(path.mnt);
65506 }
65507 path_put(&path);
65508@@ -675,7 +702,7 @@ retry:
65509 return error;
65510 error = mnt_want_write(path.mnt);
65511 if (!error) {
65512- error = removexattr(path.dentry, name);
65513+ error = removexattr(&path, name);
65514 mnt_drop_write(path.mnt);
65515 }
65516 path_put(&path);
65517@@ -689,16 +716,16 @@ retry:
65518 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65519 {
65520 struct fd f = fdget(fd);
65521- struct dentry *dentry;
65522+ struct path *path;
65523 int error = -EBADF;
65524
65525 if (!f.file)
65526 return error;
65527- dentry = f.file->f_path.dentry;
65528- audit_inode(NULL, dentry, 0);
65529+ path = &f.file->f_path;
65530+ audit_inode(NULL, path->dentry, 0);
65531 error = mnt_want_write_file(f.file);
65532 if (!error) {
65533- error = removexattr(dentry, name);
65534+ error = removexattr(path, name);
65535 mnt_drop_write_file(f.file);
65536 }
65537 fdput(f);
65538diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65539index 152543c..d80c361 100644
65540--- a/fs/xfs/xfs_bmap.c
65541+++ b/fs/xfs/xfs_bmap.c
65542@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65543
65544 #else
65545 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65546-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65547+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65548 #endif /* DEBUG */
65549
65550 /*
65551diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65552index aead369..0dfecfd 100644
65553--- a/fs/xfs/xfs_dir2_readdir.c
65554+++ b/fs/xfs/xfs_dir2_readdir.c
65555@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65556 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65557 filetype = dp->d_ops->sf_get_ftype(sfep);
65558 ctx->pos = off & 0x7fffffff;
65559- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65560+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65561+ char name[sfep->namelen];
65562+ memcpy(name, sfep->name, sfep->namelen);
65563+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65564+ return 0;
65565+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65566 xfs_dir3_get_dtype(mp, filetype)))
65567 return 0;
65568 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65569diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65570index bcfe612..aa399c0 100644
65571--- a/fs/xfs/xfs_ioctl.c
65572+++ b/fs/xfs/xfs_ioctl.c
65573@@ -122,7 +122,7 @@ xfs_find_handle(
65574 }
65575
65576 error = -EFAULT;
65577- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65578+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65579 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65580 goto out_put;
65581
65582diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65583new file mode 100644
65584index 0000000..3abaf02
65585--- /dev/null
65586+++ b/grsecurity/Kconfig
65587@@ -0,0 +1,1161 @@
65588+#
65589+# grecurity configuration
65590+#
65591+menu "Memory Protections"
65592+depends on GRKERNSEC
65593+
65594+config GRKERNSEC_KMEM
65595+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65596+ default y if GRKERNSEC_CONFIG_AUTO
65597+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65598+ help
65599+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65600+ be written to or read from to modify or leak the contents of the running
65601+ kernel. /dev/port will also not be allowed to be opened, writing to
65602+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65603+ If you have module support disabled, enabling this will close up several
65604+ ways that are currently used to insert malicious code into the running
65605+ kernel.
65606+
65607+ Even with this feature enabled, we still highly recommend that
65608+ you use the RBAC system, as it is still possible for an attacker to
65609+ modify the running kernel through other more obscure methods.
65610+
65611+ It is highly recommended that you say Y here if you meet all the
65612+ conditions above.
65613+
65614+config GRKERNSEC_VM86
65615+ bool "Restrict VM86 mode"
65616+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65617+ depends on X86_32
65618+
65619+ help
65620+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65621+ make use of a special execution mode on 32bit x86 processors called
65622+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65623+ video cards and will still work with this option enabled. The purpose
65624+ of the option is to prevent exploitation of emulation errors in
65625+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65626+ Nearly all users should be able to enable this option.
65627+
65628+config GRKERNSEC_IO
65629+ bool "Disable privileged I/O"
65630+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65631+ depends on X86
65632+ select RTC_CLASS
65633+ select RTC_INTF_DEV
65634+ select RTC_DRV_CMOS
65635+
65636+ help
65637+ If you say Y here, all ioperm and iopl calls will return an error.
65638+ Ioperm and iopl can be used to modify the running kernel.
65639+ Unfortunately, some programs need this access to operate properly,
65640+ the most notable of which are XFree86 and hwclock. hwclock can be
65641+ remedied by having RTC support in the kernel, so real-time
65642+ clock support is enabled if this option is enabled, to ensure
65643+ that hwclock operates correctly. If hwclock still does not work,
65644+ either update udev or symlink /dev/rtc to /dev/rtc0.
65645+
65646+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65647+ you may not be able to boot into a graphical environment with this
65648+ option enabled. In this case, you should use the RBAC system instead.
65649+
65650+config GRKERNSEC_JIT_HARDEN
65651+ bool "Harden BPF JIT against spray attacks"
65652+ default y if GRKERNSEC_CONFIG_AUTO
65653+ depends on BPF_JIT && X86
65654+ help
65655+ If you say Y here, the native code generated by the kernel's Berkeley
65656+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65657+ attacks that attempt to fit attacker-beneficial instructions in
65658+ 32bit immediate fields of JIT-generated native instructions. The
65659+ attacker will generally aim to cause an unintended instruction sequence
65660+ of JIT-generated native code to execute by jumping into the middle of
65661+ a generated instruction. This feature effectively randomizes the 32bit
65662+ immediate constants present in the generated code to thwart such attacks.
65663+
65664+ If you're using KERNEXEC, it's recommended that you enable this option
65665+ to supplement the hardening of the kernel.
65666+
65667+config GRKERNSEC_PERF_HARDEN
65668+ bool "Disable unprivileged PERF_EVENTS usage by default"
65669+ default y if GRKERNSEC_CONFIG_AUTO
65670+ depends on PERF_EVENTS
65671+ help
65672+ If you say Y here, the range of acceptable values for the
65673+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65674+ default to a new value: 3. When the sysctl is set to this value, no
65675+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65676+
65677+ Though PERF_EVENTS can be used legitimately for performance monitoring
65678+ and low-level application profiling, it is forced on regardless of
65679+ configuration, has been at fault for several vulnerabilities, and
65680+ creates new opportunities for side channels and other information leaks.
65681+
65682+ This feature puts PERF_EVENTS into a secure default state and permits
65683+ the administrator to change out of it temporarily if unprivileged
65684+ application profiling is needed.
65685+
65686+config GRKERNSEC_RAND_THREADSTACK
65687+ bool "Insert random gaps between thread stacks"
65688+ default y if GRKERNSEC_CONFIG_AUTO
65689+ depends on PAX_RANDMMAP && !PPC
65690+ help
65691+ If you say Y here, a random-sized gap will be enforced between allocated
65692+ thread stacks. Glibc's NPTL and other threading libraries that
65693+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65694+ The implementation currently provides 8 bits of entropy for the gap.
65695+
65696+ Many distributions do not compile threaded remote services with the
65697+ -fstack-check argument to GCC, causing the variable-sized stack-based
65698+ allocator, alloca(), to not probe the stack on allocation. This
65699+ permits an unbounded alloca() to skip over any guard page and potentially
65700+ modify another thread's stack reliably. An enforced random gap
65701+ reduces the reliability of such an attack and increases the chance
65702+ that such a read/write to another thread's stack instead lands in
65703+ an unmapped area, causing a crash and triggering grsecurity's
65704+ anti-bruteforcing logic.
65705+
65706+config GRKERNSEC_PROC_MEMMAP
65707+ bool "Harden ASLR against information leaks and entropy reduction"
65708+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65709+ depends on PAX_NOEXEC || PAX_ASLR
65710+ help
65711+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65712+ give no information about the addresses of its mappings if
65713+ PaX features that rely on random addresses are enabled on the task.
65714+ In addition to sanitizing this information and disabling other
65715+ dangerous sources of information, this option causes reads of sensitive
65716+ /proc/<pid> entries where the file descriptor was opened in a different
65717+ task than the one performing the read. Such attempts are logged.
65718+ This option also limits argv/env strings for suid/sgid binaries
65719+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65720+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65721+ binaries to prevent alternative mmap layouts from being abused.
65722+
65723+ If you use PaX it is essential that you say Y here as it closes up
65724+ several holes that make full ASLR useless locally.
65725+
65726+config GRKERNSEC_BRUTE
65727+ bool "Deter exploit bruteforcing"
65728+ default y if GRKERNSEC_CONFIG_AUTO
65729+ help
65730+ If you say Y here, attempts to bruteforce exploits against forking
65731+ daemons such as apache or sshd, as well as against suid/sgid binaries
65732+ will be deterred. When a child of a forking daemon is killed by PaX
65733+ or crashes due to an illegal instruction or other suspicious signal,
65734+ the parent process will be delayed 30 seconds upon every subsequent
65735+ fork until the administrator is able to assess the situation and
65736+ restart the daemon.
65737+ In the suid/sgid case, the attempt is logged, the user has all their
65738+ existing instances of the suid/sgid binary terminated and will
65739+ be unable to execute any suid/sgid binaries for 15 minutes.
65740+
65741+ It is recommended that you also enable signal logging in the auditing
65742+ section so that logs are generated when a process triggers a suspicious
65743+ signal.
65744+ If the sysctl option is enabled, a sysctl option with name
65745+ "deter_bruteforce" is created.
65746+
65747+config GRKERNSEC_MODHARDEN
65748+ bool "Harden module auto-loading"
65749+ default y if GRKERNSEC_CONFIG_AUTO
65750+ depends on MODULES
65751+ help
65752+ If you say Y here, module auto-loading in response to use of some
65753+ feature implemented by an unloaded module will be restricted to
65754+ root users. Enabling this option helps defend against attacks
65755+ by unprivileged users who abuse the auto-loading behavior to
65756+ cause a vulnerable module to load that is then exploited.
65757+
65758+ If this option prevents a legitimate use of auto-loading for a
65759+ non-root user, the administrator can execute modprobe manually
65760+ with the exact name of the module mentioned in the alert log.
65761+ Alternatively, the administrator can add the module to the list
65762+ of modules loaded at boot by modifying init scripts.
65763+
65764+ Modification of init scripts will most likely be needed on
65765+ Ubuntu servers with encrypted home directory support enabled,
65766+ as the first non-root user logging in will cause the ecb(aes),
65767+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65768+
65769+config GRKERNSEC_HIDESYM
65770+ bool "Hide kernel symbols"
65771+ default y if GRKERNSEC_CONFIG_AUTO
65772+ select PAX_USERCOPY_SLABS
65773+ help
65774+ If you say Y here, getting information on loaded modules, and
65775+ displaying all kernel symbols through a syscall will be restricted
65776+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65777+ /proc/kallsyms will be restricted to the root user. The RBAC
65778+ system can hide that entry even from root.
65779+
65780+ This option also prevents leaking of kernel addresses through
65781+ several /proc entries.
65782+
65783+ Note that this option is only effective provided the following
65784+ conditions are met:
65785+ 1) The kernel using grsecurity is not precompiled by some distribution
65786+ 2) You have also enabled GRKERNSEC_DMESG
65787+ 3) You are using the RBAC system and hiding other files such as your
65788+ kernel image and System.map. Alternatively, enabling this option
65789+ causes the permissions on /boot, /lib/modules, and the kernel
65790+ source directory to change at compile time to prevent
65791+ reading by non-root users.
65792+ If the above conditions are met, this option will aid in providing a
65793+ useful protection against local kernel exploitation of overflows
65794+ and arbitrary read/write vulnerabilities.
65795+
65796+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65797+ in addition to this feature.
65798+
65799+config GRKERNSEC_RANDSTRUCT
65800+ bool "Randomize layout of sensitive kernel structures"
65801+ default y if GRKERNSEC_CONFIG_AUTO
65802+ select GRKERNSEC_HIDESYM
65803+ select MODVERSIONS if MODULES
65804+ help
65805+ If you say Y here, the layouts of a number of sensitive kernel
65806+ structures (task, fs, cred, etc) and all structures composed entirely
65807+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65808+ This can introduce the requirement of an additional infoleak
65809+ vulnerability for exploits targeting these structure types.
65810+
65811+ Enabling this feature will introduce some performance impact, slightly
65812+ increase memory usage, and prevent the use of forensic tools like
65813+ Volatility against the system (unless the kernel source tree isn't
65814+ cleaned after kernel installation).
65815+
65816+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65817+ It remains after a make clean to allow for external modules to be compiled
65818+ with the existing seed and will be removed by a make mrproper or
65819+ make distclean.
65820+
65821+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65822+ to install the supporting headers explicitly in addition to the normal
65823+ gcc package.
65824+
65825+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65826+ bool "Use cacheline-aware structure randomization"
65827+ depends on GRKERNSEC_RANDSTRUCT
65828+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65829+ help
65830+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65831+ at restricting randomization to cacheline-sized groups of elements. It
65832+ will further not randomize bitfields in structures. This reduces the
65833+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65834+
65835+config GRKERNSEC_KERN_LOCKOUT
65836+ bool "Active kernel exploit response"
65837+ default y if GRKERNSEC_CONFIG_AUTO
65838+ depends on X86 || ARM || PPC || SPARC
65839+ help
65840+ If you say Y here, when a PaX alert is triggered due to suspicious
65841+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65842+ or an OOPS occurs due to bad memory accesses, instead of just
65843+ terminating the offending process (and potentially allowing
65844+ a subsequent exploit from the same user), we will take one of two
65845+ actions:
65846+ If the user was root, we will panic the system
65847+ If the user was non-root, we will log the attempt, terminate
65848+ all processes owned by the user, then prevent them from creating
65849+ any new processes until the system is restarted
65850+ This deters repeated kernel exploitation/bruteforcing attempts
65851+ and is useful for later forensics.
65852+
65853+config GRKERNSEC_OLD_ARM_USERLAND
65854+ bool "Old ARM userland compatibility"
65855+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65856+ help
65857+ If you say Y here, stubs of executable code to perform such operations
65858+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65859+ table. This is unfortunately needed for old ARM userland meant to run
65860+ across a wide range of processors. Without this option enabled,
65861+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65862+ which is enough for Linaro userlands or other userlands designed for v6
65863+ and newer ARM CPUs. It's recommended that you try without this option enabled
65864+ first, and only enable it if your userland does not boot (it will likely fail
65865+ at init time).
65866+
65867+endmenu
65868+menu "Role Based Access Control Options"
65869+depends on GRKERNSEC
65870+
65871+config GRKERNSEC_RBAC_DEBUG
65872+ bool
65873+
65874+config GRKERNSEC_NO_RBAC
65875+ bool "Disable RBAC system"
65876+ help
65877+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65878+ preventing the RBAC system from being enabled. You should only say Y
65879+ here if you have no intention of using the RBAC system, so as to prevent
65880+ an attacker with root access from misusing the RBAC system to hide files
65881+ and processes when loadable module support and /dev/[k]mem have been
65882+ locked down.
65883+
65884+config GRKERNSEC_ACL_HIDEKERN
65885+ bool "Hide kernel processes"
65886+ help
65887+ If you say Y here, all kernel threads will be hidden to all
65888+ processes but those whose subject has the "view hidden processes"
65889+ flag.
65890+
65891+config GRKERNSEC_ACL_MAXTRIES
65892+ int "Maximum tries before password lockout"
65893+ default 3
65894+ help
65895+ This option enforces the maximum number of times a user can attempt
65896+ to authorize themselves with the grsecurity RBAC system before being
65897+ denied the ability to attempt authorization again for a specified time.
65898+ The lower the number, the harder it will be to brute-force a password.
65899+
65900+config GRKERNSEC_ACL_TIMEOUT
65901+ int "Time to wait after max password tries, in seconds"
65902+ default 30
65903+ help
65904+ This option specifies the time the user must wait after attempting to
65905+ authorize to the RBAC system with the maximum number of invalid
65906+ passwords. The higher the number, the harder it will be to brute-force
65907+ a password.
65908+
65909+endmenu
65910+menu "Filesystem Protections"
65911+depends on GRKERNSEC
65912+
65913+config GRKERNSEC_PROC
65914+ bool "Proc restrictions"
65915+ default y if GRKERNSEC_CONFIG_AUTO
65916+ help
65917+ If you say Y here, the permissions of the /proc filesystem
65918+ will be altered to enhance system security and privacy. You MUST
65919+ choose either a user only restriction or a user and group restriction.
65920+ Depending upon the option you choose, you can either restrict users to
65921+ see only the processes they themselves run, or choose a group that can
65922+ view all processes and files normally restricted to root if you choose
65923+ the "restrict to user only" option. NOTE: If you're running identd or
65924+ ntpd as a non-root user, you will have to run it as the group you
65925+ specify here.
65926+
65927+config GRKERNSEC_PROC_USER
65928+ bool "Restrict /proc to user only"
65929+ depends on GRKERNSEC_PROC
65930+ help
65931+ If you say Y here, non-root users will only be able to view their own
65932+ processes, and restricts them from viewing network-related information,
65933+ and viewing kernel symbol and module information.
65934+
65935+config GRKERNSEC_PROC_USERGROUP
65936+ bool "Allow special group"
65937+ default y if GRKERNSEC_CONFIG_AUTO
65938+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65939+ help
65940+ If you say Y here, you will be able to select a group that will be
65941+ able to view all processes and network-related information. If you've
65942+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65943+ remain hidden. This option is useful if you want to run identd as
65944+ a non-root user. The group you select may also be chosen at boot time
65945+ via "grsec_proc_gid=" on the kernel commandline.
65946+
65947+config GRKERNSEC_PROC_GID
65948+ int "GID for special group"
65949+ depends on GRKERNSEC_PROC_USERGROUP
65950+ default 1001
65951+
65952+config GRKERNSEC_PROC_ADD
65953+ bool "Additional restrictions"
65954+ default y if GRKERNSEC_CONFIG_AUTO
65955+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65956+ help
65957+ If you say Y here, additional restrictions will be placed on
65958+ /proc that keep normal users from viewing device information and
65959+ slabinfo information that could be useful for exploits.
65960+
65961+config GRKERNSEC_LINK
65962+ bool "Linking restrictions"
65963+ default y if GRKERNSEC_CONFIG_AUTO
65964+ help
65965+ If you say Y here, /tmp race exploits will be prevented, since users
65966+ will no longer be able to follow symlinks owned by other users in
65967+ world-writable +t directories (e.g. /tmp), unless the owner of the
65968+ symlink is the owner of the directory. users will also not be
65969+ able to hardlink to files they do not own. If the sysctl option is
65970+ enabled, a sysctl option with name "linking_restrictions" is created.
65971+
65972+config GRKERNSEC_SYMLINKOWN
65973+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65974+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65975+ help
65976+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65977+ that prevents it from being used as a security feature. As Apache
65978+ verifies the symlink by performing a stat() against the target of
65979+ the symlink before it is followed, an attacker can setup a symlink
65980+ to point to a same-owned file, then replace the symlink with one
65981+ that targets another user's file just after Apache "validates" the
65982+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65983+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65984+ will be in place for the group you specify. If the sysctl option
65985+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65986+ created.
65987+
65988+config GRKERNSEC_SYMLINKOWN_GID
65989+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65990+ depends on GRKERNSEC_SYMLINKOWN
65991+ default 1006
65992+ help
65993+ Setting this GID determines what group kernel-enforced
65994+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65995+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65996+
65997+config GRKERNSEC_FIFO
65998+ bool "FIFO restrictions"
65999+ default y if GRKERNSEC_CONFIG_AUTO
66000+ help
66001+ If you say Y here, users will not be able to write to FIFOs they don't
66002+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66003+ the FIFO is the same owner of the directory it's held in. If the sysctl
66004+ option is enabled, a sysctl option with name "fifo_restrictions" is
66005+ created.
66006+
66007+config GRKERNSEC_SYSFS_RESTRICT
66008+ bool "Sysfs/debugfs restriction"
66009+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66010+ depends on SYSFS
66011+ help
66012+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66013+ any filesystem normally mounted under it (e.g. debugfs) will be
66014+ mostly accessible only by root. These filesystems generally provide access
66015+ to hardware and debug information that isn't appropriate for unprivileged
66016+ users of the system. Sysfs and debugfs have also become a large source
66017+ of new vulnerabilities, ranging from infoleaks to local compromise.
66018+ There has been very little oversight with an eye toward security involved
66019+ in adding new exporters of information to these filesystems, so their
66020+ use is discouraged.
66021+ For reasons of compatibility, a few directories have been whitelisted
66022+ for access by non-root users:
66023+ /sys/fs/selinux
66024+ /sys/fs/fuse
66025+ /sys/devices/system/cpu
66026+
66027+config GRKERNSEC_ROFS
66028+ bool "Runtime read-only mount protection"
66029+ depends on SYSCTL
66030+ help
66031+ If you say Y here, a sysctl option with name "romount_protect" will
66032+ be created. By setting this option to 1 at runtime, filesystems
66033+ will be protected in the following ways:
66034+ * No new writable mounts will be allowed
66035+ * Existing read-only mounts won't be able to be remounted read/write
66036+ * Write operations will be denied on all block devices
66037+ This option acts independently of grsec_lock: once it is set to 1,
66038+ it cannot be turned off. Therefore, please be mindful of the resulting
66039+ behavior if this option is enabled in an init script on a read-only
66040+ filesystem.
66041+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66042+ and GRKERNSEC_IO should be enabled and module loading disabled via
66043+ config or at runtime.
66044+ This feature is mainly intended for secure embedded systems.
66045+
66046+
66047+config GRKERNSEC_DEVICE_SIDECHANNEL
66048+ bool "Eliminate stat/notify-based device sidechannels"
66049+ default y if GRKERNSEC_CONFIG_AUTO
66050+ help
66051+ If you say Y here, timing analyses on block or character
66052+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66053+ will be thwarted for unprivileged users. If a process without
66054+ CAP_MKNOD stats such a device, the last access and last modify times
66055+ will match the device's create time. No access or modify events
66056+ will be triggered through inotify/dnotify/fanotify for such devices.
66057+ This feature will prevent attacks that may at a minimum
66058+ allow an attacker to determine the administrator's password length.
66059+
66060+config GRKERNSEC_CHROOT
66061+ bool "Chroot jail restrictions"
66062+ default y if GRKERNSEC_CONFIG_AUTO
66063+ help
66064+ If you say Y here, you will be able to choose several options that will
66065+ make breaking out of a chrooted jail much more difficult. If you
66066+ encounter no software incompatibilities with the following options, it
66067+ is recommended that you enable each one.
66068+
66069+ Note that the chroot restrictions are not intended to apply to "chroots"
66070+ to directories that are simple bind mounts of the global root filesystem.
66071+ For several other reasons, a user shouldn't expect any significant
66072+ security by performing such a chroot.
66073+
66074+config GRKERNSEC_CHROOT_MOUNT
66075+ bool "Deny mounts"
66076+ default y if GRKERNSEC_CONFIG_AUTO
66077+ depends on GRKERNSEC_CHROOT
66078+ help
66079+ If you say Y here, processes inside a chroot will not be able to
66080+ mount or remount filesystems. If the sysctl option is enabled, a
66081+ sysctl option with name "chroot_deny_mount" is created.
66082+
66083+config GRKERNSEC_CHROOT_DOUBLE
66084+ bool "Deny double-chroots"
66085+ default y if GRKERNSEC_CONFIG_AUTO
66086+ depends on GRKERNSEC_CHROOT
66087+ help
66088+ If you say Y here, processes inside a chroot will not be able to chroot
66089+ again outside the chroot. This is a widely used method of breaking
66090+ out of a chroot jail and should not be allowed. If the sysctl
66091+ option is enabled, a sysctl option with name
66092+ "chroot_deny_chroot" is created.
66093+
66094+config GRKERNSEC_CHROOT_PIVOT
66095+ bool "Deny pivot_root in chroot"
66096+ default y if GRKERNSEC_CONFIG_AUTO
66097+ depends on GRKERNSEC_CHROOT
66098+ help
66099+ If you say Y here, processes inside a chroot will not be able to use
66100+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66101+ works similar to chroot in that it changes the root filesystem. This
66102+ function could be misused in a chrooted process to attempt to break out
66103+ of the chroot, and therefore should not be allowed. If the sysctl
66104+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66105+ created.
66106+
66107+config GRKERNSEC_CHROOT_CHDIR
66108+ bool "Enforce chdir(\"/\") on all chroots"
66109+ default y if GRKERNSEC_CONFIG_AUTO
66110+ depends on GRKERNSEC_CHROOT
66111+ help
66112+ If you say Y here, the current working directory of all newly-chrooted
66113+ applications will be set to the the root directory of the chroot.
66114+ The man page on chroot(2) states:
66115+ Note that this call does not change the current working
66116+ directory, so that `.' can be outside the tree rooted at
66117+ `/'. In particular, the super-user can escape from a
66118+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66119+
66120+ It is recommended that you say Y here, since it's not known to break
66121+ any software. If the sysctl option is enabled, a sysctl option with
66122+ name "chroot_enforce_chdir" is created.
66123+
66124+config GRKERNSEC_CHROOT_CHMOD
66125+ bool "Deny (f)chmod +s"
66126+ default y if GRKERNSEC_CONFIG_AUTO
66127+ depends on GRKERNSEC_CHROOT
66128+ help
66129+ If you say Y here, processes inside a chroot will not be able to chmod
66130+ or fchmod files to make them have suid or sgid bits. This protects
66131+ against another published method of breaking a chroot. If the sysctl
66132+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66133+ created.
66134+
66135+config GRKERNSEC_CHROOT_FCHDIR
66136+ bool "Deny fchdir out of chroot"
66137+ default y if GRKERNSEC_CONFIG_AUTO
66138+ depends on GRKERNSEC_CHROOT
66139+ help
66140+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66141+ to a file descriptor of the chrooting process that points to a directory
66142+ outside the filesystem will be stopped. If the sysctl option
66143+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
66144+
66145+config GRKERNSEC_CHROOT_MKNOD
66146+ bool "Deny mknod"
66147+ default y if GRKERNSEC_CONFIG_AUTO
66148+ depends on GRKERNSEC_CHROOT
66149+ help
66150+ If you say Y here, processes inside a chroot will not be allowed to
66151+ mknod. The problem with using mknod inside a chroot is that it
66152+ would allow an attacker to create a device entry that is the same
66153+ as one on the physical root of your system, which could range from
66154+ anything from the console device to a device for your harddrive (which
66155+ they could then use to wipe the drive or steal data). It is recommended
66156+ that you say Y here, unless you run into software incompatibilities.
66157+ If the sysctl option is enabled, a sysctl option with name
66158+ "chroot_deny_mknod" is created.
66159+
66160+config GRKERNSEC_CHROOT_SHMAT
66161+ bool "Deny shmat() out of chroot"
66162+ default y if GRKERNSEC_CONFIG_AUTO
66163+ depends on GRKERNSEC_CHROOT
66164+ help
66165+ If you say Y here, processes inside a chroot will not be able to attach
66166+ to shared memory segments that were created outside of the chroot jail.
66167+ It is recommended that you say Y here. If the sysctl option is enabled,
66168+ a sysctl option with name "chroot_deny_shmat" is created.
66169+
66170+config GRKERNSEC_CHROOT_UNIX
66171+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66172+ default y if GRKERNSEC_CONFIG_AUTO
66173+ depends on GRKERNSEC_CHROOT
66174+ help
66175+ If you say Y here, processes inside a chroot will not be able to
66176+ connect to abstract (meaning not belonging to a filesystem) Unix
66177+ domain sockets that were bound outside of a chroot. It is recommended
66178+ that you say Y here. If the sysctl option is enabled, a sysctl option
66179+ with name "chroot_deny_unix" is created.
66180+
66181+config GRKERNSEC_CHROOT_FINDTASK
66182+ bool "Protect outside processes"
66183+ default y if GRKERNSEC_CONFIG_AUTO
66184+ depends on GRKERNSEC_CHROOT
66185+ help
66186+ If you say Y here, processes inside a chroot will not be able to
66187+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66188+ getsid, or view any process outside of the chroot. If the sysctl
66189+ option is enabled, a sysctl option with name "chroot_findtask" is
66190+ created.
66191+
66192+config GRKERNSEC_CHROOT_NICE
66193+ bool "Restrict priority changes"
66194+ default y if GRKERNSEC_CONFIG_AUTO
66195+ depends on GRKERNSEC_CHROOT
66196+ help
66197+ If you say Y here, processes inside a chroot will not be able to raise
66198+ the priority of processes in the chroot, or alter the priority of
66199+ processes outside the chroot. This provides more security than simply
66200+ removing CAP_SYS_NICE from the process' capability set. If the
66201+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66202+ is created.
66203+
66204+config GRKERNSEC_CHROOT_SYSCTL
66205+ bool "Deny sysctl writes"
66206+ default y if GRKERNSEC_CONFIG_AUTO
66207+ depends on GRKERNSEC_CHROOT
66208+ help
66209+ If you say Y here, an attacker in a chroot will not be able to
66210+ write to sysctl entries, either by sysctl(2) or through a /proc
66211+ interface. It is strongly recommended that you say Y here. If the
66212+ sysctl option is enabled, a sysctl option with name
66213+ "chroot_deny_sysctl" is created.
66214+
66215+config GRKERNSEC_CHROOT_CAPS
66216+ bool "Capability restrictions"
66217+ default y if GRKERNSEC_CONFIG_AUTO
66218+ depends on GRKERNSEC_CHROOT
66219+ help
66220+ If you say Y here, the capabilities on all processes within a
66221+ chroot jail will be lowered to stop module insertion, raw i/o,
66222+ system and net admin tasks, rebooting the system, modifying immutable
66223+ files, modifying IPC owned by another, and changing the system time.
66224+ This is left an option because it can break some apps. Disable this
66225+ if your chrooted apps are having problems performing those kinds of
66226+ tasks. If the sysctl option is enabled, a sysctl option with
66227+ name "chroot_caps" is created.
66228+
66229+config GRKERNSEC_CHROOT_INITRD
66230+ bool "Exempt initrd tasks from restrictions"
66231+ default y if GRKERNSEC_CONFIG_AUTO
66232+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66233+ help
66234+ If you say Y here, tasks started prior to init will be exempted from
66235+ grsecurity's chroot restrictions. This option is mainly meant to
66236+ resolve Plymouth's performing privileged operations unnecessarily
66237+ in a chroot.
66238+
66239+endmenu
66240+menu "Kernel Auditing"
66241+depends on GRKERNSEC
66242+
66243+config GRKERNSEC_AUDIT_GROUP
66244+ bool "Single group for auditing"
66245+ help
66246+ If you say Y here, the exec and chdir logging features will only operate
66247+ on a group you specify. This option is recommended if you only want to
66248+ watch certain users instead of having a large amount of logs from the
66249+ entire system. If the sysctl option is enabled, a sysctl option with
66250+ name "audit_group" is created.
66251+
66252+config GRKERNSEC_AUDIT_GID
66253+ int "GID for auditing"
66254+ depends on GRKERNSEC_AUDIT_GROUP
66255+ default 1007
66256+
66257+config GRKERNSEC_EXECLOG
66258+ bool "Exec logging"
66259+ help
66260+ If you say Y here, all execve() calls will be logged (since the
66261+ other exec*() calls are frontends to execve(), all execution
66262+ will be logged). Useful for shell-servers that like to keep track
66263+ of their users. If the sysctl option is enabled, a sysctl option with
66264+ name "exec_logging" is created.
66265+ WARNING: This option when enabled will produce a LOT of logs, especially
66266+ on an active system.
66267+
66268+config GRKERNSEC_RESLOG
66269+ bool "Resource logging"
66270+ default y if GRKERNSEC_CONFIG_AUTO
66271+ help
66272+ If you say Y here, all attempts to overstep resource limits will
66273+ be logged with the resource name, the requested size, and the current
66274+ limit. It is highly recommended that you say Y here. If the sysctl
66275+ option is enabled, a sysctl option with name "resource_logging" is
66276+ created. If the RBAC system is enabled, the sysctl value is ignored.
66277+
66278+config GRKERNSEC_CHROOT_EXECLOG
66279+ bool "Log execs within chroot"
66280+ help
66281+ If you say Y here, all executions inside a chroot jail will be logged
66282+ to syslog. This can cause a large amount of logs if certain
66283+ applications (eg. djb's daemontools) are installed on the system, and
66284+ is therefore left as an option. If the sysctl option is enabled, a
66285+ sysctl option with name "chroot_execlog" is created.
66286+
66287+config GRKERNSEC_AUDIT_PTRACE
66288+ bool "Ptrace logging"
66289+ help
66290+ If you say Y here, all attempts to attach to a process via ptrace
66291+ will be logged. If the sysctl option is enabled, a sysctl option
66292+ with name "audit_ptrace" is created.
66293+
66294+config GRKERNSEC_AUDIT_CHDIR
66295+ bool "Chdir logging"
66296+ help
66297+ If you say Y here, all chdir() calls will be logged. If the sysctl
66298+ option is enabled, a sysctl option with name "audit_chdir" is created.
66299+
66300+config GRKERNSEC_AUDIT_MOUNT
66301+ bool "(Un)Mount logging"
66302+ help
66303+ If you say Y here, all mounts and unmounts will be logged. If the
66304+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66305+ created.
66306+
66307+config GRKERNSEC_SIGNAL
66308+ bool "Signal logging"
66309+ default y if GRKERNSEC_CONFIG_AUTO
66310+ help
66311+ If you say Y here, certain important signals will be logged, such as
66312+ SIGSEGV, which will as a result inform you of when a error in a program
66313+ occurred, which in some cases could mean a possible exploit attempt.
66314+ If the sysctl option is enabled, a sysctl option with name
66315+ "signal_logging" is created.
66316+
66317+config GRKERNSEC_FORKFAIL
66318+ bool "Fork failure logging"
66319+ help
66320+ If you say Y here, all failed fork() attempts will be logged.
66321+ This could suggest a fork bomb, or someone attempting to overstep
66322+ their process limit. If the sysctl option is enabled, a sysctl option
66323+ with name "forkfail_logging" is created.
66324+
66325+config GRKERNSEC_TIME
66326+ bool "Time change logging"
66327+ default y if GRKERNSEC_CONFIG_AUTO
66328+ help
66329+ If you say Y here, any changes of the system clock will be logged.
66330+ If the sysctl option is enabled, a sysctl option with name
66331+ "timechange_logging" is created.
66332+
66333+config GRKERNSEC_PROC_IPADDR
66334+ bool "/proc/<pid>/ipaddr support"
66335+ default y if GRKERNSEC_CONFIG_AUTO
66336+ help
66337+ If you say Y here, a new entry will be added to each /proc/<pid>
66338+ directory that contains the IP address of the person using the task.
66339+ The IP is carried across local TCP and AF_UNIX stream sockets.
66340+ This information can be useful for IDS/IPSes to perform remote response
66341+ to a local attack. The entry is readable by only the owner of the
66342+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66343+ the RBAC system), and thus does not create privacy concerns.
66344+
66345+config GRKERNSEC_RWXMAP_LOG
66346+ bool 'Denied RWX mmap/mprotect logging'
66347+ default y if GRKERNSEC_CONFIG_AUTO
66348+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66349+ help
66350+ If you say Y here, calls to mmap() and mprotect() with explicit
66351+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66352+ denied by the PAX_MPROTECT feature. This feature will also
66353+ log other problematic scenarios that can occur when PAX_MPROTECT
66354+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66355+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66356+ is created.
66357+
66358+endmenu
66359+
66360+menu "Executable Protections"
66361+depends on GRKERNSEC
66362+
66363+config GRKERNSEC_DMESG
66364+ bool "Dmesg(8) restriction"
66365+ default y if GRKERNSEC_CONFIG_AUTO
66366+ help
66367+ If you say Y here, non-root users will not be able to use dmesg(8)
66368+ to view the contents of the kernel's circular log buffer.
66369+ The kernel's log buffer often contains kernel addresses and other
66370+ identifying information useful to an attacker in fingerprinting a
66371+ system for a targeted exploit.
66372+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66373+ created.
66374+
66375+config GRKERNSEC_HARDEN_PTRACE
66376+ bool "Deter ptrace-based process snooping"
66377+ default y if GRKERNSEC_CONFIG_AUTO
66378+ help
66379+ If you say Y here, TTY sniffers and other malicious monitoring
66380+ programs implemented through ptrace will be defeated. If you
66381+ have been using the RBAC system, this option has already been
66382+ enabled for several years for all users, with the ability to make
66383+ fine-grained exceptions.
66384+
66385+ This option only affects the ability of non-root users to ptrace
66386+ processes that are not a descendent of the ptracing process.
66387+ This means that strace ./binary and gdb ./binary will still work,
66388+ but attaching to arbitrary processes will not. If the sysctl
66389+ option is enabled, a sysctl option with name "harden_ptrace" is
66390+ created.
66391+
66392+config GRKERNSEC_PTRACE_READEXEC
66393+ bool "Require read access to ptrace sensitive binaries"
66394+ default y if GRKERNSEC_CONFIG_AUTO
66395+ help
66396+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66397+ binaries. This option is useful in environments that
66398+ remove the read bits (e.g. file mode 4711) from suid binaries to
66399+ prevent infoleaking of their contents. This option adds
66400+ consistency to the use of that file mode, as the binary could normally
66401+ be read out when run without privileges while ptracing.
66402+
66403+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66404+ is created.
66405+
66406+config GRKERNSEC_SETXID
66407+ bool "Enforce consistent multithreaded privileges"
66408+ default y if GRKERNSEC_CONFIG_AUTO
66409+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66410+ help
66411+ If you say Y here, a change from a root uid to a non-root uid
66412+ in a multithreaded application will cause the resulting uids,
66413+ gids, supplementary groups, and capabilities in that thread
66414+ to be propagated to the other threads of the process. In most
66415+ cases this is unnecessary, as glibc will emulate this behavior
66416+ on behalf of the application. Other libcs do not act in the
66417+ same way, allowing the other threads of the process to continue
66418+ running with root privileges. If the sysctl option is enabled,
66419+ a sysctl option with name "consistent_setxid" is created.
66420+
66421+config GRKERNSEC_HARDEN_IPC
66422+ bool "Disallow access to overly-permissive IPC objects"
66423+ default y if GRKERNSEC_CONFIG_AUTO
66424+ depends on SYSVIPC
66425+ help
66426+ If you say Y here, access to overly-permissive IPC objects (shared
66427+ memory, message queues, and semaphores) will be denied for processes
66428+ given the following criteria beyond normal permission checks:
66429+ 1) If the IPC object is world-accessible and the euid doesn't match
66430+ that of the creator or current uid for the IPC object
66431+ 2) If the IPC object is group-accessible and the egid doesn't
66432+ match that of the creator or current gid for the IPC object
66433+ It's a common error to grant too much permission to these objects,
66434+ with impact ranging from denial of service and information leaking to
66435+ privilege escalation. This feature was developed in response to
66436+ research by Tim Brown:
66437+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66438+ who found hundreds of such insecure usages. Processes with
66439+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66440+ If the sysctl option is enabled, a sysctl option with name
66441+ "harden_ipc" is created.
66442+
66443+config GRKERNSEC_TPE
66444+ bool "Trusted Path Execution (TPE)"
66445+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66446+ help
66447+ If you say Y here, you will be able to choose a gid to add to the
66448+ supplementary groups of users you want to mark as "untrusted."
66449+ These users will not be able to execute any files that are not in
66450+ root-owned directories writable only by root. If the sysctl option
66451+ is enabled, a sysctl option with name "tpe" is created.
66452+
66453+config GRKERNSEC_TPE_ALL
66454+ bool "Partially restrict all non-root users"
66455+ depends on GRKERNSEC_TPE
66456+ help
66457+ If you say Y here, all non-root users will be covered under
66458+ a weaker TPE restriction. This is separate from, and in addition to,
66459+ the main TPE options that you have selected elsewhere. Thus, if a
66460+ "trusted" GID is chosen, this restriction applies to even that GID.
66461+ Under this restriction, all non-root users will only be allowed to
66462+ execute files in directories they own that are not group or
66463+ world-writable, or in directories owned by root and writable only by
66464+ root. If the sysctl option is enabled, a sysctl option with name
66465+ "tpe_restrict_all" is created.
66466+
66467+config GRKERNSEC_TPE_INVERT
66468+ bool "Invert GID option"
66469+ depends on GRKERNSEC_TPE
66470+ help
66471+ If you say Y here, the group you specify in the TPE configuration will
66472+ decide what group TPE restrictions will be *disabled* for. This
66473+ option is useful if you want TPE restrictions to be applied to most
66474+ users on the system. If the sysctl option is enabled, a sysctl option
66475+ with name "tpe_invert" is created. Unlike other sysctl options, this
66476+ entry will default to on for backward-compatibility.
66477+
66478+config GRKERNSEC_TPE_GID
66479+ int
66480+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66481+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66482+
66483+config GRKERNSEC_TPE_UNTRUSTED_GID
66484+ int "GID for TPE-untrusted users"
66485+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66486+ default 1005
66487+ help
66488+ Setting this GID determines what group TPE restrictions will be
66489+ *enabled* for. If the sysctl option is enabled, a sysctl option
66490+ with name "tpe_gid" is created.
66491+
66492+config GRKERNSEC_TPE_TRUSTED_GID
66493+ int "GID for TPE-trusted users"
66494+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66495+ default 1005
66496+ help
66497+ Setting this GID determines what group TPE restrictions will be
66498+ *disabled* for. If the sysctl option is enabled, a sysctl option
66499+ with name "tpe_gid" is created.
66500+
66501+endmenu
66502+menu "Network Protections"
66503+depends on GRKERNSEC
66504+
66505+config GRKERNSEC_RANDNET
66506+ bool "Larger entropy pools"
66507+ default y if GRKERNSEC_CONFIG_AUTO
66508+ help
66509+ If you say Y here, the entropy pools used for many features of Linux
66510+ and grsecurity will be doubled in size. Since several grsecurity
66511+ features use additional randomness, it is recommended that you say Y
66512+ here. Saying Y here has a similar effect as modifying
66513+ /proc/sys/kernel/random/poolsize.
66514+
66515+config GRKERNSEC_BLACKHOLE
66516+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66517+ default y if GRKERNSEC_CONFIG_AUTO
66518+ depends on NET
66519+ help
66520+ If you say Y here, neither TCP resets nor ICMP
66521+ destination-unreachable packets will be sent in response to packets
66522+ sent to ports for which no associated listening process exists.
66523+ This feature supports both IPV4 and IPV6 and exempts the
66524+ loopback interface from blackholing. Enabling this feature
66525+ makes a host more resilient to DoS attacks and reduces network
66526+ visibility against scanners.
66527+
66528+ The blackhole feature as-implemented is equivalent to the FreeBSD
66529+ blackhole feature, as it prevents RST responses to all packets, not
66530+ just SYNs. Under most application behavior this causes no
66531+ problems, but applications (like haproxy) may not close certain
66532+ connections in a way that cleanly terminates them on the remote
66533+ end, leaving the remote host in LAST_ACK state. Because of this
66534+ side-effect and to prevent intentional LAST_ACK DoSes, this
66535+ feature also adds automatic mitigation against such attacks.
66536+ The mitigation drastically reduces the amount of time a socket
66537+ can spend in LAST_ACK state. If you're using haproxy and not
66538+ all servers it connects to have this option enabled, consider
66539+ disabling this feature on the haproxy host.
66540+
66541+ If the sysctl option is enabled, two sysctl options with names
66542+ "ip_blackhole" and "lastack_retries" will be created.
66543+ While "ip_blackhole" takes the standard zero/non-zero on/off
66544+ toggle, "lastack_retries" uses the same kinds of values as
66545+ "tcp_retries1" and "tcp_retries2". The default value of 4
66546+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66547+ state.
66548+
66549+config GRKERNSEC_NO_SIMULT_CONNECT
66550+ bool "Disable TCP Simultaneous Connect"
66551+ default y if GRKERNSEC_CONFIG_AUTO
66552+ depends on NET
66553+ help
66554+ If you say Y here, a feature by Willy Tarreau will be enabled that
66555+ removes a weakness in Linux's strict implementation of TCP that
66556+ allows two clients to connect to each other without either entering
66557+ a listening state. The weakness allows an attacker to easily prevent
66558+ a client from connecting to a known server provided the source port
66559+ for the connection is guessed correctly.
66560+
66561+ As the weakness could be used to prevent an antivirus or IPS from
66562+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66563+ it should be eliminated by enabling this option. Though Linux is
66564+ one of few operating systems supporting simultaneous connect, it
66565+ has no legitimate use in practice and is rarely supported by firewalls.
66566+
66567+config GRKERNSEC_SOCKET
66568+ bool "Socket restrictions"
66569+ depends on NET
66570+ help
66571+ If you say Y here, you will be able to choose from several options.
66572+ If you assign a GID on your system and add it to the supplementary
66573+ groups of users you want to restrict socket access to, this patch
66574+ will perform up to three things, based on the option(s) you choose.
66575+
66576+config GRKERNSEC_SOCKET_ALL
66577+ bool "Deny any sockets to group"
66578+ depends on GRKERNSEC_SOCKET
66579+ help
66580+ If you say Y here, you will be able to choose a GID of whose users will
66581+ be unable to connect to other hosts from your machine or run server
66582+ applications from your machine. If the sysctl option is enabled, a
66583+ sysctl option with name "socket_all" is created.
66584+
66585+config GRKERNSEC_SOCKET_ALL_GID
66586+ int "GID to deny all sockets for"
66587+ depends on GRKERNSEC_SOCKET_ALL
66588+ default 1004
66589+ help
66590+ Here you can choose the GID to disable socket access for. Remember to
66591+ add the users you want socket access disabled for to the GID
66592+ specified here. If the sysctl option is enabled, a sysctl option
66593+ with name "socket_all_gid" is created.
66594+
66595+config GRKERNSEC_SOCKET_CLIENT
66596+ bool "Deny client sockets to group"
66597+ depends on GRKERNSEC_SOCKET
66598+ help
66599+ If you say Y here, you will be able to choose a GID of whose users will
66600+ be unable to connect to other hosts from your machine, but will be
66601+ able to run servers. If this option is enabled, all users in the group
66602+ you specify will have to use passive mode when initiating ftp transfers
66603+ from the shell on your machine. If the sysctl option is enabled, a
66604+ sysctl option with name "socket_client" is created.
66605+
66606+config GRKERNSEC_SOCKET_CLIENT_GID
66607+ int "GID to deny client sockets for"
66608+ depends on GRKERNSEC_SOCKET_CLIENT
66609+ default 1003
66610+ help
66611+ Here you can choose the GID to disable client socket access for.
66612+ Remember to add the users you want client socket access disabled for to
66613+ the GID specified here. If the sysctl option is enabled, a sysctl
66614+ option with name "socket_client_gid" is created.
66615+
66616+config GRKERNSEC_SOCKET_SERVER
66617+ bool "Deny server sockets to group"
66618+ depends on GRKERNSEC_SOCKET
66619+ help
66620+ If you say Y here, you will be able to choose a GID of whose users will
66621+ be unable to run server applications from your machine. If the sysctl
66622+ option is enabled, a sysctl option with name "socket_server" is created.
66623+
66624+config GRKERNSEC_SOCKET_SERVER_GID
66625+ int "GID to deny server sockets for"
66626+ depends on GRKERNSEC_SOCKET_SERVER
66627+ default 1002
66628+ help
66629+ Here you can choose the GID to disable server socket access for.
66630+ Remember to add the users you want server socket access disabled for to
66631+ the GID specified here. If the sysctl option is enabled, a sysctl
66632+ option with name "socket_server_gid" is created.
66633+
66634+endmenu
66635+
66636+menu "Physical Protections"
66637+depends on GRKERNSEC
66638+
66639+config GRKERNSEC_DENYUSB
66640+ bool "Deny new USB connections after toggle"
66641+ default y if GRKERNSEC_CONFIG_AUTO
66642+ depends on SYSCTL && USB_SUPPORT
66643+ help
66644+ If you say Y here, a new sysctl option with name "deny_new_usb"
66645+ will be created. Setting its value to 1 will prevent any new
66646+ USB devices from being recognized by the OS. Any attempted USB
66647+ device insertion will be logged. This option is intended to be
66648+ used against custom USB devices designed to exploit vulnerabilities
66649+ in various USB device drivers.
66650+
66651+ For greatest effectiveness, this sysctl should be set after any
66652+ relevant init scripts. This option is safe to enable in distros
66653+ as each user can choose whether or not to toggle the sysctl.
66654+
66655+config GRKERNSEC_DENYUSB_FORCE
66656+ bool "Reject all USB devices not connected at boot"
66657+ select USB
66658+ depends on GRKERNSEC_DENYUSB
66659+ help
66660+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66661+ that doesn't involve a sysctl entry. This option should only be
66662+ enabled if you're sure you want to deny all new USB connections
66663+ at runtime and don't want to modify init scripts. This should not
66664+ be enabled by distros. It forces the core USB code to be built
66665+ into the kernel image so that all devices connected at boot time
66666+ can be recognized and new USB device connections can be prevented
66667+ prior to init running.
66668+
66669+endmenu
66670+
66671+menu "Sysctl Support"
66672+depends on GRKERNSEC && SYSCTL
66673+
66674+config GRKERNSEC_SYSCTL
66675+ bool "Sysctl support"
66676+ default y if GRKERNSEC_CONFIG_AUTO
66677+ help
66678+ If you say Y here, you will be able to change the options that
66679+ grsecurity runs with at bootup, without having to recompile your
66680+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66681+ to enable (1) or disable (0) various features. All the sysctl entries
66682+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66683+ All features enabled in the kernel configuration are disabled at boot
66684+ if you do not say Y to the "Turn on features by default" option.
66685+ All options should be set at startup, and the grsec_lock entry should
66686+ be set to a non-zero value after all the options are set.
66687+ *THIS IS EXTREMELY IMPORTANT*
66688+
66689+config GRKERNSEC_SYSCTL_DISTRO
66690+ bool "Extra sysctl support for distro makers (READ HELP)"
66691+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66692+ help
66693+ If you say Y here, additional sysctl options will be created
66694+ for features that affect processes running as root. Therefore,
66695+ it is critical when using this option that the grsec_lock entry be
66696+ enabled after boot. Only distros with prebuilt kernel packages
66697+ with this option enabled that can ensure grsec_lock is enabled
66698+ after boot should use this option.
66699+ *Failure to set grsec_lock after boot makes all grsec features
66700+ this option covers useless*
66701+
66702+ Currently this option creates the following sysctl entries:
66703+ "Disable Privileged I/O": "disable_priv_io"
66704+
66705+config GRKERNSEC_SYSCTL_ON
66706+ bool "Turn on features by default"
66707+ default y if GRKERNSEC_CONFIG_AUTO
66708+ depends on GRKERNSEC_SYSCTL
66709+ help
66710+ If you say Y here, instead of having all features enabled in the
66711+ kernel configuration disabled at boot time, the features will be
66712+ enabled at boot time. It is recommended you say Y here unless
66713+ there is some reason you would want all sysctl-tunable features to
66714+ be disabled by default. As mentioned elsewhere, it is important
66715+ to enable the grsec_lock entry once you have finished modifying
66716+ the sysctl entries.
66717+
66718+endmenu
66719+menu "Logging Options"
66720+depends on GRKERNSEC
66721+
66722+config GRKERNSEC_FLOODTIME
66723+ int "Seconds in between log messages (minimum)"
66724+ default 10
66725+ help
66726+ This option allows you to enforce the number of seconds between
66727+ grsecurity log messages. The default should be suitable for most
66728+ people, however, if you choose to change it, choose a value small enough
66729+ to allow informative logs to be produced, but large enough to
66730+ prevent flooding.
66731+
66732+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66733+ any rate limiting on grsecurity log messages.
66734+
66735+config GRKERNSEC_FLOODBURST
66736+ int "Number of messages in a burst (maximum)"
66737+ default 6
66738+ help
66739+ This option allows you to choose the maximum number of messages allowed
66740+ within the flood time interval you chose in a separate option. The
66741+ default should be suitable for most people, however if you find that
66742+ many of your logs are being interpreted as flooding, you may want to
66743+ raise this value.
66744+
66745+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66746+ any rate limiting on grsecurity log messages.
66747+
66748+endmenu
66749diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66750new file mode 100644
66751index 0000000..30ababb
66752--- /dev/null
66753+++ b/grsecurity/Makefile
66754@@ -0,0 +1,54 @@
66755+# grsecurity – access control and security hardening for Linux
66756+# All code in this directory and various hooks located throughout the Linux kernel are
66757+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66758+# http://www.grsecurity.net spender@grsecurity.net
66759+#
66760+# This program is free software; you can redistribute it and/or
66761+# modify it under the terms of the GNU General Public License version 2
66762+# as published by the Free Software Foundation.
66763+#
66764+# This program is distributed in the hope that it will be useful,
66765+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66766+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66767+# GNU General Public License for more details.
66768+#
66769+# You should have received a copy of the GNU General Public License
66770+# along with this program; if not, write to the Free Software
66771+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66772+
66773+KBUILD_CFLAGS += -Werror
66774+
66775+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66776+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66777+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66778+ grsec_usb.o grsec_ipc.o grsec_proc.o
66779+
66780+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66781+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66782+ gracl_learn.o grsec_log.o gracl_policy.o
66783+ifdef CONFIG_COMPAT
66784+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66785+endif
66786+
66787+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66788+
66789+ifdef CONFIG_NET
66790+obj-y += grsec_sock.o
66791+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66792+endif
66793+
66794+ifndef CONFIG_GRKERNSEC
66795+obj-y += grsec_disabled.o
66796+endif
66797+
66798+ifdef CONFIG_GRKERNSEC_HIDESYM
66799+extra-y := grsec_hidesym.o
66800+$(obj)/grsec_hidesym.o:
66801+ @-chmod -f 500 /boot
66802+ @-chmod -f 500 /lib/modules
66803+ @-chmod -f 500 /lib64/modules
66804+ @-chmod -f 500 /lib32/modules
66805+ @-chmod -f 700 .
66806+ @-chmod -f 700 $(objtree)
66807+ @echo ' grsec: protected kernel image paths'
66808+endif
66809diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66810new file mode 100644
66811index 0000000..e56396f
66812--- /dev/null
66813+++ b/grsecurity/gracl.c
66814@@ -0,0 +1,2679 @@
66815+#include <linux/kernel.h>
66816+#include <linux/module.h>
66817+#include <linux/sched.h>
66818+#include <linux/mm.h>
66819+#include <linux/file.h>
66820+#include <linux/fs.h>
66821+#include <linux/namei.h>
66822+#include <linux/mount.h>
66823+#include <linux/tty.h>
66824+#include <linux/proc_fs.h>
66825+#include <linux/lglock.h>
66826+#include <linux/slab.h>
66827+#include <linux/vmalloc.h>
66828+#include <linux/types.h>
66829+#include <linux/sysctl.h>
66830+#include <linux/netdevice.h>
66831+#include <linux/ptrace.h>
66832+#include <linux/gracl.h>
66833+#include <linux/gralloc.h>
66834+#include <linux/security.h>
66835+#include <linux/grinternal.h>
66836+#include <linux/pid_namespace.h>
66837+#include <linux/stop_machine.h>
66838+#include <linux/fdtable.h>
66839+#include <linux/percpu.h>
66840+#include <linux/lglock.h>
66841+#include <linux/hugetlb.h>
66842+#include <linux/posix-timers.h>
66843+#include <linux/prefetch.h>
66844+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66845+#include <linux/magic.h>
66846+#include <linux/pagemap.h>
66847+#include "../fs/btrfs/async-thread.h"
66848+#include "../fs/btrfs/ctree.h"
66849+#include "../fs/btrfs/btrfs_inode.h"
66850+#endif
66851+#include "../fs/mount.h"
66852+
66853+#include <asm/uaccess.h>
66854+#include <asm/errno.h>
66855+#include <asm/mman.h>
66856+
66857+#define FOR_EACH_ROLE_START(role) \
66858+ role = running_polstate.role_list; \
66859+ while (role) {
66860+
66861+#define FOR_EACH_ROLE_END(role) \
66862+ role = role->prev; \
66863+ }
66864+
66865+extern struct path gr_real_root;
66866+
66867+static struct gr_policy_state running_polstate;
66868+struct gr_policy_state *polstate = &running_polstate;
66869+extern struct gr_alloc_state *current_alloc_state;
66870+
66871+extern char *gr_shared_page[4];
66872+DEFINE_RWLOCK(gr_inode_lock);
66873+
66874+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66875+
66876+#ifdef CONFIG_NET
66877+extern struct vfsmount *sock_mnt;
66878+#endif
66879+
66880+extern struct vfsmount *pipe_mnt;
66881+extern struct vfsmount *shm_mnt;
66882+
66883+#ifdef CONFIG_HUGETLBFS
66884+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66885+#endif
66886+
66887+extern u16 acl_sp_role_value;
66888+extern struct acl_object_label *fakefs_obj_rw;
66889+extern struct acl_object_label *fakefs_obj_rwx;
66890+
66891+int gr_acl_is_enabled(void)
66892+{
66893+ return (gr_status & GR_READY);
66894+}
66895+
66896+void gr_enable_rbac_system(void)
66897+{
66898+ pax_open_kernel();
66899+ gr_status |= GR_READY;
66900+ pax_close_kernel();
66901+}
66902+
66903+int gr_rbac_disable(void *unused)
66904+{
66905+ pax_open_kernel();
66906+ gr_status &= ~GR_READY;
66907+ pax_close_kernel();
66908+
66909+ return 0;
66910+}
66911+
66912+static inline dev_t __get_dev(const struct dentry *dentry)
66913+{
66914+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66915+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66916+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66917+ else
66918+#endif
66919+ return dentry->d_sb->s_dev;
66920+}
66921+
66922+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66923+{
66924+ return __get_dev(dentry);
66925+}
66926+
66927+static char gr_task_roletype_to_char(struct task_struct *task)
66928+{
66929+ switch (task->role->roletype &
66930+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66931+ GR_ROLE_SPECIAL)) {
66932+ case GR_ROLE_DEFAULT:
66933+ return 'D';
66934+ case GR_ROLE_USER:
66935+ return 'U';
66936+ case GR_ROLE_GROUP:
66937+ return 'G';
66938+ case GR_ROLE_SPECIAL:
66939+ return 'S';
66940+ }
66941+
66942+ return 'X';
66943+}
66944+
66945+char gr_roletype_to_char(void)
66946+{
66947+ return gr_task_roletype_to_char(current);
66948+}
66949+
66950+__inline__ int
66951+gr_acl_tpe_check(void)
66952+{
66953+ if (unlikely(!(gr_status & GR_READY)))
66954+ return 0;
66955+ if (current->role->roletype & GR_ROLE_TPE)
66956+ return 1;
66957+ else
66958+ return 0;
66959+}
66960+
66961+int
66962+gr_handle_rawio(const struct inode *inode)
66963+{
66964+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66965+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66966+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66967+ !capable(CAP_SYS_RAWIO))
66968+ return 1;
66969+#endif
66970+ return 0;
66971+}
66972+
66973+int
66974+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66975+{
66976+ if (likely(lena != lenb))
66977+ return 0;
66978+
66979+ return !memcmp(a, b, lena);
66980+}
66981+
66982+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66983+{
66984+ *buflen -= namelen;
66985+ if (*buflen < 0)
66986+ return -ENAMETOOLONG;
66987+ *buffer -= namelen;
66988+ memcpy(*buffer, str, namelen);
66989+ return 0;
66990+}
66991+
66992+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66993+{
66994+ return prepend(buffer, buflen, name->name, name->len);
66995+}
66996+
66997+static int prepend_path(const struct path *path, struct path *root,
66998+ char **buffer, int *buflen)
66999+{
67000+ struct dentry *dentry = path->dentry;
67001+ struct vfsmount *vfsmnt = path->mnt;
67002+ struct mount *mnt = real_mount(vfsmnt);
67003+ bool slash = false;
67004+ int error = 0;
67005+
67006+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67007+ struct dentry * parent;
67008+
67009+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67010+ /* Global root? */
67011+ if (!mnt_has_parent(mnt)) {
67012+ goto out;
67013+ }
67014+ dentry = mnt->mnt_mountpoint;
67015+ mnt = mnt->mnt_parent;
67016+ vfsmnt = &mnt->mnt;
67017+ continue;
67018+ }
67019+ parent = dentry->d_parent;
67020+ prefetch(parent);
67021+ spin_lock(&dentry->d_lock);
67022+ error = prepend_name(buffer, buflen, &dentry->d_name);
67023+ spin_unlock(&dentry->d_lock);
67024+ if (!error)
67025+ error = prepend(buffer, buflen, "/", 1);
67026+ if (error)
67027+ break;
67028+
67029+ slash = true;
67030+ dentry = parent;
67031+ }
67032+
67033+out:
67034+ if (!error && !slash)
67035+ error = prepend(buffer, buflen, "/", 1);
67036+
67037+ return error;
67038+}
67039+
67040+/* this must be called with mount_lock and rename_lock held */
67041+
67042+static char *__our_d_path(const struct path *path, struct path *root,
67043+ char *buf, int buflen)
67044+{
67045+ char *res = buf + buflen;
67046+ int error;
67047+
67048+ prepend(&res, &buflen, "\0", 1);
67049+ error = prepend_path(path, root, &res, &buflen);
67050+ if (error)
67051+ return ERR_PTR(error);
67052+
67053+ return res;
67054+}
67055+
67056+static char *
67057+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67058+{
67059+ char *retval;
67060+
67061+ retval = __our_d_path(path, root, buf, buflen);
67062+ if (unlikely(IS_ERR(retval)))
67063+ retval = strcpy(buf, "<path too long>");
67064+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67065+ retval[1] = '\0';
67066+
67067+ return retval;
67068+}
67069+
67070+static char *
67071+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67072+ char *buf, int buflen)
67073+{
67074+ struct path path;
67075+ char *res;
67076+
67077+ path.dentry = (struct dentry *)dentry;
67078+ path.mnt = (struct vfsmount *)vfsmnt;
67079+
67080+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67081+ by the RBAC system */
67082+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67083+
67084+ return res;
67085+}
67086+
67087+static char *
67088+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67089+ char *buf, int buflen)
67090+{
67091+ char *res;
67092+ struct path path;
67093+ struct path root;
67094+ struct task_struct *reaper = init_pid_ns.child_reaper;
67095+
67096+ path.dentry = (struct dentry *)dentry;
67097+ path.mnt = (struct vfsmount *)vfsmnt;
67098+
67099+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67100+ get_fs_root(reaper->fs, &root);
67101+
67102+ read_seqlock_excl(&mount_lock);
67103+ write_seqlock(&rename_lock);
67104+ res = gen_full_path(&path, &root, buf, buflen);
67105+ write_sequnlock(&rename_lock);
67106+ read_sequnlock_excl(&mount_lock);
67107+
67108+ path_put(&root);
67109+ return res;
67110+}
67111+
67112+char *
67113+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67114+{
67115+ char *ret;
67116+ read_seqlock_excl(&mount_lock);
67117+ write_seqlock(&rename_lock);
67118+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67119+ PAGE_SIZE);
67120+ write_sequnlock(&rename_lock);
67121+ read_sequnlock_excl(&mount_lock);
67122+ return ret;
67123+}
67124+
67125+static char *
67126+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67127+{
67128+ char *ret;
67129+ char *buf;
67130+ int buflen;
67131+
67132+ read_seqlock_excl(&mount_lock);
67133+ write_seqlock(&rename_lock);
67134+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67135+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67136+ buflen = (int)(ret - buf);
67137+ if (buflen >= 5)
67138+ prepend(&ret, &buflen, "/proc", 5);
67139+ else
67140+ ret = strcpy(buf, "<path too long>");
67141+ write_sequnlock(&rename_lock);
67142+ read_sequnlock_excl(&mount_lock);
67143+ return ret;
67144+}
67145+
67146+char *
67147+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67148+{
67149+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67150+ PAGE_SIZE);
67151+}
67152+
67153+char *
67154+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67155+{
67156+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67157+ PAGE_SIZE);
67158+}
67159+
67160+char *
67161+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67162+{
67163+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67164+ PAGE_SIZE);
67165+}
67166+
67167+char *
67168+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67169+{
67170+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67171+ PAGE_SIZE);
67172+}
67173+
67174+char *
67175+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67176+{
67177+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67178+ PAGE_SIZE);
67179+}
67180+
67181+__inline__ __u32
67182+to_gr_audit(const __u32 reqmode)
67183+{
67184+ /* masks off auditable permission flags, then shifts them to create
67185+ auditing flags, and adds the special case of append auditing if
67186+ we're requesting write */
67187+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67188+}
67189+
67190+struct acl_role_label *
67191+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67192+ const gid_t gid)
67193+{
67194+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67195+ struct acl_role_label *match;
67196+ struct role_allowed_ip *ipp;
67197+ unsigned int x;
67198+ u32 curr_ip = task->signal->saved_ip;
67199+
67200+ match = state->acl_role_set.r_hash[index];
67201+
67202+ while (match) {
67203+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67204+ for (x = 0; x < match->domain_child_num; x++) {
67205+ if (match->domain_children[x] == uid)
67206+ goto found;
67207+ }
67208+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67209+ break;
67210+ match = match->next;
67211+ }
67212+found:
67213+ if (match == NULL) {
67214+ try_group:
67215+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67216+ match = state->acl_role_set.r_hash[index];
67217+
67218+ while (match) {
67219+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67220+ for (x = 0; x < match->domain_child_num; x++) {
67221+ if (match->domain_children[x] == gid)
67222+ goto found2;
67223+ }
67224+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67225+ break;
67226+ match = match->next;
67227+ }
67228+found2:
67229+ if (match == NULL)
67230+ match = state->default_role;
67231+ if (match->allowed_ips == NULL)
67232+ return match;
67233+ else {
67234+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67235+ if (likely
67236+ ((ntohl(curr_ip) & ipp->netmask) ==
67237+ (ntohl(ipp->addr) & ipp->netmask)))
67238+ return match;
67239+ }
67240+ match = state->default_role;
67241+ }
67242+ } else if (match->allowed_ips == NULL) {
67243+ return match;
67244+ } else {
67245+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67246+ if (likely
67247+ ((ntohl(curr_ip) & ipp->netmask) ==
67248+ (ntohl(ipp->addr) & ipp->netmask)))
67249+ return match;
67250+ }
67251+ goto try_group;
67252+ }
67253+
67254+ return match;
67255+}
67256+
67257+static struct acl_role_label *
67258+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67259+ const gid_t gid)
67260+{
67261+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67262+}
67263+
67264+struct acl_subject_label *
67265+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67266+ const struct acl_role_label *role)
67267+{
67268+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67269+ struct acl_subject_label *match;
67270+
67271+ match = role->subj_hash[index];
67272+
67273+ while (match && (match->inode != ino || match->device != dev ||
67274+ (match->mode & GR_DELETED))) {
67275+ match = match->next;
67276+ }
67277+
67278+ if (match && !(match->mode & GR_DELETED))
67279+ return match;
67280+ else
67281+ return NULL;
67282+}
67283+
67284+struct acl_subject_label *
67285+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67286+ const struct acl_role_label *role)
67287+{
67288+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67289+ struct acl_subject_label *match;
67290+
67291+ match = role->subj_hash[index];
67292+
67293+ while (match && (match->inode != ino || match->device != dev ||
67294+ !(match->mode & GR_DELETED))) {
67295+ match = match->next;
67296+ }
67297+
67298+ if (match && (match->mode & GR_DELETED))
67299+ return match;
67300+ else
67301+ return NULL;
67302+}
67303+
67304+static struct acl_object_label *
67305+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67306+ const struct acl_subject_label *subj)
67307+{
67308+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67309+ struct acl_object_label *match;
67310+
67311+ match = subj->obj_hash[index];
67312+
67313+ while (match && (match->inode != ino || match->device != dev ||
67314+ (match->mode & GR_DELETED))) {
67315+ match = match->next;
67316+ }
67317+
67318+ if (match && !(match->mode & GR_DELETED))
67319+ return match;
67320+ else
67321+ return NULL;
67322+}
67323+
67324+static struct acl_object_label *
67325+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67326+ const struct acl_subject_label *subj)
67327+{
67328+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67329+ struct acl_object_label *match;
67330+
67331+ match = subj->obj_hash[index];
67332+
67333+ while (match && (match->inode != ino || match->device != dev ||
67334+ !(match->mode & GR_DELETED))) {
67335+ match = match->next;
67336+ }
67337+
67338+ if (match && (match->mode & GR_DELETED))
67339+ return match;
67340+
67341+ match = subj->obj_hash[index];
67342+
67343+ while (match && (match->inode != ino || match->device != dev ||
67344+ (match->mode & GR_DELETED))) {
67345+ match = match->next;
67346+ }
67347+
67348+ if (match && !(match->mode & GR_DELETED))
67349+ return match;
67350+ else
67351+ return NULL;
67352+}
67353+
67354+struct name_entry *
67355+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67356+{
67357+ unsigned int len = strlen(name);
67358+ unsigned int key = full_name_hash(name, len);
67359+ unsigned int index = key % state->name_set.n_size;
67360+ struct name_entry *match;
67361+
67362+ match = state->name_set.n_hash[index];
67363+
67364+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67365+ match = match->next;
67366+
67367+ return match;
67368+}
67369+
67370+static struct name_entry *
67371+lookup_name_entry(const char *name)
67372+{
67373+ return __lookup_name_entry(&running_polstate, name);
67374+}
67375+
67376+static struct name_entry *
67377+lookup_name_entry_create(const char *name)
67378+{
67379+ unsigned int len = strlen(name);
67380+ unsigned int key = full_name_hash(name, len);
67381+ unsigned int index = key % running_polstate.name_set.n_size;
67382+ struct name_entry *match;
67383+
67384+ match = running_polstate.name_set.n_hash[index];
67385+
67386+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67387+ !match->deleted))
67388+ match = match->next;
67389+
67390+ if (match && match->deleted)
67391+ return match;
67392+
67393+ match = running_polstate.name_set.n_hash[index];
67394+
67395+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67396+ match->deleted))
67397+ match = match->next;
67398+
67399+ if (match && !match->deleted)
67400+ return match;
67401+ else
67402+ return NULL;
67403+}
67404+
67405+static struct inodev_entry *
67406+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67407+{
67408+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67409+ struct inodev_entry *match;
67410+
67411+ match = running_polstate.inodev_set.i_hash[index];
67412+
67413+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67414+ match = match->next;
67415+
67416+ return match;
67417+}
67418+
67419+void
67420+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67421+{
67422+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67423+ state->inodev_set.i_size);
67424+ struct inodev_entry **curr;
67425+
67426+ entry->prev = NULL;
67427+
67428+ curr = &state->inodev_set.i_hash[index];
67429+ if (*curr != NULL)
67430+ (*curr)->prev = entry;
67431+
67432+ entry->next = *curr;
67433+ *curr = entry;
67434+
67435+ return;
67436+}
67437+
67438+static void
67439+insert_inodev_entry(struct inodev_entry *entry)
67440+{
67441+ __insert_inodev_entry(&running_polstate, entry);
67442+}
67443+
67444+void
67445+insert_acl_obj_label(struct acl_object_label *obj,
67446+ struct acl_subject_label *subj)
67447+{
67448+ unsigned int index =
67449+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67450+ struct acl_object_label **curr;
67451+
67452+ obj->prev = NULL;
67453+
67454+ curr = &subj->obj_hash[index];
67455+ if (*curr != NULL)
67456+ (*curr)->prev = obj;
67457+
67458+ obj->next = *curr;
67459+ *curr = obj;
67460+
67461+ return;
67462+}
67463+
67464+void
67465+insert_acl_subj_label(struct acl_subject_label *obj,
67466+ struct acl_role_label *role)
67467+{
67468+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67469+ struct acl_subject_label **curr;
67470+
67471+ obj->prev = NULL;
67472+
67473+ curr = &role->subj_hash[index];
67474+ if (*curr != NULL)
67475+ (*curr)->prev = obj;
67476+
67477+ obj->next = *curr;
67478+ *curr = obj;
67479+
67480+ return;
67481+}
67482+
67483+/* derived from glibc fnmatch() 0: match, 1: no match*/
67484+
67485+static int
67486+glob_match(const char *p, const char *n)
67487+{
67488+ char c;
67489+
67490+ while ((c = *p++) != '\0') {
67491+ switch (c) {
67492+ case '?':
67493+ if (*n == '\0')
67494+ return 1;
67495+ else if (*n == '/')
67496+ return 1;
67497+ break;
67498+ case '\\':
67499+ if (*n != c)
67500+ return 1;
67501+ break;
67502+ case '*':
67503+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67504+ if (*n == '/')
67505+ return 1;
67506+ else if (c == '?') {
67507+ if (*n == '\0')
67508+ return 1;
67509+ else
67510+ ++n;
67511+ }
67512+ }
67513+ if (c == '\0') {
67514+ return 0;
67515+ } else {
67516+ const char *endp;
67517+
67518+ if ((endp = strchr(n, '/')) == NULL)
67519+ endp = n + strlen(n);
67520+
67521+ if (c == '[') {
67522+ for (--p; n < endp; ++n)
67523+ if (!glob_match(p, n))
67524+ return 0;
67525+ } else if (c == '/') {
67526+ while (*n != '\0' && *n != '/')
67527+ ++n;
67528+ if (*n == '/' && !glob_match(p, n + 1))
67529+ return 0;
67530+ } else {
67531+ for (--p; n < endp; ++n)
67532+ if (*n == c && !glob_match(p, n))
67533+ return 0;
67534+ }
67535+
67536+ return 1;
67537+ }
67538+ case '[':
67539+ {
67540+ int not;
67541+ char cold;
67542+
67543+ if (*n == '\0' || *n == '/')
67544+ return 1;
67545+
67546+ not = (*p == '!' || *p == '^');
67547+ if (not)
67548+ ++p;
67549+
67550+ c = *p++;
67551+ for (;;) {
67552+ unsigned char fn = (unsigned char)*n;
67553+
67554+ if (c == '\0')
67555+ return 1;
67556+ else {
67557+ if (c == fn)
67558+ goto matched;
67559+ cold = c;
67560+ c = *p++;
67561+
67562+ if (c == '-' && *p != ']') {
67563+ unsigned char cend = *p++;
67564+
67565+ if (cend == '\0')
67566+ return 1;
67567+
67568+ if (cold <= fn && fn <= cend)
67569+ goto matched;
67570+
67571+ c = *p++;
67572+ }
67573+ }
67574+
67575+ if (c == ']')
67576+ break;
67577+ }
67578+ if (!not)
67579+ return 1;
67580+ break;
67581+ matched:
67582+ while (c != ']') {
67583+ if (c == '\0')
67584+ return 1;
67585+
67586+ c = *p++;
67587+ }
67588+ if (not)
67589+ return 1;
67590+ }
67591+ break;
67592+ default:
67593+ if (c != *n)
67594+ return 1;
67595+ }
67596+
67597+ ++n;
67598+ }
67599+
67600+ if (*n == '\0')
67601+ return 0;
67602+
67603+ if (*n == '/')
67604+ return 0;
67605+
67606+ return 1;
67607+}
67608+
67609+static struct acl_object_label *
67610+chk_glob_label(struct acl_object_label *globbed,
67611+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67612+{
67613+ struct acl_object_label *tmp;
67614+
67615+ if (*path == NULL)
67616+ *path = gr_to_filename_nolock(dentry, mnt);
67617+
67618+ tmp = globbed;
67619+
67620+ while (tmp) {
67621+ if (!glob_match(tmp->filename, *path))
67622+ return tmp;
67623+ tmp = tmp->next;
67624+ }
67625+
67626+ return NULL;
67627+}
67628+
67629+static struct acl_object_label *
67630+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67631+ const ino_t curr_ino, const dev_t curr_dev,
67632+ const struct acl_subject_label *subj, char **path, const int checkglob)
67633+{
67634+ struct acl_subject_label *tmpsubj;
67635+ struct acl_object_label *retval;
67636+ struct acl_object_label *retval2;
67637+
67638+ tmpsubj = (struct acl_subject_label *) subj;
67639+ read_lock(&gr_inode_lock);
67640+ do {
67641+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67642+ if (retval) {
67643+ if (checkglob && retval->globbed) {
67644+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67645+ if (retval2)
67646+ retval = retval2;
67647+ }
67648+ break;
67649+ }
67650+ } while ((tmpsubj = tmpsubj->parent_subject));
67651+ read_unlock(&gr_inode_lock);
67652+
67653+ return retval;
67654+}
67655+
67656+static __inline__ struct acl_object_label *
67657+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67658+ struct dentry *curr_dentry,
67659+ const struct acl_subject_label *subj, char **path, const int checkglob)
67660+{
67661+ int newglob = checkglob;
67662+ ino_t inode;
67663+ dev_t device;
67664+
67665+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67666+ as we don't want a / * rule to match instead of the / object
67667+ don't do this for create lookups that call this function though, since they're looking up
67668+ on the parent and thus need globbing checks on all paths
67669+ */
67670+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67671+ newglob = GR_NO_GLOB;
67672+
67673+ spin_lock(&curr_dentry->d_lock);
67674+ inode = curr_dentry->d_inode->i_ino;
67675+ device = __get_dev(curr_dentry);
67676+ spin_unlock(&curr_dentry->d_lock);
67677+
67678+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67679+}
67680+
67681+#ifdef CONFIG_HUGETLBFS
67682+static inline bool
67683+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67684+{
67685+ int i;
67686+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67687+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67688+ return true;
67689+ }
67690+
67691+ return false;
67692+}
67693+#endif
67694+
67695+static struct acl_object_label *
67696+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67697+ const struct acl_subject_label *subj, char *path, const int checkglob)
67698+{
67699+ struct dentry *dentry = (struct dentry *) l_dentry;
67700+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67701+ struct mount *real_mnt = real_mount(mnt);
67702+ struct acl_object_label *retval;
67703+ struct dentry *parent;
67704+
67705+ read_seqlock_excl(&mount_lock);
67706+ write_seqlock(&rename_lock);
67707+
67708+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67709+#ifdef CONFIG_NET
67710+ mnt == sock_mnt ||
67711+#endif
67712+#ifdef CONFIG_HUGETLBFS
67713+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67714+#endif
67715+ /* ignore Eric Biederman */
67716+ IS_PRIVATE(l_dentry->d_inode))) {
67717+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67718+ goto out;
67719+ }
67720+
67721+ for (;;) {
67722+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67723+ break;
67724+
67725+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67726+ if (!mnt_has_parent(real_mnt))
67727+ break;
67728+
67729+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67730+ if (retval != NULL)
67731+ goto out;
67732+
67733+ dentry = real_mnt->mnt_mountpoint;
67734+ real_mnt = real_mnt->mnt_parent;
67735+ mnt = &real_mnt->mnt;
67736+ continue;
67737+ }
67738+
67739+ parent = dentry->d_parent;
67740+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67741+ if (retval != NULL)
67742+ goto out;
67743+
67744+ dentry = parent;
67745+ }
67746+
67747+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67748+
67749+ /* gr_real_root is pinned so we don't have to hold a reference */
67750+ if (retval == NULL)
67751+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67752+out:
67753+ write_sequnlock(&rename_lock);
67754+ read_sequnlock_excl(&mount_lock);
67755+
67756+ BUG_ON(retval == NULL);
67757+
67758+ return retval;
67759+}
67760+
67761+static __inline__ struct acl_object_label *
67762+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67763+ const struct acl_subject_label *subj)
67764+{
67765+ char *path = NULL;
67766+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67767+}
67768+
67769+static __inline__ struct acl_object_label *
67770+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67771+ const struct acl_subject_label *subj)
67772+{
67773+ char *path = NULL;
67774+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67775+}
67776+
67777+static __inline__ struct acl_object_label *
67778+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67779+ const struct acl_subject_label *subj, char *path)
67780+{
67781+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67782+}
67783+
67784+struct acl_subject_label *
67785+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67786+ const struct acl_role_label *role)
67787+{
67788+ struct dentry *dentry = (struct dentry *) l_dentry;
67789+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67790+ struct mount *real_mnt = real_mount(mnt);
67791+ struct acl_subject_label *retval;
67792+ struct dentry *parent;
67793+
67794+ read_seqlock_excl(&mount_lock);
67795+ write_seqlock(&rename_lock);
67796+
67797+ for (;;) {
67798+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67799+ break;
67800+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67801+ if (!mnt_has_parent(real_mnt))
67802+ break;
67803+
67804+ spin_lock(&dentry->d_lock);
67805+ read_lock(&gr_inode_lock);
67806+ retval =
67807+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67808+ __get_dev(dentry), role);
67809+ read_unlock(&gr_inode_lock);
67810+ spin_unlock(&dentry->d_lock);
67811+ if (retval != NULL)
67812+ goto out;
67813+
67814+ dentry = real_mnt->mnt_mountpoint;
67815+ real_mnt = real_mnt->mnt_parent;
67816+ mnt = &real_mnt->mnt;
67817+ continue;
67818+ }
67819+
67820+ spin_lock(&dentry->d_lock);
67821+ read_lock(&gr_inode_lock);
67822+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67823+ __get_dev(dentry), role);
67824+ read_unlock(&gr_inode_lock);
67825+ parent = dentry->d_parent;
67826+ spin_unlock(&dentry->d_lock);
67827+
67828+ if (retval != NULL)
67829+ goto out;
67830+
67831+ dentry = parent;
67832+ }
67833+
67834+ spin_lock(&dentry->d_lock);
67835+ read_lock(&gr_inode_lock);
67836+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67837+ __get_dev(dentry), role);
67838+ read_unlock(&gr_inode_lock);
67839+ spin_unlock(&dentry->d_lock);
67840+
67841+ if (unlikely(retval == NULL)) {
67842+ /* gr_real_root is pinned, we don't need to hold a reference */
67843+ read_lock(&gr_inode_lock);
67844+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67845+ __get_dev(gr_real_root.dentry), role);
67846+ read_unlock(&gr_inode_lock);
67847+ }
67848+out:
67849+ write_sequnlock(&rename_lock);
67850+ read_sequnlock_excl(&mount_lock);
67851+
67852+ BUG_ON(retval == NULL);
67853+
67854+ return retval;
67855+}
67856+
67857+void
67858+assign_special_role(const char *rolename)
67859+{
67860+ struct acl_object_label *obj;
67861+ struct acl_role_label *r;
67862+ struct acl_role_label *assigned = NULL;
67863+ struct task_struct *tsk;
67864+ struct file *filp;
67865+
67866+ FOR_EACH_ROLE_START(r)
67867+ if (!strcmp(rolename, r->rolename) &&
67868+ (r->roletype & GR_ROLE_SPECIAL)) {
67869+ assigned = r;
67870+ break;
67871+ }
67872+ FOR_EACH_ROLE_END(r)
67873+
67874+ if (!assigned)
67875+ return;
67876+
67877+ read_lock(&tasklist_lock);
67878+ read_lock(&grsec_exec_file_lock);
67879+
67880+ tsk = current->real_parent;
67881+ if (tsk == NULL)
67882+ goto out_unlock;
67883+
67884+ filp = tsk->exec_file;
67885+ if (filp == NULL)
67886+ goto out_unlock;
67887+
67888+ tsk->is_writable = 0;
67889+ tsk->inherited = 0;
67890+
67891+ tsk->acl_sp_role = 1;
67892+ tsk->acl_role_id = ++acl_sp_role_value;
67893+ tsk->role = assigned;
67894+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67895+
67896+ /* ignore additional mmap checks for processes that are writable
67897+ by the default ACL */
67898+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67899+ if (unlikely(obj->mode & GR_WRITE))
67900+ tsk->is_writable = 1;
67901+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67902+ if (unlikely(obj->mode & GR_WRITE))
67903+ tsk->is_writable = 1;
67904+
67905+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67906+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67907+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67908+#endif
67909+
67910+out_unlock:
67911+ read_unlock(&grsec_exec_file_lock);
67912+ read_unlock(&tasklist_lock);
67913+ return;
67914+}
67915+
67916+
67917+static void
67918+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67919+{
67920+ struct task_struct *task = current;
67921+ const struct cred *cred = current_cred();
67922+
67923+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67924+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67925+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67926+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67927+
67928+ return;
67929+}
67930+
67931+static void
67932+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67933+{
67934+ struct task_struct *task = current;
67935+ const struct cred *cred = current_cred();
67936+
67937+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67938+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67939+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67940+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67941+
67942+ return;
67943+}
67944+
67945+static void
67946+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67947+{
67948+ struct task_struct *task = current;
67949+ const struct cred *cred = current_cred();
67950+
67951+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67952+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67953+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67954+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67955+
67956+ return;
67957+}
67958+
67959+static void
67960+gr_set_proc_res(struct task_struct *task)
67961+{
67962+ struct acl_subject_label *proc;
67963+ unsigned short i;
67964+
67965+ proc = task->acl;
67966+
67967+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67968+ return;
67969+
67970+ for (i = 0; i < RLIM_NLIMITS; i++) {
67971+ if (!(proc->resmask & (1U << i)))
67972+ continue;
67973+
67974+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67975+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67976+
67977+ if (i == RLIMIT_CPU)
67978+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67979+ }
67980+
67981+ return;
67982+}
67983+
67984+/* both of the below must be called with
67985+ rcu_read_lock();
67986+ read_lock(&tasklist_lock);
67987+ read_lock(&grsec_exec_file_lock);
67988+*/
67989+
67990+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67991+{
67992+ char *tmpname;
67993+ struct acl_subject_label *tmpsubj;
67994+ struct file *filp;
67995+ struct name_entry *nmatch;
67996+
67997+ filp = task->exec_file;
67998+ if (filp == NULL)
67999+ return NULL;
68000+
68001+ /* the following is to apply the correct subject
68002+ on binaries running when the RBAC system
68003+ is enabled, when the binaries have been
68004+ replaced or deleted since their execution
68005+ -----
68006+ when the RBAC system starts, the inode/dev
68007+ from exec_file will be one the RBAC system
68008+ is unaware of. It only knows the inode/dev
68009+ of the present file on disk, or the absence
68010+ of it.
68011+ */
68012+
68013+ if (filename)
68014+ nmatch = __lookup_name_entry(state, filename);
68015+ else {
68016+ preempt_disable();
68017+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68018+
68019+ nmatch = __lookup_name_entry(state, tmpname);
68020+ preempt_enable();
68021+ }
68022+ tmpsubj = NULL;
68023+ if (nmatch) {
68024+ if (nmatch->deleted)
68025+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68026+ else
68027+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68028+ }
68029+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68030+ then we fall back to a normal lookup based on the binary's ino/dev
68031+ */
68032+ if (tmpsubj == NULL)
68033+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68034+
68035+ return tmpsubj;
68036+}
68037+
68038+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68039+{
68040+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68041+}
68042+
68043+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68044+{
68045+ struct acl_object_label *obj;
68046+ struct file *filp;
68047+
68048+ filp = task->exec_file;
68049+
68050+ task->acl = subj;
68051+ task->is_writable = 0;
68052+ /* ignore additional mmap checks for processes that are writable
68053+ by the default ACL */
68054+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68055+ if (unlikely(obj->mode & GR_WRITE))
68056+ task->is_writable = 1;
68057+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68058+ if (unlikely(obj->mode & GR_WRITE))
68059+ task->is_writable = 1;
68060+
68061+ gr_set_proc_res(task);
68062+
68063+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68064+ 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);
68065+#endif
68066+}
68067+
68068+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68069+{
68070+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68071+}
68072+
68073+__u32
68074+gr_search_file(const struct dentry * dentry, const __u32 mode,
68075+ const struct vfsmount * mnt)
68076+{
68077+ __u32 retval = mode;
68078+ struct acl_subject_label *curracl;
68079+ struct acl_object_label *currobj;
68080+
68081+ if (unlikely(!(gr_status & GR_READY)))
68082+ return (mode & ~GR_AUDITS);
68083+
68084+ curracl = current->acl;
68085+
68086+ currobj = chk_obj_label(dentry, mnt, curracl);
68087+ retval = currobj->mode & mode;
68088+
68089+ /* if we're opening a specified transfer file for writing
68090+ (e.g. /dev/initctl), then transfer our role to init
68091+ */
68092+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68093+ current->role->roletype & GR_ROLE_PERSIST)) {
68094+ struct task_struct *task = init_pid_ns.child_reaper;
68095+
68096+ if (task->role != current->role) {
68097+ struct acl_subject_label *subj;
68098+
68099+ task->acl_sp_role = 0;
68100+ task->acl_role_id = current->acl_role_id;
68101+ task->role = current->role;
68102+ rcu_read_lock();
68103+ read_lock(&grsec_exec_file_lock);
68104+ subj = gr_get_subject_for_task(task, NULL);
68105+ gr_apply_subject_to_task(task, subj);
68106+ read_unlock(&grsec_exec_file_lock);
68107+ rcu_read_unlock();
68108+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68109+ }
68110+ }
68111+
68112+ if (unlikely
68113+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68114+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68115+ __u32 new_mode = mode;
68116+
68117+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68118+
68119+ retval = new_mode;
68120+
68121+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68122+ new_mode |= GR_INHERIT;
68123+
68124+ if (!(mode & GR_NOLEARN))
68125+ gr_log_learn(dentry, mnt, new_mode);
68126+ }
68127+
68128+ return retval;
68129+}
68130+
68131+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68132+ const struct dentry *parent,
68133+ const struct vfsmount *mnt)
68134+{
68135+ struct name_entry *match;
68136+ struct acl_object_label *matchpo;
68137+ struct acl_subject_label *curracl;
68138+ char *path;
68139+
68140+ if (unlikely(!(gr_status & GR_READY)))
68141+ return NULL;
68142+
68143+ preempt_disable();
68144+ path = gr_to_filename_rbac(new_dentry, mnt);
68145+ match = lookup_name_entry_create(path);
68146+
68147+ curracl = current->acl;
68148+
68149+ if (match) {
68150+ read_lock(&gr_inode_lock);
68151+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68152+ read_unlock(&gr_inode_lock);
68153+
68154+ if (matchpo) {
68155+ preempt_enable();
68156+ return matchpo;
68157+ }
68158+ }
68159+
68160+ // lookup parent
68161+
68162+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68163+
68164+ preempt_enable();
68165+ return matchpo;
68166+}
68167+
68168+__u32
68169+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68170+ const struct vfsmount * mnt, const __u32 mode)
68171+{
68172+ struct acl_object_label *matchpo;
68173+ __u32 retval;
68174+
68175+ if (unlikely(!(gr_status & GR_READY)))
68176+ return (mode & ~GR_AUDITS);
68177+
68178+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68179+
68180+ retval = matchpo->mode & mode;
68181+
68182+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68183+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68184+ __u32 new_mode = mode;
68185+
68186+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68187+
68188+ gr_log_learn(new_dentry, mnt, new_mode);
68189+ return new_mode;
68190+ }
68191+
68192+ return retval;
68193+}
68194+
68195+__u32
68196+gr_check_link(const struct dentry * new_dentry,
68197+ const struct dentry * parent_dentry,
68198+ const struct vfsmount * parent_mnt,
68199+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68200+{
68201+ struct acl_object_label *obj;
68202+ __u32 oldmode, newmode;
68203+ __u32 needmode;
68204+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68205+ GR_DELETE | GR_INHERIT;
68206+
68207+ if (unlikely(!(gr_status & GR_READY)))
68208+ return (GR_CREATE | GR_LINK);
68209+
68210+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68211+ oldmode = obj->mode;
68212+
68213+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68214+ newmode = obj->mode;
68215+
68216+ needmode = newmode & checkmodes;
68217+
68218+ // old name for hardlink must have at least the permissions of the new name
68219+ if ((oldmode & needmode) != needmode)
68220+ goto bad;
68221+
68222+ // if old name had restrictions/auditing, make sure the new name does as well
68223+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68224+
68225+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68226+ if (is_privileged_binary(old_dentry))
68227+ needmode |= GR_SETID;
68228+
68229+ if ((newmode & needmode) != needmode)
68230+ goto bad;
68231+
68232+ // enforce minimum permissions
68233+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68234+ return newmode;
68235+bad:
68236+ needmode = oldmode;
68237+ if (is_privileged_binary(old_dentry))
68238+ needmode |= GR_SETID;
68239+
68240+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68241+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68242+ return (GR_CREATE | GR_LINK);
68243+ } else if (newmode & GR_SUPPRESS)
68244+ return GR_SUPPRESS;
68245+ else
68246+ return 0;
68247+}
68248+
68249+int
68250+gr_check_hidden_task(const struct task_struct *task)
68251+{
68252+ if (unlikely(!(gr_status & GR_READY)))
68253+ return 0;
68254+
68255+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68256+ return 1;
68257+
68258+ return 0;
68259+}
68260+
68261+int
68262+gr_check_protected_task(const struct task_struct *task)
68263+{
68264+ if (unlikely(!(gr_status & GR_READY) || !task))
68265+ return 0;
68266+
68267+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68268+ task->acl != current->acl)
68269+ return 1;
68270+
68271+ return 0;
68272+}
68273+
68274+int
68275+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68276+{
68277+ struct task_struct *p;
68278+ int ret = 0;
68279+
68280+ if (unlikely(!(gr_status & GR_READY) || !pid))
68281+ return ret;
68282+
68283+ read_lock(&tasklist_lock);
68284+ do_each_pid_task(pid, type, p) {
68285+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68286+ p->acl != current->acl) {
68287+ ret = 1;
68288+ goto out;
68289+ }
68290+ } while_each_pid_task(pid, type, p);
68291+out:
68292+ read_unlock(&tasklist_lock);
68293+
68294+ return ret;
68295+}
68296+
68297+void
68298+gr_copy_label(struct task_struct *tsk)
68299+{
68300+ struct task_struct *p = current;
68301+
68302+ tsk->inherited = p->inherited;
68303+ tsk->acl_sp_role = 0;
68304+ tsk->acl_role_id = p->acl_role_id;
68305+ tsk->acl = p->acl;
68306+ tsk->role = p->role;
68307+ tsk->signal->used_accept = 0;
68308+ tsk->signal->curr_ip = p->signal->curr_ip;
68309+ tsk->signal->saved_ip = p->signal->saved_ip;
68310+ if (p->exec_file)
68311+ get_file(p->exec_file);
68312+ tsk->exec_file = p->exec_file;
68313+ tsk->is_writable = p->is_writable;
68314+ if (unlikely(p->signal->used_accept)) {
68315+ p->signal->curr_ip = 0;
68316+ p->signal->saved_ip = 0;
68317+ }
68318+
68319+ return;
68320+}
68321+
68322+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68323+
68324+int
68325+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68326+{
68327+ unsigned int i;
68328+ __u16 num;
68329+ uid_t *uidlist;
68330+ uid_t curuid;
68331+ int realok = 0;
68332+ int effectiveok = 0;
68333+ int fsok = 0;
68334+ uid_t globalreal, globaleffective, globalfs;
68335+
68336+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68337+ struct user_struct *user;
68338+
68339+ if (!uid_valid(real))
68340+ goto skipit;
68341+
68342+ /* find user based on global namespace */
68343+
68344+ globalreal = GR_GLOBAL_UID(real);
68345+
68346+ user = find_user(make_kuid(&init_user_ns, globalreal));
68347+ if (user == NULL)
68348+ goto skipit;
68349+
68350+ if (gr_process_kernel_setuid_ban(user)) {
68351+ /* for find_user */
68352+ free_uid(user);
68353+ return 1;
68354+ }
68355+
68356+ /* for find_user */
68357+ free_uid(user);
68358+
68359+skipit:
68360+#endif
68361+
68362+ if (unlikely(!(gr_status & GR_READY)))
68363+ return 0;
68364+
68365+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68366+ gr_log_learn_uid_change(real, effective, fs);
68367+
68368+ num = current->acl->user_trans_num;
68369+ uidlist = current->acl->user_transitions;
68370+
68371+ if (uidlist == NULL)
68372+ return 0;
68373+
68374+ if (!uid_valid(real)) {
68375+ realok = 1;
68376+ globalreal = (uid_t)-1;
68377+ } else {
68378+ globalreal = GR_GLOBAL_UID(real);
68379+ }
68380+ if (!uid_valid(effective)) {
68381+ effectiveok = 1;
68382+ globaleffective = (uid_t)-1;
68383+ } else {
68384+ globaleffective = GR_GLOBAL_UID(effective);
68385+ }
68386+ if (!uid_valid(fs)) {
68387+ fsok = 1;
68388+ globalfs = (uid_t)-1;
68389+ } else {
68390+ globalfs = GR_GLOBAL_UID(fs);
68391+ }
68392+
68393+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68394+ for (i = 0; i < num; i++) {
68395+ curuid = uidlist[i];
68396+ if (globalreal == curuid)
68397+ realok = 1;
68398+ if (globaleffective == curuid)
68399+ effectiveok = 1;
68400+ if (globalfs == curuid)
68401+ fsok = 1;
68402+ }
68403+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68404+ for (i = 0; i < num; i++) {
68405+ curuid = uidlist[i];
68406+ if (globalreal == curuid)
68407+ break;
68408+ if (globaleffective == curuid)
68409+ break;
68410+ if (globalfs == curuid)
68411+ break;
68412+ }
68413+ /* not in deny list */
68414+ if (i == num) {
68415+ realok = 1;
68416+ effectiveok = 1;
68417+ fsok = 1;
68418+ }
68419+ }
68420+
68421+ if (realok && effectiveok && fsok)
68422+ return 0;
68423+ else {
68424+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68425+ return 1;
68426+ }
68427+}
68428+
68429+int
68430+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68431+{
68432+ unsigned int i;
68433+ __u16 num;
68434+ gid_t *gidlist;
68435+ gid_t curgid;
68436+ int realok = 0;
68437+ int effectiveok = 0;
68438+ int fsok = 0;
68439+ gid_t globalreal, globaleffective, globalfs;
68440+
68441+ if (unlikely(!(gr_status & GR_READY)))
68442+ return 0;
68443+
68444+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68445+ gr_log_learn_gid_change(real, effective, fs);
68446+
68447+ num = current->acl->group_trans_num;
68448+ gidlist = current->acl->group_transitions;
68449+
68450+ if (gidlist == NULL)
68451+ return 0;
68452+
68453+ if (!gid_valid(real)) {
68454+ realok = 1;
68455+ globalreal = (gid_t)-1;
68456+ } else {
68457+ globalreal = GR_GLOBAL_GID(real);
68458+ }
68459+ if (!gid_valid(effective)) {
68460+ effectiveok = 1;
68461+ globaleffective = (gid_t)-1;
68462+ } else {
68463+ globaleffective = GR_GLOBAL_GID(effective);
68464+ }
68465+ if (!gid_valid(fs)) {
68466+ fsok = 1;
68467+ globalfs = (gid_t)-1;
68468+ } else {
68469+ globalfs = GR_GLOBAL_GID(fs);
68470+ }
68471+
68472+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68473+ for (i = 0; i < num; i++) {
68474+ curgid = gidlist[i];
68475+ if (globalreal == curgid)
68476+ realok = 1;
68477+ if (globaleffective == curgid)
68478+ effectiveok = 1;
68479+ if (globalfs == curgid)
68480+ fsok = 1;
68481+ }
68482+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68483+ for (i = 0; i < num; i++) {
68484+ curgid = gidlist[i];
68485+ if (globalreal == curgid)
68486+ break;
68487+ if (globaleffective == curgid)
68488+ break;
68489+ if (globalfs == curgid)
68490+ break;
68491+ }
68492+ /* not in deny list */
68493+ if (i == num) {
68494+ realok = 1;
68495+ effectiveok = 1;
68496+ fsok = 1;
68497+ }
68498+ }
68499+
68500+ if (realok && effectiveok && fsok)
68501+ return 0;
68502+ else {
68503+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68504+ return 1;
68505+ }
68506+}
68507+
68508+extern int gr_acl_is_capable(const int cap);
68509+
68510+void
68511+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68512+{
68513+ struct acl_role_label *role = task->role;
68514+ struct acl_subject_label *subj = NULL;
68515+ struct acl_object_label *obj;
68516+ struct file *filp;
68517+ uid_t uid;
68518+ gid_t gid;
68519+
68520+ if (unlikely(!(gr_status & GR_READY)))
68521+ return;
68522+
68523+ uid = GR_GLOBAL_UID(kuid);
68524+ gid = GR_GLOBAL_GID(kgid);
68525+
68526+ filp = task->exec_file;
68527+
68528+ /* kernel process, we'll give them the kernel role */
68529+ if (unlikely(!filp)) {
68530+ task->role = running_polstate.kernel_role;
68531+ task->acl = running_polstate.kernel_role->root_label;
68532+ return;
68533+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68534+ /* save the current ip at time of role lookup so that the proper
68535+ IP will be learned for role_allowed_ip */
68536+ task->signal->saved_ip = task->signal->curr_ip;
68537+ role = lookup_acl_role_label(task, uid, gid);
68538+ }
68539+
68540+ /* don't change the role if we're not a privileged process */
68541+ if (role && task->role != role &&
68542+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68543+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68544+ return;
68545+
68546+ /* perform subject lookup in possibly new role
68547+ we can use this result below in the case where role == task->role
68548+ */
68549+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68550+
68551+ /* if we changed uid/gid, but result in the same role
68552+ and are using inheritance, don't lose the inherited subject
68553+ if current subject is other than what normal lookup
68554+ would result in, we arrived via inheritance, don't
68555+ lose subject
68556+ */
68557+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68558+ (subj == task->acl)))
68559+ task->acl = subj;
68560+
68561+ /* leave task->inherited unaffected */
68562+
68563+ task->role = role;
68564+
68565+ task->is_writable = 0;
68566+
68567+ /* ignore additional mmap checks for processes that are writable
68568+ by the default ACL */
68569+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68570+ if (unlikely(obj->mode & GR_WRITE))
68571+ task->is_writable = 1;
68572+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68573+ if (unlikely(obj->mode & GR_WRITE))
68574+ task->is_writable = 1;
68575+
68576+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68577+ 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);
68578+#endif
68579+
68580+ gr_set_proc_res(task);
68581+
68582+ return;
68583+}
68584+
68585+int
68586+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68587+ const int unsafe_flags)
68588+{
68589+ struct task_struct *task = current;
68590+ struct acl_subject_label *newacl;
68591+ struct acl_object_label *obj;
68592+ __u32 retmode;
68593+
68594+ if (unlikely(!(gr_status & GR_READY)))
68595+ return 0;
68596+
68597+ newacl = chk_subj_label(dentry, mnt, task->role);
68598+
68599+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68600+ did an exec
68601+ */
68602+ rcu_read_lock();
68603+ read_lock(&tasklist_lock);
68604+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68605+ (task->parent->acl->mode & GR_POVERRIDE))) {
68606+ read_unlock(&tasklist_lock);
68607+ rcu_read_unlock();
68608+ goto skip_check;
68609+ }
68610+ read_unlock(&tasklist_lock);
68611+ rcu_read_unlock();
68612+
68613+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68614+ !(task->role->roletype & GR_ROLE_GOD) &&
68615+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68616+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68617+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68618+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68619+ else
68620+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68621+ return -EACCES;
68622+ }
68623+
68624+skip_check:
68625+
68626+ obj = chk_obj_label(dentry, mnt, task->acl);
68627+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68628+
68629+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68630+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68631+ if (obj->nested)
68632+ task->acl = obj->nested;
68633+ else
68634+ task->acl = newacl;
68635+ task->inherited = 0;
68636+ } else {
68637+ task->inherited = 1;
68638+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68639+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68640+ }
68641+
68642+ task->is_writable = 0;
68643+
68644+ /* ignore additional mmap checks for processes that are writable
68645+ by the default ACL */
68646+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68647+ if (unlikely(obj->mode & GR_WRITE))
68648+ task->is_writable = 1;
68649+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68650+ if (unlikely(obj->mode & GR_WRITE))
68651+ task->is_writable = 1;
68652+
68653+ gr_set_proc_res(task);
68654+
68655+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68656+ 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);
68657+#endif
68658+ return 0;
68659+}
68660+
68661+/* always called with valid inodev ptr */
68662+static void
68663+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68664+{
68665+ struct acl_object_label *matchpo;
68666+ struct acl_subject_label *matchps;
68667+ struct acl_subject_label *subj;
68668+ struct acl_role_label *role;
68669+ unsigned int x;
68670+
68671+ FOR_EACH_ROLE_START(role)
68672+ FOR_EACH_SUBJECT_START(role, subj, x)
68673+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68674+ matchpo->mode |= GR_DELETED;
68675+ FOR_EACH_SUBJECT_END(subj,x)
68676+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68677+ /* nested subjects aren't in the role's subj_hash table */
68678+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68679+ matchpo->mode |= GR_DELETED;
68680+ FOR_EACH_NESTED_SUBJECT_END(subj)
68681+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68682+ matchps->mode |= GR_DELETED;
68683+ FOR_EACH_ROLE_END(role)
68684+
68685+ inodev->nentry->deleted = 1;
68686+
68687+ return;
68688+}
68689+
68690+void
68691+gr_handle_delete(const ino_t ino, const dev_t dev)
68692+{
68693+ struct inodev_entry *inodev;
68694+
68695+ if (unlikely(!(gr_status & GR_READY)))
68696+ return;
68697+
68698+ write_lock(&gr_inode_lock);
68699+ inodev = lookup_inodev_entry(ino, dev);
68700+ if (inodev != NULL)
68701+ do_handle_delete(inodev, ino, dev);
68702+ write_unlock(&gr_inode_lock);
68703+
68704+ return;
68705+}
68706+
68707+static void
68708+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68709+ const ino_t newinode, const dev_t newdevice,
68710+ struct acl_subject_label *subj)
68711+{
68712+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68713+ struct acl_object_label *match;
68714+
68715+ match = subj->obj_hash[index];
68716+
68717+ while (match && (match->inode != oldinode ||
68718+ match->device != olddevice ||
68719+ !(match->mode & GR_DELETED)))
68720+ match = match->next;
68721+
68722+ if (match && (match->inode == oldinode)
68723+ && (match->device == olddevice)
68724+ && (match->mode & GR_DELETED)) {
68725+ if (match->prev == NULL) {
68726+ subj->obj_hash[index] = match->next;
68727+ if (match->next != NULL)
68728+ match->next->prev = NULL;
68729+ } else {
68730+ match->prev->next = match->next;
68731+ if (match->next != NULL)
68732+ match->next->prev = match->prev;
68733+ }
68734+ match->prev = NULL;
68735+ match->next = NULL;
68736+ match->inode = newinode;
68737+ match->device = newdevice;
68738+ match->mode &= ~GR_DELETED;
68739+
68740+ insert_acl_obj_label(match, subj);
68741+ }
68742+
68743+ return;
68744+}
68745+
68746+static void
68747+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68748+ const ino_t newinode, const dev_t newdevice,
68749+ struct acl_role_label *role)
68750+{
68751+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68752+ struct acl_subject_label *match;
68753+
68754+ match = role->subj_hash[index];
68755+
68756+ while (match && (match->inode != oldinode ||
68757+ match->device != olddevice ||
68758+ !(match->mode & GR_DELETED)))
68759+ match = match->next;
68760+
68761+ if (match && (match->inode == oldinode)
68762+ && (match->device == olddevice)
68763+ && (match->mode & GR_DELETED)) {
68764+ if (match->prev == NULL) {
68765+ role->subj_hash[index] = match->next;
68766+ if (match->next != NULL)
68767+ match->next->prev = NULL;
68768+ } else {
68769+ match->prev->next = match->next;
68770+ if (match->next != NULL)
68771+ match->next->prev = match->prev;
68772+ }
68773+ match->prev = NULL;
68774+ match->next = NULL;
68775+ match->inode = newinode;
68776+ match->device = newdevice;
68777+ match->mode &= ~GR_DELETED;
68778+
68779+ insert_acl_subj_label(match, role);
68780+ }
68781+
68782+ return;
68783+}
68784+
68785+static void
68786+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68787+ const ino_t newinode, const dev_t newdevice)
68788+{
68789+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68790+ struct inodev_entry *match;
68791+
68792+ match = running_polstate.inodev_set.i_hash[index];
68793+
68794+ while (match && (match->nentry->inode != oldinode ||
68795+ match->nentry->device != olddevice || !match->nentry->deleted))
68796+ match = match->next;
68797+
68798+ if (match && (match->nentry->inode == oldinode)
68799+ && (match->nentry->device == olddevice) &&
68800+ match->nentry->deleted) {
68801+ if (match->prev == NULL) {
68802+ running_polstate.inodev_set.i_hash[index] = match->next;
68803+ if (match->next != NULL)
68804+ match->next->prev = NULL;
68805+ } else {
68806+ match->prev->next = match->next;
68807+ if (match->next != NULL)
68808+ match->next->prev = match->prev;
68809+ }
68810+ match->prev = NULL;
68811+ match->next = NULL;
68812+ match->nentry->inode = newinode;
68813+ match->nentry->device = newdevice;
68814+ match->nentry->deleted = 0;
68815+
68816+ insert_inodev_entry(match);
68817+ }
68818+
68819+ return;
68820+}
68821+
68822+static void
68823+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68824+{
68825+ struct acl_subject_label *subj;
68826+ struct acl_role_label *role;
68827+ unsigned int x;
68828+
68829+ FOR_EACH_ROLE_START(role)
68830+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68831+
68832+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68833+ if ((subj->inode == ino) && (subj->device == dev)) {
68834+ subj->inode = ino;
68835+ subj->device = dev;
68836+ }
68837+ /* nested subjects aren't in the role's subj_hash table */
68838+ update_acl_obj_label(matchn->inode, matchn->device,
68839+ ino, dev, subj);
68840+ FOR_EACH_NESTED_SUBJECT_END(subj)
68841+ FOR_EACH_SUBJECT_START(role, subj, x)
68842+ update_acl_obj_label(matchn->inode, matchn->device,
68843+ ino, dev, subj);
68844+ FOR_EACH_SUBJECT_END(subj,x)
68845+ FOR_EACH_ROLE_END(role)
68846+
68847+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68848+
68849+ return;
68850+}
68851+
68852+static void
68853+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68854+ const struct vfsmount *mnt)
68855+{
68856+ ino_t ino = dentry->d_inode->i_ino;
68857+ dev_t dev = __get_dev(dentry);
68858+
68859+ __do_handle_create(matchn, ino, dev);
68860+
68861+ return;
68862+}
68863+
68864+void
68865+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68866+{
68867+ struct name_entry *matchn;
68868+
68869+ if (unlikely(!(gr_status & GR_READY)))
68870+ return;
68871+
68872+ preempt_disable();
68873+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68874+
68875+ if (unlikely((unsigned long)matchn)) {
68876+ write_lock(&gr_inode_lock);
68877+ do_handle_create(matchn, dentry, mnt);
68878+ write_unlock(&gr_inode_lock);
68879+ }
68880+ preempt_enable();
68881+
68882+ return;
68883+}
68884+
68885+void
68886+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68887+{
68888+ struct name_entry *matchn;
68889+
68890+ if (unlikely(!(gr_status & GR_READY)))
68891+ return;
68892+
68893+ preempt_disable();
68894+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68895+
68896+ if (unlikely((unsigned long)matchn)) {
68897+ write_lock(&gr_inode_lock);
68898+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68899+ write_unlock(&gr_inode_lock);
68900+ }
68901+ preempt_enable();
68902+
68903+ return;
68904+}
68905+
68906+void
68907+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68908+ struct dentry *old_dentry,
68909+ struct dentry *new_dentry,
68910+ struct vfsmount *mnt, const __u8 replace)
68911+{
68912+ struct name_entry *matchn;
68913+ struct inodev_entry *inodev;
68914+ struct inode *inode = new_dentry->d_inode;
68915+ ino_t old_ino = old_dentry->d_inode->i_ino;
68916+ dev_t old_dev = __get_dev(old_dentry);
68917+
68918+ /* vfs_rename swaps the name and parent link for old_dentry and
68919+ new_dentry
68920+ at this point, old_dentry has the new name, parent link, and inode
68921+ for the renamed file
68922+ if a file is being replaced by a rename, new_dentry has the inode
68923+ and name for the replaced file
68924+ */
68925+
68926+ if (unlikely(!(gr_status & GR_READY)))
68927+ return;
68928+
68929+ preempt_disable();
68930+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68931+
68932+ /* we wouldn't have to check d_inode if it weren't for
68933+ NFS silly-renaming
68934+ */
68935+
68936+ write_lock(&gr_inode_lock);
68937+ if (unlikely(replace && inode)) {
68938+ ino_t new_ino = inode->i_ino;
68939+ dev_t new_dev = __get_dev(new_dentry);
68940+
68941+ inodev = lookup_inodev_entry(new_ino, new_dev);
68942+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68943+ do_handle_delete(inodev, new_ino, new_dev);
68944+ }
68945+
68946+ inodev = lookup_inodev_entry(old_ino, old_dev);
68947+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68948+ do_handle_delete(inodev, old_ino, old_dev);
68949+
68950+ if (unlikely((unsigned long)matchn))
68951+ do_handle_create(matchn, old_dentry, mnt);
68952+
68953+ write_unlock(&gr_inode_lock);
68954+ preempt_enable();
68955+
68956+ return;
68957+}
68958+
68959+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68960+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68961+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68962+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68963+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68964+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68965+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68966+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68967+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68968+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68969+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68970+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68971+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68972+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68973+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68974+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68975+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68976+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68977+};
68978+
68979+void
68980+gr_learn_resource(const struct task_struct *task,
68981+ const int res, const unsigned long wanted, const int gt)
68982+{
68983+ struct acl_subject_label *acl;
68984+ const struct cred *cred;
68985+
68986+ if (unlikely((gr_status & GR_READY) &&
68987+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68988+ goto skip_reslog;
68989+
68990+ gr_log_resource(task, res, wanted, gt);
68991+skip_reslog:
68992+
68993+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68994+ return;
68995+
68996+ acl = task->acl;
68997+
68998+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68999+ !(acl->resmask & (1U << (unsigned short) res))))
69000+ return;
69001+
69002+ if (wanted >= acl->res[res].rlim_cur) {
69003+ unsigned long res_add;
69004+
69005+ res_add = wanted + res_learn_bumps[res];
69006+
69007+ acl->res[res].rlim_cur = res_add;
69008+
69009+ if (wanted > acl->res[res].rlim_max)
69010+ acl->res[res].rlim_max = res_add;
69011+
69012+ /* only log the subject filename, since resource logging is supported for
69013+ single-subject learning only */
69014+ rcu_read_lock();
69015+ cred = __task_cred(task);
69016+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69017+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69018+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69019+ "", (unsigned long) res, &task->signal->saved_ip);
69020+ rcu_read_unlock();
69021+ }
69022+
69023+ return;
69024+}
69025+EXPORT_SYMBOL_GPL(gr_learn_resource);
69026+#endif
69027+
69028+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69029+void
69030+pax_set_initial_flags(struct linux_binprm *bprm)
69031+{
69032+ struct task_struct *task = current;
69033+ struct acl_subject_label *proc;
69034+ unsigned long flags;
69035+
69036+ if (unlikely(!(gr_status & GR_READY)))
69037+ return;
69038+
69039+ flags = pax_get_flags(task);
69040+
69041+ proc = task->acl;
69042+
69043+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69044+ flags &= ~MF_PAX_PAGEEXEC;
69045+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69046+ flags &= ~MF_PAX_SEGMEXEC;
69047+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69048+ flags &= ~MF_PAX_RANDMMAP;
69049+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69050+ flags &= ~MF_PAX_EMUTRAMP;
69051+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69052+ flags &= ~MF_PAX_MPROTECT;
69053+
69054+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69055+ flags |= MF_PAX_PAGEEXEC;
69056+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69057+ flags |= MF_PAX_SEGMEXEC;
69058+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69059+ flags |= MF_PAX_RANDMMAP;
69060+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69061+ flags |= MF_PAX_EMUTRAMP;
69062+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69063+ flags |= MF_PAX_MPROTECT;
69064+
69065+ pax_set_flags(task, flags);
69066+
69067+ return;
69068+}
69069+#endif
69070+
69071+int
69072+gr_handle_proc_ptrace(struct task_struct *task)
69073+{
69074+ struct file *filp;
69075+ struct task_struct *tmp = task;
69076+ struct task_struct *curtemp = current;
69077+ __u32 retmode;
69078+
69079+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69080+ if (unlikely(!(gr_status & GR_READY)))
69081+ return 0;
69082+#endif
69083+
69084+ read_lock(&tasklist_lock);
69085+ read_lock(&grsec_exec_file_lock);
69086+ filp = task->exec_file;
69087+
69088+ while (task_pid_nr(tmp) > 0) {
69089+ if (tmp == curtemp)
69090+ break;
69091+ tmp = tmp->real_parent;
69092+ }
69093+
69094+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69095+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69096+ read_unlock(&grsec_exec_file_lock);
69097+ read_unlock(&tasklist_lock);
69098+ return 1;
69099+ }
69100+
69101+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69102+ if (!(gr_status & GR_READY)) {
69103+ read_unlock(&grsec_exec_file_lock);
69104+ read_unlock(&tasklist_lock);
69105+ return 0;
69106+ }
69107+#endif
69108+
69109+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69110+ read_unlock(&grsec_exec_file_lock);
69111+ read_unlock(&tasklist_lock);
69112+
69113+ if (retmode & GR_NOPTRACE)
69114+ return 1;
69115+
69116+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69117+ && (current->acl != task->acl || (current->acl != current->role->root_label
69118+ && task_pid_nr(current) != task_pid_nr(task))))
69119+ return 1;
69120+
69121+ return 0;
69122+}
69123+
69124+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69125+{
69126+ if (unlikely(!(gr_status & GR_READY)))
69127+ return;
69128+
69129+ if (!(current->role->roletype & GR_ROLE_GOD))
69130+ return;
69131+
69132+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69133+ p->role->rolename, gr_task_roletype_to_char(p),
69134+ p->acl->filename);
69135+}
69136+
69137+int
69138+gr_handle_ptrace(struct task_struct *task, const long request)
69139+{
69140+ struct task_struct *tmp = task;
69141+ struct task_struct *curtemp = current;
69142+ __u32 retmode;
69143+
69144+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69145+ if (unlikely(!(gr_status & GR_READY)))
69146+ return 0;
69147+#endif
69148+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69149+ read_lock(&tasklist_lock);
69150+ while (task_pid_nr(tmp) > 0) {
69151+ if (tmp == curtemp)
69152+ break;
69153+ tmp = tmp->real_parent;
69154+ }
69155+
69156+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69157+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69158+ read_unlock(&tasklist_lock);
69159+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69160+ return 1;
69161+ }
69162+ read_unlock(&tasklist_lock);
69163+ }
69164+
69165+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69166+ if (!(gr_status & GR_READY))
69167+ return 0;
69168+#endif
69169+
69170+ read_lock(&grsec_exec_file_lock);
69171+ if (unlikely(!task->exec_file)) {
69172+ read_unlock(&grsec_exec_file_lock);
69173+ return 0;
69174+ }
69175+
69176+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69177+ read_unlock(&grsec_exec_file_lock);
69178+
69179+ if (retmode & GR_NOPTRACE) {
69180+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69181+ return 1;
69182+ }
69183+
69184+ if (retmode & GR_PTRACERD) {
69185+ switch (request) {
69186+ case PTRACE_SEIZE:
69187+ case PTRACE_POKETEXT:
69188+ case PTRACE_POKEDATA:
69189+ case PTRACE_POKEUSR:
69190+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69191+ case PTRACE_SETREGS:
69192+ case PTRACE_SETFPREGS:
69193+#endif
69194+#ifdef CONFIG_X86
69195+ case PTRACE_SETFPXREGS:
69196+#endif
69197+#ifdef CONFIG_ALTIVEC
69198+ case PTRACE_SETVRREGS:
69199+#endif
69200+ return 1;
69201+ default:
69202+ return 0;
69203+ }
69204+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69205+ !(current->role->roletype & GR_ROLE_GOD) &&
69206+ (current->acl != task->acl)) {
69207+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69208+ return 1;
69209+ }
69210+
69211+ return 0;
69212+}
69213+
69214+static int is_writable_mmap(const struct file *filp)
69215+{
69216+ struct task_struct *task = current;
69217+ struct acl_object_label *obj, *obj2;
69218+
69219+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69220+ !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))) {
69221+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69222+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69223+ task->role->root_label);
69224+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69225+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69226+ return 1;
69227+ }
69228+ }
69229+ return 0;
69230+}
69231+
69232+int
69233+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69234+{
69235+ __u32 mode;
69236+
69237+ if (unlikely(!file || !(prot & PROT_EXEC)))
69238+ return 1;
69239+
69240+ if (is_writable_mmap(file))
69241+ return 0;
69242+
69243+ mode =
69244+ gr_search_file(file->f_path.dentry,
69245+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69246+ file->f_path.mnt);
69247+
69248+ if (!gr_tpe_allow(file))
69249+ return 0;
69250+
69251+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69252+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69253+ return 0;
69254+ } else if (unlikely(!(mode & GR_EXEC))) {
69255+ return 0;
69256+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69257+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69258+ return 1;
69259+ }
69260+
69261+ return 1;
69262+}
69263+
69264+int
69265+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69266+{
69267+ __u32 mode;
69268+
69269+ if (unlikely(!file || !(prot & PROT_EXEC)))
69270+ return 1;
69271+
69272+ if (is_writable_mmap(file))
69273+ return 0;
69274+
69275+ mode =
69276+ gr_search_file(file->f_path.dentry,
69277+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69278+ file->f_path.mnt);
69279+
69280+ if (!gr_tpe_allow(file))
69281+ return 0;
69282+
69283+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69284+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69285+ return 0;
69286+ } else if (unlikely(!(mode & GR_EXEC))) {
69287+ return 0;
69288+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69289+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69290+ return 1;
69291+ }
69292+
69293+ return 1;
69294+}
69295+
69296+void
69297+gr_acl_handle_psacct(struct task_struct *task, const long code)
69298+{
69299+ unsigned long runtime, cputime;
69300+ cputime_t utime, stime;
69301+ unsigned int wday, cday;
69302+ __u8 whr, chr;
69303+ __u8 wmin, cmin;
69304+ __u8 wsec, csec;
69305+ struct timespec timeval;
69306+
69307+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69308+ !(task->acl->mode & GR_PROCACCT)))
69309+ return;
69310+
69311+ do_posix_clock_monotonic_gettime(&timeval);
69312+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69313+ wday = runtime / (60 * 60 * 24);
69314+ runtime -= wday * (60 * 60 * 24);
69315+ whr = runtime / (60 * 60);
69316+ runtime -= whr * (60 * 60);
69317+ wmin = runtime / 60;
69318+ runtime -= wmin * 60;
69319+ wsec = runtime;
69320+
69321+ task_cputime(task, &utime, &stime);
69322+ cputime = cputime_to_secs(utime + stime);
69323+ cday = cputime / (60 * 60 * 24);
69324+ cputime -= cday * (60 * 60 * 24);
69325+ chr = cputime / (60 * 60);
69326+ cputime -= chr * (60 * 60);
69327+ cmin = cputime / 60;
69328+ cputime -= cmin * 60;
69329+ csec = cputime;
69330+
69331+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69332+
69333+ return;
69334+}
69335+
69336+#ifdef CONFIG_TASKSTATS
69337+int gr_is_taskstats_denied(int pid)
69338+{
69339+ struct task_struct *task;
69340+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69341+ const struct cred *cred;
69342+#endif
69343+ int ret = 0;
69344+
69345+ /* restrict taskstats viewing to un-chrooted root users
69346+ who have the 'view' subject flag if the RBAC system is enabled
69347+ */
69348+
69349+ rcu_read_lock();
69350+ read_lock(&tasklist_lock);
69351+ task = find_task_by_vpid(pid);
69352+ if (task) {
69353+#ifdef CONFIG_GRKERNSEC_CHROOT
69354+ if (proc_is_chrooted(task))
69355+ ret = -EACCES;
69356+#endif
69357+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69358+ cred = __task_cred(task);
69359+#ifdef CONFIG_GRKERNSEC_PROC_USER
69360+ if (gr_is_global_nonroot(cred->uid))
69361+ ret = -EACCES;
69362+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69363+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69364+ ret = -EACCES;
69365+#endif
69366+#endif
69367+ if (gr_status & GR_READY) {
69368+ if (!(task->acl->mode & GR_VIEW))
69369+ ret = -EACCES;
69370+ }
69371+ } else
69372+ ret = -ENOENT;
69373+
69374+ read_unlock(&tasklist_lock);
69375+ rcu_read_unlock();
69376+
69377+ return ret;
69378+}
69379+#endif
69380+
69381+/* AUXV entries are filled via a descendant of search_binary_handler
69382+ after we've already applied the subject for the target
69383+*/
69384+int gr_acl_enable_at_secure(void)
69385+{
69386+ if (unlikely(!(gr_status & GR_READY)))
69387+ return 0;
69388+
69389+ if (current->acl->mode & GR_ATSECURE)
69390+ return 1;
69391+
69392+ return 0;
69393+}
69394+
69395+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69396+{
69397+ struct task_struct *task = current;
69398+ struct dentry *dentry = file->f_path.dentry;
69399+ struct vfsmount *mnt = file->f_path.mnt;
69400+ struct acl_object_label *obj, *tmp;
69401+ struct acl_subject_label *subj;
69402+ unsigned int bufsize;
69403+ int is_not_root;
69404+ char *path;
69405+ dev_t dev = __get_dev(dentry);
69406+
69407+ if (unlikely(!(gr_status & GR_READY)))
69408+ return 1;
69409+
69410+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69411+ return 1;
69412+
69413+ /* ignore Eric Biederman */
69414+ if (IS_PRIVATE(dentry->d_inode))
69415+ return 1;
69416+
69417+ subj = task->acl;
69418+ read_lock(&gr_inode_lock);
69419+ do {
69420+ obj = lookup_acl_obj_label(ino, dev, subj);
69421+ if (obj != NULL) {
69422+ read_unlock(&gr_inode_lock);
69423+ return (obj->mode & GR_FIND) ? 1 : 0;
69424+ }
69425+ } while ((subj = subj->parent_subject));
69426+ read_unlock(&gr_inode_lock);
69427+
69428+ /* this is purely an optimization since we're looking for an object
69429+ for the directory we're doing a readdir on
69430+ if it's possible for any globbed object to match the entry we're
69431+ filling into the directory, then the object we find here will be
69432+ an anchor point with attached globbed objects
69433+ */
69434+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69435+ if (obj->globbed == NULL)
69436+ return (obj->mode & GR_FIND) ? 1 : 0;
69437+
69438+ is_not_root = ((obj->filename[0] == '/') &&
69439+ (obj->filename[1] == '\0')) ? 0 : 1;
69440+ bufsize = PAGE_SIZE - namelen - is_not_root;
69441+
69442+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69443+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69444+ return 1;
69445+
69446+ preempt_disable();
69447+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69448+ bufsize);
69449+
69450+ bufsize = strlen(path);
69451+
69452+ /* if base is "/", don't append an additional slash */
69453+ if (is_not_root)
69454+ *(path + bufsize) = '/';
69455+ memcpy(path + bufsize + is_not_root, name, namelen);
69456+ *(path + bufsize + namelen + is_not_root) = '\0';
69457+
69458+ tmp = obj->globbed;
69459+ while (tmp) {
69460+ if (!glob_match(tmp->filename, path)) {
69461+ preempt_enable();
69462+ return (tmp->mode & GR_FIND) ? 1 : 0;
69463+ }
69464+ tmp = tmp->next;
69465+ }
69466+ preempt_enable();
69467+ return (obj->mode & GR_FIND) ? 1 : 0;
69468+}
69469+
69470+void gr_put_exec_file(struct task_struct *task)
69471+{
69472+ struct file *filp;
69473+
69474+ write_lock(&grsec_exec_file_lock);
69475+ filp = task->exec_file;
69476+ task->exec_file = NULL;
69477+ write_unlock(&grsec_exec_file_lock);
69478+
69479+ if (filp)
69480+ fput(filp);
69481+
69482+ return;
69483+}
69484+
69485+
69486+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69487+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69488+#endif
69489+#ifdef CONFIG_SECURITY
69490+EXPORT_SYMBOL_GPL(gr_check_user_change);
69491+EXPORT_SYMBOL_GPL(gr_check_group_change);
69492+#endif
69493+
69494diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69495new file mode 100644
69496index 0000000..18ffbbd
69497--- /dev/null
69498+++ b/grsecurity/gracl_alloc.c
69499@@ -0,0 +1,105 @@
69500+#include <linux/kernel.h>
69501+#include <linux/mm.h>
69502+#include <linux/slab.h>
69503+#include <linux/vmalloc.h>
69504+#include <linux/gracl.h>
69505+#include <linux/grsecurity.h>
69506+
69507+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69508+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69509+
69510+static __inline__ int
69511+alloc_pop(void)
69512+{
69513+ if (current_alloc_state->alloc_stack_next == 1)
69514+ return 0;
69515+
69516+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69517+
69518+ current_alloc_state->alloc_stack_next--;
69519+
69520+ return 1;
69521+}
69522+
69523+static __inline__ int
69524+alloc_push(void *buf)
69525+{
69526+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69527+ return 1;
69528+
69529+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69530+
69531+ current_alloc_state->alloc_stack_next++;
69532+
69533+ return 0;
69534+}
69535+
69536+void *
69537+acl_alloc(unsigned long len)
69538+{
69539+ void *ret = NULL;
69540+
69541+ if (!len || len > PAGE_SIZE)
69542+ goto out;
69543+
69544+ ret = kmalloc(len, GFP_KERNEL);
69545+
69546+ if (ret) {
69547+ if (alloc_push(ret)) {
69548+ kfree(ret);
69549+ ret = NULL;
69550+ }
69551+ }
69552+
69553+out:
69554+ return ret;
69555+}
69556+
69557+void *
69558+acl_alloc_num(unsigned long num, unsigned long len)
69559+{
69560+ if (!len || (num > (PAGE_SIZE / len)))
69561+ return NULL;
69562+
69563+ return acl_alloc(num * len);
69564+}
69565+
69566+void
69567+acl_free_all(void)
69568+{
69569+ if (!current_alloc_state->alloc_stack)
69570+ return;
69571+
69572+ while (alloc_pop()) ;
69573+
69574+ if (current_alloc_state->alloc_stack) {
69575+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69576+ kfree(current_alloc_state->alloc_stack);
69577+ else
69578+ vfree(current_alloc_state->alloc_stack);
69579+ }
69580+
69581+ current_alloc_state->alloc_stack = NULL;
69582+ current_alloc_state->alloc_stack_size = 1;
69583+ current_alloc_state->alloc_stack_next = 1;
69584+
69585+ return;
69586+}
69587+
69588+int
69589+acl_alloc_stack_init(unsigned long size)
69590+{
69591+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69592+ current_alloc_state->alloc_stack =
69593+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69594+ else
69595+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69596+
69597+ current_alloc_state->alloc_stack_size = size;
69598+ current_alloc_state->alloc_stack_next = 1;
69599+
69600+ if (!current_alloc_state->alloc_stack)
69601+ return 0;
69602+ else
69603+ return 1;
69604+}
69605diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69606new file mode 100644
69607index 0000000..bdd51ea
69608--- /dev/null
69609+++ b/grsecurity/gracl_cap.c
69610@@ -0,0 +1,110 @@
69611+#include <linux/kernel.h>
69612+#include <linux/module.h>
69613+#include <linux/sched.h>
69614+#include <linux/gracl.h>
69615+#include <linux/grsecurity.h>
69616+#include <linux/grinternal.h>
69617+
69618+extern const char *captab_log[];
69619+extern int captab_log_entries;
69620+
69621+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69622+{
69623+ struct acl_subject_label *curracl;
69624+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69625+ kernel_cap_t cap_audit = __cap_empty_set;
69626+
69627+ if (!gr_acl_is_enabled())
69628+ return 1;
69629+
69630+ curracl = task->acl;
69631+
69632+ cap_drop = curracl->cap_lower;
69633+ cap_mask = curracl->cap_mask;
69634+ cap_audit = curracl->cap_invert_audit;
69635+
69636+ while ((curracl = curracl->parent_subject)) {
69637+ /* if the cap isn't specified in the current computed mask but is specified in the
69638+ current level subject, and is lowered in the current level subject, then add
69639+ it to the set of dropped capabilities
69640+ otherwise, add the current level subject's mask to the current computed mask
69641+ */
69642+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69643+ cap_raise(cap_mask, cap);
69644+ if (cap_raised(curracl->cap_lower, cap))
69645+ cap_raise(cap_drop, cap);
69646+ if (cap_raised(curracl->cap_invert_audit, cap))
69647+ cap_raise(cap_audit, cap);
69648+ }
69649+ }
69650+
69651+ if (!cap_raised(cap_drop, cap)) {
69652+ if (cap_raised(cap_audit, cap))
69653+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69654+ return 1;
69655+ }
69656+
69657+ curracl = task->acl;
69658+
69659+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69660+ && cap_raised(cred->cap_effective, cap)) {
69661+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69662+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69663+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69664+ gr_to_filename(task->exec_file->f_path.dentry,
69665+ task->exec_file->f_path.mnt) : curracl->filename,
69666+ curracl->filename, 0UL,
69667+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69668+ return 1;
69669+ }
69670+
69671+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69672+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69673+
69674+ return 0;
69675+}
69676+
69677+int
69678+gr_acl_is_capable(const int cap)
69679+{
69680+ return gr_task_acl_is_capable(current, current_cred(), cap);
69681+}
69682+
69683+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69684+{
69685+ struct acl_subject_label *curracl;
69686+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69687+
69688+ if (!gr_acl_is_enabled())
69689+ return 1;
69690+
69691+ curracl = task->acl;
69692+
69693+ cap_drop = curracl->cap_lower;
69694+ cap_mask = curracl->cap_mask;
69695+
69696+ while ((curracl = curracl->parent_subject)) {
69697+ /* if the cap isn't specified in the current computed mask but is specified in the
69698+ current level subject, and is lowered in the current level subject, then add
69699+ it to the set of dropped capabilities
69700+ otherwise, add the current level subject's mask to the current computed mask
69701+ */
69702+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69703+ cap_raise(cap_mask, cap);
69704+ if (cap_raised(curracl->cap_lower, cap))
69705+ cap_raise(cap_drop, cap);
69706+ }
69707+ }
69708+
69709+ if (!cap_raised(cap_drop, cap))
69710+ return 1;
69711+
69712+ return 0;
69713+}
69714+
69715+int
69716+gr_acl_is_capable_nolog(const int cap)
69717+{
69718+ return gr_task_acl_is_capable_nolog(current, cap);
69719+}
69720+
69721diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69722new file mode 100644
69723index 0000000..ca25605
69724--- /dev/null
69725+++ b/grsecurity/gracl_compat.c
69726@@ -0,0 +1,270 @@
69727+#include <linux/kernel.h>
69728+#include <linux/gracl.h>
69729+#include <linux/compat.h>
69730+#include <linux/gracl_compat.h>
69731+
69732+#include <asm/uaccess.h>
69733+
69734+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69735+{
69736+ struct gr_arg_wrapper_compat uwrapcompat;
69737+
69738+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69739+ return -EFAULT;
69740+
69741+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69742+ (uwrapcompat.version != 0x2901)) ||
69743+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69744+ return -EINVAL;
69745+
69746+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69747+ uwrap->version = uwrapcompat.version;
69748+ uwrap->size = sizeof(struct gr_arg);
69749+
69750+ return 0;
69751+}
69752+
69753+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69754+{
69755+ struct gr_arg_compat argcompat;
69756+
69757+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69758+ return -EFAULT;
69759+
69760+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69761+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69762+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69763+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69764+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69765+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69766+
69767+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69768+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69769+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69770+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69771+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69772+ arg->segv_device = argcompat.segv_device;
69773+ arg->segv_inode = argcompat.segv_inode;
69774+ arg->segv_uid = argcompat.segv_uid;
69775+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69776+ arg->mode = argcompat.mode;
69777+
69778+ return 0;
69779+}
69780+
69781+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69782+{
69783+ struct acl_object_label_compat objcompat;
69784+
69785+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69786+ return -EFAULT;
69787+
69788+ obj->filename = compat_ptr(objcompat.filename);
69789+ obj->inode = objcompat.inode;
69790+ obj->device = objcompat.device;
69791+ obj->mode = objcompat.mode;
69792+
69793+ obj->nested = compat_ptr(objcompat.nested);
69794+ obj->globbed = compat_ptr(objcompat.globbed);
69795+
69796+ obj->prev = compat_ptr(objcompat.prev);
69797+ obj->next = compat_ptr(objcompat.next);
69798+
69799+ return 0;
69800+}
69801+
69802+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69803+{
69804+ unsigned int i;
69805+ struct acl_subject_label_compat subjcompat;
69806+
69807+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69808+ return -EFAULT;
69809+
69810+ subj->filename = compat_ptr(subjcompat.filename);
69811+ subj->inode = subjcompat.inode;
69812+ subj->device = subjcompat.device;
69813+ subj->mode = subjcompat.mode;
69814+ subj->cap_mask = subjcompat.cap_mask;
69815+ subj->cap_lower = subjcompat.cap_lower;
69816+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69817+
69818+ for (i = 0; i < GR_NLIMITS; i++) {
69819+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69820+ subj->res[i].rlim_cur = RLIM_INFINITY;
69821+ else
69822+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69823+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69824+ subj->res[i].rlim_max = RLIM_INFINITY;
69825+ else
69826+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69827+ }
69828+ subj->resmask = subjcompat.resmask;
69829+
69830+ subj->user_trans_type = subjcompat.user_trans_type;
69831+ subj->group_trans_type = subjcompat.group_trans_type;
69832+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69833+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69834+ subj->user_trans_num = subjcompat.user_trans_num;
69835+ subj->group_trans_num = subjcompat.group_trans_num;
69836+
69837+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69838+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69839+ subj->ip_type = subjcompat.ip_type;
69840+ subj->ips = compat_ptr(subjcompat.ips);
69841+ subj->ip_num = subjcompat.ip_num;
69842+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69843+
69844+ subj->crashes = subjcompat.crashes;
69845+ subj->expires = subjcompat.expires;
69846+
69847+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69848+ subj->hash = compat_ptr(subjcompat.hash);
69849+ subj->prev = compat_ptr(subjcompat.prev);
69850+ subj->next = compat_ptr(subjcompat.next);
69851+
69852+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69853+ subj->obj_hash_size = subjcompat.obj_hash_size;
69854+ subj->pax_flags = subjcompat.pax_flags;
69855+
69856+ return 0;
69857+}
69858+
69859+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69860+{
69861+ struct acl_role_label_compat rolecompat;
69862+
69863+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69864+ return -EFAULT;
69865+
69866+ role->rolename = compat_ptr(rolecompat.rolename);
69867+ role->uidgid = rolecompat.uidgid;
69868+ role->roletype = rolecompat.roletype;
69869+
69870+ role->auth_attempts = rolecompat.auth_attempts;
69871+ role->expires = rolecompat.expires;
69872+
69873+ role->root_label = compat_ptr(rolecompat.root_label);
69874+ role->hash = compat_ptr(rolecompat.hash);
69875+
69876+ role->prev = compat_ptr(rolecompat.prev);
69877+ role->next = compat_ptr(rolecompat.next);
69878+
69879+ role->transitions = compat_ptr(rolecompat.transitions);
69880+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69881+ role->domain_children = compat_ptr(rolecompat.domain_children);
69882+ role->domain_child_num = rolecompat.domain_child_num;
69883+
69884+ role->umask = rolecompat.umask;
69885+
69886+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69887+ role->subj_hash_size = rolecompat.subj_hash_size;
69888+
69889+ return 0;
69890+}
69891+
69892+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69893+{
69894+ struct role_allowed_ip_compat roleip_compat;
69895+
69896+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69897+ return -EFAULT;
69898+
69899+ roleip->addr = roleip_compat.addr;
69900+ roleip->netmask = roleip_compat.netmask;
69901+
69902+ roleip->prev = compat_ptr(roleip_compat.prev);
69903+ roleip->next = compat_ptr(roleip_compat.next);
69904+
69905+ return 0;
69906+}
69907+
69908+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69909+{
69910+ struct role_transition_compat trans_compat;
69911+
69912+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69913+ return -EFAULT;
69914+
69915+ trans->rolename = compat_ptr(trans_compat.rolename);
69916+
69917+ trans->prev = compat_ptr(trans_compat.prev);
69918+ trans->next = compat_ptr(trans_compat.next);
69919+
69920+ return 0;
69921+
69922+}
69923+
69924+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69925+{
69926+ struct gr_hash_struct_compat hash_compat;
69927+
69928+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69929+ return -EFAULT;
69930+
69931+ hash->table = compat_ptr(hash_compat.table);
69932+ hash->nametable = compat_ptr(hash_compat.nametable);
69933+ hash->first = compat_ptr(hash_compat.first);
69934+
69935+ hash->table_size = hash_compat.table_size;
69936+ hash->used_size = hash_compat.used_size;
69937+
69938+ hash->type = hash_compat.type;
69939+
69940+ return 0;
69941+}
69942+
69943+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69944+{
69945+ compat_uptr_t ptrcompat;
69946+
69947+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69948+ return -EFAULT;
69949+
69950+ *(void **)ptr = compat_ptr(ptrcompat);
69951+
69952+ return 0;
69953+}
69954+
69955+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69956+{
69957+ struct acl_ip_label_compat ip_compat;
69958+
69959+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69960+ return -EFAULT;
69961+
69962+ ip->iface = compat_ptr(ip_compat.iface);
69963+ ip->addr = ip_compat.addr;
69964+ ip->netmask = ip_compat.netmask;
69965+ ip->low = ip_compat.low;
69966+ ip->high = ip_compat.high;
69967+ ip->mode = ip_compat.mode;
69968+ ip->type = ip_compat.type;
69969+
69970+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69971+
69972+ ip->prev = compat_ptr(ip_compat.prev);
69973+ ip->next = compat_ptr(ip_compat.next);
69974+
69975+ return 0;
69976+}
69977+
69978+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69979+{
69980+ struct sprole_pw_compat pw_compat;
69981+
69982+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69983+ return -EFAULT;
69984+
69985+ pw->rolename = compat_ptr(pw_compat.rolename);
69986+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69987+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69988+
69989+ return 0;
69990+}
69991+
69992+size_t get_gr_arg_wrapper_size_compat(void)
69993+{
69994+ return sizeof(struct gr_arg_wrapper_compat);
69995+}
69996+
69997diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69998new file mode 100644
69999index 0000000..a89b1f4
70000--- /dev/null
70001+++ b/grsecurity/gracl_fs.c
70002@@ -0,0 +1,437 @@
70003+#include <linux/kernel.h>
70004+#include <linux/sched.h>
70005+#include <linux/types.h>
70006+#include <linux/fs.h>
70007+#include <linux/file.h>
70008+#include <linux/stat.h>
70009+#include <linux/grsecurity.h>
70010+#include <linux/grinternal.h>
70011+#include <linux/gracl.h>
70012+
70013+umode_t
70014+gr_acl_umask(void)
70015+{
70016+ if (unlikely(!gr_acl_is_enabled()))
70017+ return 0;
70018+
70019+ return current->role->umask;
70020+}
70021+
70022+__u32
70023+gr_acl_handle_hidden_file(const struct dentry * dentry,
70024+ const struct vfsmount * mnt)
70025+{
70026+ __u32 mode;
70027+
70028+ if (unlikely(d_is_negative(dentry)))
70029+ return GR_FIND;
70030+
70031+ mode =
70032+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70033+
70034+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70035+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70036+ return mode;
70037+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70038+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70039+ return 0;
70040+ } else if (unlikely(!(mode & GR_FIND)))
70041+ return 0;
70042+
70043+ return GR_FIND;
70044+}
70045+
70046+__u32
70047+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70048+ int acc_mode)
70049+{
70050+ __u32 reqmode = GR_FIND;
70051+ __u32 mode;
70052+
70053+ if (unlikely(d_is_negative(dentry)))
70054+ return reqmode;
70055+
70056+ if (acc_mode & MAY_APPEND)
70057+ reqmode |= GR_APPEND;
70058+ else if (acc_mode & MAY_WRITE)
70059+ reqmode |= GR_WRITE;
70060+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70061+ reqmode |= GR_READ;
70062+
70063+ mode =
70064+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70065+ mnt);
70066+
70067+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70068+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70069+ reqmode & GR_READ ? " reading" : "",
70070+ reqmode & GR_WRITE ? " writing" : reqmode &
70071+ GR_APPEND ? " appending" : "");
70072+ return reqmode;
70073+ } else
70074+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70075+ {
70076+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70077+ reqmode & GR_READ ? " reading" : "",
70078+ reqmode & GR_WRITE ? " writing" : reqmode &
70079+ GR_APPEND ? " appending" : "");
70080+ return 0;
70081+ } else if (unlikely((mode & reqmode) != reqmode))
70082+ return 0;
70083+
70084+ return reqmode;
70085+}
70086+
70087+__u32
70088+gr_acl_handle_creat(const struct dentry * dentry,
70089+ const struct dentry * p_dentry,
70090+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70091+ const int imode)
70092+{
70093+ __u32 reqmode = GR_WRITE | GR_CREATE;
70094+ __u32 mode;
70095+
70096+ if (acc_mode & MAY_APPEND)
70097+ reqmode |= GR_APPEND;
70098+ // if a directory was required or the directory already exists, then
70099+ // don't count this open as a read
70100+ if ((acc_mode & MAY_READ) &&
70101+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70102+ reqmode |= GR_READ;
70103+ if ((open_flags & O_CREAT) &&
70104+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70105+ reqmode |= GR_SETID;
70106+
70107+ mode =
70108+ gr_check_create(dentry, p_dentry, p_mnt,
70109+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70110+
70111+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70112+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70113+ reqmode & GR_READ ? " reading" : "",
70114+ reqmode & GR_WRITE ? " writing" : reqmode &
70115+ GR_APPEND ? " appending" : "");
70116+ return reqmode;
70117+ } else
70118+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70119+ {
70120+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70121+ reqmode & GR_READ ? " reading" : "",
70122+ reqmode & GR_WRITE ? " writing" : reqmode &
70123+ GR_APPEND ? " appending" : "");
70124+ return 0;
70125+ } else if (unlikely((mode & reqmode) != reqmode))
70126+ return 0;
70127+
70128+ return reqmode;
70129+}
70130+
70131+__u32
70132+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70133+ const int fmode)
70134+{
70135+ __u32 mode, reqmode = GR_FIND;
70136+
70137+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70138+ reqmode |= GR_EXEC;
70139+ if (fmode & S_IWOTH)
70140+ reqmode |= GR_WRITE;
70141+ if (fmode & S_IROTH)
70142+ reqmode |= GR_READ;
70143+
70144+ mode =
70145+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70146+ mnt);
70147+
70148+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70149+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70150+ reqmode & GR_READ ? " reading" : "",
70151+ reqmode & GR_WRITE ? " writing" : "",
70152+ reqmode & GR_EXEC ? " executing" : "");
70153+ return reqmode;
70154+ } else
70155+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70156+ {
70157+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70158+ reqmode & GR_READ ? " reading" : "",
70159+ reqmode & GR_WRITE ? " writing" : "",
70160+ reqmode & GR_EXEC ? " executing" : "");
70161+ return 0;
70162+ } else if (unlikely((mode & reqmode) != reqmode))
70163+ return 0;
70164+
70165+ return reqmode;
70166+}
70167+
70168+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70169+{
70170+ __u32 mode;
70171+
70172+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70173+
70174+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70175+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70176+ return mode;
70177+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70178+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70179+ return 0;
70180+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70181+ return 0;
70182+
70183+ return (reqmode);
70184+}
70185+
70186+__u32
70187+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70188+{
70189+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70190+}
70191+
70192+__u32
70193+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70194+{
70195+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70196+}
70197+
70198+__u32
70199+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70200+{
70201+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70202+}
70203+
70204+__u32
70205+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70206+{
70207+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70208+}
70209+
70210+__u32
70211+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70212+ umode_t *modeptr)
70213+{
70214+ umode_t mode;
70215+
70216+ *modeptr &= ~gr_acl_umask();
70217+ mode = *modeptr;
70218+
70219+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70220+ return 1;
70221+
70222+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70223+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70224+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70225+ GR_CHMOD_ACL_MSG);
70226+ } else {
70227+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70228+ }
70229+}
70230+
70231+__u32
70232+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70233+{
70234+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70235+}
70236+
70237+__u32
70238+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70239+{
70240+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70241+}
70242+
70243+__u32
70244+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70245+{
70246+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70247+}
70248+
70249+__u32
70250+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70251+{
70252+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70253+}
70254+
70255+__u32
70256+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70257+{
70258+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70259+ GR_UNIXCONNECT_ACL_MSG);
70260+}
70261+
70262+/* hardlinks require at minimum create and link permission,
70263+ any additional privilege required is based on the
70264+ privilege of the file being linked to
70265+*/
70266+__u32
70267+gr_acl_handle_link(const struct dentry * new_dentry,
70268+ const struct dentry * parent_dentry,
70269+ const struct vfsmount * parent_mnt,
70270+ const struct dentry * old_dentry,
70271+ const struct vfsmount * old_mnt, const struct filename *to)
70272+{
70273+ __u32 mode;
70274+ __u32 needmode = GR_CREATE | GR_LINK;
70275+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70276+
70277+ mode =
70278+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70279+ old_mnt);
70280+
70281+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70282+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70283+ return mode;
70284+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70285+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70286+ return 0;
70287+ } else if (unlikely((mode & needmode) != needmode))
70288+ return 0;
70289+
70290+ return 1;
70291+}
70292+
70293+__u32
70294+gr_acl_handle_symlink(const struct dentry * new_dentry,
70295+ const struct dentry * parent_dentry,
70296+ const struct vfsmount * parent_mnt, const struct filename *from)
70297+{
70298+ __u32 needmode = GR_WRITE | GR_CREATE;
70299+ __u32 mode;
70300+
70301+ mode =
70302+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70303+ GR_CREATE | GR_AUDIT_CREATE |
70304+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70305+
70306+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70307+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70308+ return mode;
70309+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70310+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70311+ return 0;
70312+ } else if (unlikely((mode & needmode) != needmode))
70313+ return 0;
70314+
70315+ return (GR_WRITE | GR_CREATE);
70316+}
70317+
70318+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)
70319+{
70320+ __u32 mode;
70321+
70322+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70323+
70324+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70325+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70326+ return mode;
70327+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70328+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70329+ return 0;
70330+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70331+ return 0;
70332+
70333+ return (reqmode);
70334+}
70335+
70336+__u32
70337+gr_acl_handle_mknod(const struct dentry * new_dentry,
70338+ const struct dentry * parent_dentry,
70339+ const struct vfsmount * parent_mnt,
70340+ const int mode)
70341+{
70342+ __u32 reqmode = GR_WRITE | GR_CREATE;
70343+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70344+ reqmode |= GR_SETID;
70345+
70346+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70347+ reqmode, GR_MKNOD_ACL_MSG);
70348+}
70349+
70350+__u32
70351+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70352+ const struct dentry *parent_dentry,
70353+ const struct vfsmount *parent_mnt)
70354+{
70355+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70356+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70357+}
70358+
70359+#define RENAME_CHECK_SUCCESS(old, new) \
70360+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70361+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70362+
70363+int
70364+gr_acl_handle_rename(struct dentry *new_dentry,
70365+ struct dentry *parent_dentry,
70366+ const struct vfsmount *parent_mnt,
70367+ struct dentry *old_dentry,
70368+ struct inode *old_parent_inode,
70369+ struct vfsmount *old_mnt, const struct filename *newname)
70370+{
70371+ __u32 comp1, comp2;
70372+ int error = 0;
70373+
70374+ if (unlikely(!gr_acl_is_enabled()))
70375+ return 0;
70376+
70377+ if (d_is_negative(new_dentry)) {
70378+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70379+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70380+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70381+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70382+ GR_DELETE | GR_AUDIT_DELETE |
70383+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70384+ GR_SUPPRESS, old_mnt);
70385+ } else {
70386+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70387+ GR_CREATE | GR_DELETE |
70388+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70389+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70390+ GR_SUPPRESS, parent_mnt);
70391+ comp2 =
70392+ gr_search_file(old_dentry,
70393+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70394+ GR_DELETE | GR_AUDIT_DELETE |
70395+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70396+ }
70397+
70398+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70399+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70400+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70401+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70402+ && !(comp2 & GR_SUPPRESS)) {
70403+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70404+ error = -EACCES;
70405+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70406+ error = -EACCES;
70407+
70408+ return error;
70409+}
70410+
70411+void
70412+gr_acl_handle_exit(void)
70413+{
70414+ u16 id;
70415+ char *rolename;
70416+
70417+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70418+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70419+ id = current->acl_role_id;
70420+ rolename = current->role->rolename;
70421+ gr_set_acls(1);
70422+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70423+ }
70424+
70425+ gr_put_exec_file(current);
70426+ return;
70427+}
70428+
70429+int
70430+gr_acl_handle_procpidmem(const struct task_struct *task)
70431+{
70432+ if (unlikely(!gr_acl_is_enabled()))
70433+ return 0;
70434+
70435+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70436+ return -EACCES;
70437+
70438+ return 0;
70439+}
70440diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70441new file mode 100644
70442index 0000000..f056b81
70443--- /dev/null
70444+++ b/grsecurity/gracl_ip.c
70445@@ -0,0 +1,386 @@
70446+#include <linux/kernel.h>
70447+#include <asm/uaccess.h>
70448+#include <asm/errno.h>
70449+#include <net/sock.h>
70450+#include <linux/file.h>
70451+#include <linux/fs.h>
70452+#include <linux/net.h>
70453+#include <linux/in.h>
70454+#include <linux/skbuff.h>
70455+#include <linux/ip.h>
70456+#include <linux/udp.h>
70457+#include <linux/types.h>
70458+#include <linux/sched.h>
70459+#include <linux/netdevice.h>
70460+#include <linux/inetdevice.h>
70461+#include <linux/gracl.h>
70462+#include <linux/grsecurity.h>
70463+#include <linux/grinternal.h>
70464+
70465+#define GR_BIND 0x01
70466+#define GR_CONNECT 0x02
70467+#define GR_INVERT 0x04
70468+#define GR_BINDOVERRIDE 0x08
70469+#define GR_CONNECTOVERRIDE 0x10
70470+#define GR_SOCK_FAMILY 0x20
70471+
70472+static const char * gr_protocols[IPPROTO_MAX] = {
70473+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70474+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70475+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70476+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70477+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70478+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70479+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70480+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70481+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70482+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70483+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70484+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70485+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70486+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70487+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70488+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70489+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70490+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70491+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70492+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70493+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70494+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70495+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70496+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70497+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70498+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70499+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70500+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70501+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70502+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70503+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70504+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70505+ };
70506+
70507+static const char * gr_socktypes[SOCK_MAX] = {
70508+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70509+ "unknown:7", "unknown:8", "unknown:9", "packet"
70510+ };
70511+
70512+static const char * gr_sockfamilies[AF_MAX+1] = {
70513+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70514+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70515+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70516+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70517+ };
70518+
70519+const char *
70520+gr_proto_to_name(unsigned char proto)
70521+{
70522+ return gr_protocols[proto];
70523+}
70524+
70525+const char *
70526+gr_socktype_to_name(unsigned char type)
70527+{
70528+ return gr_socktypes[type];
70529+}
70530+
70531+const char *
70532+gr_sockfamily_to_name(unsigned char family)
70533+{
70534+ return gr_sockfamilies[family];
70535+}
70536+
70537+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70538+
70539+int
70540+gr_search_socket(const int domain, const int type, const int protocol)
70541+{
70542+ struct acl_subject_label *curr;
70543+ const struct cred *cred = current_cred();
70544+
70545+ if (unlikely(!gr_acl_is_enabled()))
70546+ goto exit;
70547+
70548+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70549+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70550+ goto exit; // let the kernel handle it
70551+
70552+ curr = current->acl;
70553+
70554+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70555+ /* the family is allowed, if this is PF_INET allow it only if
70556+ the extra sock type/protocol checks pass */
70557+ if (domain == PF_INET)
70558+ goto inet_check;
70559+ goto exit;
70560+ } else {
70561+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70562+ __u32 fakeip = 0;
70563+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70564+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70565+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70566+ gr_to_filename(current->exec_file->f_path.dentry,
70567+ current->exec_file->f_path.mnt) :
70568+ curr->filename, curr->filename,
70569+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70570+ &current->signal->saved_ip);
70571+ goto exit;
70572+ }
70573+ goto exit_fail;
70574+ }
70575+
70576+inet_check:
70577+ /* the rest of this checking is for IPv4 only */
70578+ if (!curr->ips)
70579+ goto exit;
70580+
70581+ if ((curr->ip_type & (1U << type)) &&
70582+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70583+ goto exit;
70584+
70585+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70586+ /* we don't place acls on raw sockets , and sometimes
70587+ dgram/ip sockets are opened for ioctl and not
70588+ bind/connect, so we'll fake a bind learn log */
70589+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70590+ __u32 fakeip = 0;
70591+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70592+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70593+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70594+ gr_to_filename(current->exec_file->f_path.dentry,
70595+ current->exec_file->f_path.mnt) :
70596+ curr->filename, curr->filename,
70597+ &fakeip, 0, type,
70598+ protocol, GR_CONNECT, &current->signal->saved_ip);
70599+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70600+ __u32 fakeip = 0;
70601+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70602+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70603+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70604+ gr_to_filename(current->exec_file->f_path.dentry,
70605+ current->exec_file->f_path.mnt) :
70606+ curr->filename, curr->filename,
70607+ &fakeip, 0, type,
70608+ protocol, GR_BIND, &current->signal->saved_ip);
70609+ }
70610+ /* we'll log when they use connect or bind */
70611+ goto exit;
70612+ }
70613+
70614+exit_fail:
70615+ if (domain == PF_INET)
70616+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70617+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70618+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70619+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70620+ gr_socktype_to_name(type), protocol);
70621+
70622+ return 0;
70623+exit:
70624+ return 1;
70625+}
70626+
70627+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)
70628+{
70629+ if ((ip->mode & mode) &&
70630+ (ip_port >= ip->low) &&
70631+ (ip_port <= ip->high) &&
70632+ ((ntohl(ip_addr) & our_netmask) ==
70633+ (ntohl(our_addr) & our_netmask))
70634+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70635+ && (ip->type & (1U << type))) {
70636+ if (ip->mode & GR_INVERT)
70637+ return 2; // specifically denied
70638+ else
70639+ return 1; // allowed
70640+ }
70641+
70642+ return 0; // not specifically allowed, may continue parsing
70643+}
70644+
70645+static int
70646+gr_search_connectbind(const int full_mode, struct sock *sk,
70647+ struct sockaddr_in *addr, const int type)
70648+{
70649+ char iface[IFNAMSIZ] = {0};
70650+ struct acl_subject_label *curr;
70651+ struct acl_ip_label *ip;
70652+ struct inet_sock *isk;
70653+ struct net_device *dev;
70654+ struct in_device *idev;
70655+ unsigned long i;
70656+ int ret;
70657+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70658+ __u32 ip_addr = 0;
70659+ __u32 our_addr;
70660+ __u32 our_netmask;
70661+ char *p;
70662+ __u16 ip_port = 0;
70663+ const struct cred *cred = current_cred();
70664+
70665+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70666+ return 0;
70667+
70668+ curr = current->acl;
70669+ isk = inet_sk(sk);
70670+
70671+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70672+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70673+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70674+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70675+ struct sockaddr_in saddr;
70676+ int err;
70677+
70678+ saddr.sin_family = AF_INET;
70679+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70680+ saddr.sin_port = isk->inet_sport;
70681+
70682+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70683+ if (err)
70684+ return err;
70685+
70686+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70687+ if (err)
70688+ return err;
70689+ }
70690+
70691+ if (!curr->ips)
70692+ return 0;
70693+
70694+ ip_addr = addr->sin_addr.s_addr;
70695+ ip_port = ntohs(addr->sin_port);
70696+
70697+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70698+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70699+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70700+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70701+ gr_to_filename(current->exec_file->f_path.dentry,
70702+ current->exec_file->f_path.mnt) :
70703+ curr->filename, curr->filename,
70704+ &ip_addr, ip_port, type,
70705+ sk->sk_protocol, mode, &current->signal->saved_ip);
70706+ return 0;
70707+ }
70708+
70709+ for (i = 0; i < curr->ip_num; i++) {
70710+ ip = *(curr->ips + i);
70711+ if (ip->iface != NULL) {
70712+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70713+ p = strchr(iface, ':');
70714+ if (p != NULL)
70715+ *p = '\0';
70716+ dev = dev_get_by_name(sock_net(sk), iface);
70717+ if (dev == NULL)
70718+ continue;
70719+ idev = in_dev_get(dev);
70720+ if (idev == NULL) {
70721+ dev_put(dev);
70722+ continue;
70723+ }
70724+ rcu_read_lock();
70725+ for_ifa(idev) {
70726+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70727+ our_addr = ifa->ifa_address;
70728+ our_netmask = 0xffffffff;
70729+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70730+ if (ret == 1) {
70731+ rcu_read_unlock();
70732+ in_dev_put(idev);
70733+ dev_put(dev);
70734+ return 0;
70735+ } else if (ret == 2) {
70736+ rcu_read_unlock();
70737+ in_dev_put(idev);
70738+ dev_put(dev);
70739+ goto denied;
70740+ }
70741+ }
70742+ } endfor_ifa(idev);
70743+ rcu_read_unlock();
70744+ in_dev_put(idev);
70745+ dev_put(dev);
70746+ } else {
70747+ our_addr = ip->addr;
70748+ our_netmask = ip->netmask;
70749+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70750+ if (ret == 1)
70751+ return 0;
70752+ else if (ret == 2)
70753+ goto denied;
70754+ }
70755+ }
70756+
70757+denied:
70758+ if (mode == GR_BIND)
70759+ 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));
70760+ else if (mode == GR_CONNECT)
70761+ 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));
70762+
70763+ return -EACCES;
70764+}
70765+
70766+int
70767+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70768+{
70769+ /* always allow disconnection of dgram sockets with connect */
70770+ if (addr->sin_family == AF_UNSPEC)
70771+ return 0;
70772+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70773+}
70774+
70775+int
70776+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70777+{
70778+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70779+}
70780+
70781+int gr_search_listen(struct socket *sock)
70782+{
70783+ struct sock *sk = sock->sk;
70784+ struct sockaddr_in addr;
70785+
70786+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70787+ addr.sin_port = inet_sk(sk)->inet_sport;
70788+
70789+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70790+}
70791+
70792+int gr_search_accept(struct socket *sock)
70793+{
70794+ struct sock *sk = sock->sk;
70795+ struct sockaddr_in addr;
70796+
70797+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70798+ addr.sin_port = inet_sk(sk)->inet_sport;
70799+
70800+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70801+}
70802+
70803+int
70804+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70805+{
70806+ if (addr)
70807+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70808+ else {
70809+ struct sockaddr_in sin;
70810+ const struct inet_sock *inet = inet_sk(sk);
70811+
70812+ sin.sin_addr.s_addr = inet->inet_daddr;
70813+ sin.sin_port = inet->inet_dport;
70814+
70815+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70816+ }
70817+}
70818+
70819+int
70820+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70821+{
70822+ struct sockaddr_in sin;
70823+
70824+ if (unlikely(skb->len < sizeof (struct udphdr)))
70825+ return 0; // skip this packet
70826+
70827+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70828+ sin.sin_port = udp_hdr(skb)->source;
70829+
70830+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70831+}
70832diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70833new file mode 100644
70834index 0000000..25f54ef
70835--- /dev/null
70836+++ b/grsecurity/gracl_learn.c
70837@@ -0,0 +1,207 @@
70838+#include <linux/kernel.h>
70839+#include <linux/mm.h>
70840+#include <linux/sched.h>
70841+#include <linux/poll.h>
70842+#include <linux/string.h>
70843+#include <linux/file.h>
70844+#include <linux/types.h>
70845+#include <linux/vmalloc.h>
70846+#include <linux/grinternal.h>
70847+
70848+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70849+ size_t count, loff_t *ppos);
70850+extern int gr_acl_is_enabled(void);
70851+
70852+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70853+static int gr_learn_attached;
70854+
70855+/* use a 512k buffer */
70856+#define LEARN_BUFFER_SIZE (512 * 1024)
70857+
70858+static DEFINE_SPINLOCK(gr_learn_lock);
70859+static DEFINE_MUTEX(gr_learn_user_mutex);
70860+
70861+/* we need to maintain two buffers, so that the kernel context of grlearn
70862+ uses a semaphore around the userspace copying, and the other kernel contexts
70863+ use a spinlock when copying into the buffer, since they cannot sleep
70864+*/
70865+static char *learn_buffer;
70866+static char *learn_buffer_user;
70867+static int learn_buffer_len;
70868+static int learn_buffer_user_len;
70869+
70870+static ssize_t
70871+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70872+{
70873+ DECLARE_WAITQUEUE(wait, current);
70874+ ssize_t retval = 0;
70875+
70876+ add_wait_queue(&learn_wait, &wait);
70877+ set_current_state(TASK_INTERRUPTIBLE);
70878+ do {
70879+ mutex_lock(&gr_learn_user_mutex);
70880+ spin_lock(&gr_learn_lock);
70881+ if (learn_buffer_len)
70882+ break;
70883+ spin_unlock(&gr_learn_lock);
70884+ mutex_unlock(&gr_learn_user_mutex);
70885+ if (file->f_flags & O_NONBLOCK) {
70886+ retval = -EAGAIN;
70887+ goto out;
70888+ }
70889+ if (signal_pending(current)) {
70890+ retval = -ERESTARTSYS;
70891+ goto out;
70892+ }
70893+
70894+ schedule();
70895+ } while (1);
70896+
70897+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70898+ learn_buffer_user_len = learn_buffer_len;
70899+ retval = learn_buffer_len;
70900+ learn_buffer_len = 0;
70901+
70902+ spin_unlock(&gr_learn_lock);
70903+
70904+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70905+ retval = -EFAULT;
70906+
70907+ mutex_unlock(&gr_learn_user_mutex);
70908+out:
70909+ set_current_state(TASK_RUNNING);
70910+ remove_wait_queue(&learn_wait, &wait);
70911+ return retval;
70912+}
70913+
70914+static unsigned int
70915+poll_learn(struct file * file, poll_table * wait)
70916+{
70917+ poll_wait(file, &learn_wait, wait);
70918+
70919+ if (learn_buffer_len)
70920+ return (POLLIN | POLLRDNORM);
70921+
70922+ return 0;
70923+}
70924+
70925+void
70926+gr_clear_learn_entries(void)
70927+{
70928+ char *tmp;
70929+
70930+ mutex_lock(&gr_learn_user_mutex);
70931+ spin_lock(&gr_learn_lock);
70932+ tmp = learn_buffer;
70933+ learn_buffer = NULL;
70934+ spin_unlock(&gr_learn_lock);
70935+ if (tmp)
70936+ vfree(tmp);
70937+ if (learn_buffer_user != NULL) {
70938+ vfree(learn_buffer_user);
70939+ learn_buffer_user = NULL;
70940+ }
70941+ learn_buffer_len = 0;
70942+ mutex_unlock(&gr_learn_user_mutex);
70943+
70944+ return;
70945+}
70946+
70947+void
70948+gr_add_learn_entry(const char *fmt, ...)
70949+{
70950+ va_list args;
70951+ unsigned int len;
70952+
70953+ if (!gr_learn_attached)
70954+ return;
70955+
70956+ spin_lock(&gr_learn_lock);
70957+
70958+ /* leave a gap at the end so we know when it's "full" but don't have to
70959+ compute the exact length of the string we're trying to append
70960+ */
70961+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70962+ spin_unlock(&gr_learn_lock);
70963+ wake_up_interruptible(&learn_wait);
70964+ return;
70965+ }
70966+ if (learn_buffer == NULL) {
70967+ spin_unlock(&gr_learn_lock);
70968+ return;
70969+ }
70970+
70971+ va_start(args, fmt);
70972+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70973+ va_end(args);
70974+
70975+ learn_buffer_len += len + 1;
70976+
70977+ spin_unlock(&gr_learn_lock);
70978+ wake_up_interruptible(&learn_wait);
70979+
70980+ return;
70981+}
70982+
70983+static int
70984+open_learn(struct inode *inode, struct file *file)
70985+{
70986+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70987+ return -EBUSY;
70988+ if (file->f_mode & FMODE_READ) {
70989+ int retval = 0;
70990+ mutex_lock(&gr_learn_user_mutex);
70991+ if (learn_buffer == NULL)
70992+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70993+ if (learn_buffer_user == NULL)
70994+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70995+ if (learn_buffer == NULL) {
70996+ retval = -ENOMEM;
70997+ goto out_error;
70998+ }
70999+ if (learn_buffer_user == NULL) {
71000+ retval = -ENOMEM;
71001+ goto out_error;
71002+ }
71003+ learn_buffer_len = 0;
71004+ learn_buffer_user_len = 0;
71005+ gr_learn_attached = 1;
71006+out_error:
71007+ mutex_unlock(&gr_learn_user_mutex);
71008+ return retval;
71009+ }
71010+ return 0;
71011+}
71012+
71013+static int
71014+close_learn(struct inode *inode, struct file *file)
71015+{
71016+ if (file->f_mode & FMODE_READ) {
71017+ char *tmp = NULL;
71018+ mutex_lock(&gr_learn_user_mutex);
71019+ spin_lock(&gr_learn_lock);
71020+ tmp = learn_buffer;
71021+ learn_buffer = NULL;
71022+ spin_unlock(&gr_learn_lock);
71023+ if (tmp)
71024+ vfree(tmp);
71025+ if (learn_buffer_user != NULL) {
71026+ vfree(learn_buffer_user);
71027+ learn_buffer_user = NULL;
71028+ }
71029+ learn_buffer_len = 0;
71030+ learn_buffer_user_len = 0;
71031+ gr_learn_attached = 0;
71032+ mutex_unlock(&gr_learn_user_mutex);
71033+ }
71034+
71035+ return 0;
71036+}
71037+
71038+const struct file_operations grsec_fops = {
71039+ .read = read_learn,
71040+ .write = write_grsec_handler,
71041+ .open = open_learn,
71042+ .release = close_learn,
71043+ .poll = poll_learn,
71044+};
71045diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71046new file mode 100644
71047index 0000000..361a099
71048--- /dev/null
71049+++ b/grsecurity/gracl_policy.c
71050@@ -0,0 +1,1782 @@
71051+#include <linux/kernel.h>
71052+#include <linux/module.h>
71053+#include <linux/sched.h>
71054+#include <linux/mm.h>
71055+#include <linux/file.h>
71056+#include <linux/fs.h>
71057+#include <linux/namei.h>
71058+#include <linux/mount.h>
71059+#include <linux/tty.h>
71060+#include <linux/proc_fs.h>
71061+#include <linux/lglock.h>
71062+#include <linux/slab.h>
71063+#include <linux/vmalloc.h>
71064+#include <linux/types.h>
71065+#include <linux/sysctl.h>
71066+#include <linux/netdevice.h>
71067+#include <linux/ptrace.h>
71068+#include <linux/gracl.h>
71069+#include <linux/gralloc.h>
71070+#include <linux/security.h>
71071+#include <linux/grinternal.h>
71072+#include <linux/pid_namespace.h>
71073+#include <linux/stop_machine.h>
71074+#include <linux/fdtable.h>
71075+#include <linux/percpu.h>
71076+#include <linux/lglock.h>
71077+#include <linux/hugetlb.h>
71078+#include <linux/posix-timers.h>
71079+#include "../fs/mount.h"
71080+
71081+#include <asm/uaccess.h>
71082+#include <asm/errno.h>
71083+#include <asm/mman.h>
71084+
71085+extern struct gr_policy_state *polstate;
71086+
71087+#define FOR_EACH_ROLE_START(role) \
71088+ role = polstate->role_list; \
71089+ while (role) {
71090+
71091+#define FOR_EACH_ROLE_END(role) \
71092+ role = role->prev; \
71093+ }
71094+
71095+struct path gr_real_root;
71096+
71097+extern struct gr_alloc_state *current_alloc_state;
71098+
71099+u16 acl_sp_role_value;
71100+
71101+static DEFINE_MUTEX(gr_dev_mutex);
71102+
71103+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71104+extern void gr_clear_learn_entries(void);
71105+
71106+static struct gr_arg gr_usermode;
71107+static unsigned char gr_system_salt[GR_SALT_LEN];
71108+static unsigned char gr_system_sum[GR_SHA_LEN];
71109+
71110+static unsigned int gr_auth_attempts = 0;
71111+static unsigned long gr_auth_expires = 0UL;
71112+
71113+struct acl_object_label *fakefs_obj_rw;
71114+struct acl_object_label *fakefs_obj_rwx;
71115+
71116+extern int gr_init_uidset(void);
71117+extern void gr_free_uidset(void);
71118+extern void gr_remove_uid(uid_t uid);
71119+extern int gr_find_uid(uid_t uid);
71120+
71121+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71122+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71123+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71124+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71125+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);
71126+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71127+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71128+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71129+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71130+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71131+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71132+extern void assign_special_role(const char *rolename);
71133+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71134+extern int gr_rbac_disable(void *unused);
71135+extern void gr_enable_rbac_system(void);
71136+
71137+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71138+{
71139+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71140+ return -EFAULT;
71141+
71142+ return 0;
71143+}
71144+
71145+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71146+{
71147+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71148+ return -EFAULT;
71149+
71150+ return 0;
71151+}
71152+
71153+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71154+{
71155+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71156+ return -EFAULT;
71157+
71158+ return 0;
71159+}
71160+
71161+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71162+{
71163+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71164+ return -EFAULT;
71165+
71166+ return 0;
71167+}
71168+
71169+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71170+{
71171+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71172+ return -EFAULT;
71173+
71174+ return 0;
71175+}
71176+
71177+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71178+{
71179+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71180+ return -EFAULT;
71181+
71182+ return 0;
71183+}
71184+
71185+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71186+{
71187+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71188+ return -EFAULT;
71189+
71190+ return 0;
71191+}
71192+
71193+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71194+{
71195+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71196+ return -EFAULT;
71197+
71198+ return 0;
71199+}
71200+
71201+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71202+{
71203+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71204+ return -EFAULT;
71205+
71206+ return 0;
71207+}
71208+
71209+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71210+{
71211+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71212+ return -EFAULT;
71213+
71214+ if (((uwrap->version != GRSECURITY_VERSION) &&
71215+ (uwrap->version != 0x2901)) ||
71216+ (uwrap->size != sizeof(struct gr_arg)))
71217+ return -EINVAL;
71218+
71219+ return 0;
71220+}
71221+
71222+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71223+{
71224+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71225+ return -EFAULT;
71226+
71227+ return 0;
71228+}
71229+
71230+static size_t get_gr_arg_wrapper_size_normal(void)
71231+{
71232+ return sizeof(struct gr_arg_wrapper);
71233+}
71234+
71235+#ifdef CONFIG_COMPAT
71236+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71237+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71238+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71239+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71240+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71241+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71242+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71243+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71244+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71245+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71246+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71247+extern size_t get_gr_arg_wrapper_size_compat(void);
71248+
71249+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71250+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71251+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71252+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71253+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71254+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71255+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71256+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71257+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71258+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71259+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71260+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71261+
71262+#else
71263+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71264+#define copy_gr_arg copy_gr_arg_normal
71265+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71266+#define copy_acl_object_label copy_acl_object_label_normal
71267+#define copy_acl_subject_label copy_acl_subject_label_normal
71268+#define copy_acl_role_label copy_acl_role_label_normal
71269+#define copy_acl_ip_label copy_acl_ip_label_normal
71270+#define copy_pointer_from_array copy_pointer_from_array_normal
71271+#define copy_sprole_pw copy_sprole_pw_normal
71272+#define copy_role_transition copy_role_transition_normal
71273+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71274+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71275+#endif
71276+
71277+static struct acl_subject_label *
71278+lookup_subject_map(const struct acl_subject_label *userp)
71279+{
71280+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71281+ struct subject_map *match;
71282+
71283+ match = polstate->subj_map_set.s_hash[index];
71284+
71285+ while (match && match->user != userp)
71286+ match = match->next;
71287+
71288+ if (match != NULL)
71289+ return match->kernel;
71290+ else
71291+ return NULL;
71292+}
71293+
71294+static void
71295+insert_subj_map_entry(struct subject_map *subjmap)
71296+{
71297+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71298+ struct subject_map **curr;
71299+
71300+ subjmap->prev = NULL;
71301+
71302+ curr = &polstate->subj_map_set.s_hash[index];
71303+ if (*curr != NULL)
71304+ (*curr)->prev = subjmap;
71305+
71306+ subjmap->next = *curr;
71307+ *curr = subjmap;
71308+
71309+ return;
71310+}
71311+
71312+static void
71313+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71314+{
71315+ unsigned int index =
71316+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71317+ struct acl_role_label **curr;
71318+ struct acl_role_label *tmp, *tmp2;
71319+
71320+ curr = &polstate->acl_role_set.r_hash[index];
71321+
71322+ /* simple case, slot is empty, just set it to our role */
71323+ if (*curr == NULL) {
71324+ *curr = role;
71325+ } else {
71326+ /* example:
71327+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71328+ 2 -> 3
71329+ */
71330+ /* first check to see if we can already be reached via this slot */
71331+ tmp = *curr;
71332+ while (tmp && tmp != role)
71333+ tmp = tmp->next;
71334+ if (tmp == role) {
71335+ /* we don't need to add ourselves to this slot's chain */
71336+ return;
71337+ }
71338+ /* we need to add ourselves to this chain, two cases */
71339+ if (role->next == NULL) {
71340+ /* simple case, append the current chain to our role */
71341+ role->next = *curr;
71342+ *curr = role;
71343+ } else {
71344+ /* 1 -> 2 -> 3 -> 4
71345+ 2 -> 3 -> 4
71346+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71347+ */
71348+ /* trickier case: walk our role's chain until we find
71349+ the role for the start of the current slot's chain */
71350+ tmp = role;
71351+ tmp2 = *curr;
71352+ while (tmp->next && tmp->next != tmp2)
71353+ tmp = tmp->next;
71354+ if (tmp->next == tmp2) {
71355+ /* from example above, we found 3, so just
71356+ replace this slot's chain with ours */
71357+ *curr = role;
71358+ } else {
71359+ /* we didn't find a subset of our role's chain
71360+ in the current slot's chain, so append their
71361+ chain to ours, and set us as the first role in
71362+ the slot's chain
71363+
71364+ we could fold this case with the case above,
71365+ but making it explicit for clarity
71366+ */
71367+ tmp->next = tmp2;
71368+ *curr = role;
71369+ }
71370+ }
71371+ }
71372+
71373+ return;
71374+}
71375+
71376+static void
71377+insert_acl_role_label(struct acl_role_label *role)
71378+{
71379+ int i;
71380+
71381+ if (polstate->role_list == NULL) {
71382+ polstate->role_list = role;
71383+ role->prev = NULL;
71384+ } else {
71385+ role->prev = polstate->role_list;
71386+ polstate->role_list = role;
71387+ }
71388+
71389+ /* used for hash chains */
71390+ role->next = NULL;
71391+
71392+ if (role->roletype & GR_ROLE_DOMAIN) {
71393+ for (i = 0; i < role->domain_child_num; i++)
71394+ __insert_acl_role_label(role, role->domain_children[i]);
71395+ } else
71396+ __insert_acl_role_label(role, role->uidgid);
71397+}
71398+
71399+static int
71400+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71401+{
71402+ struct name_entry **curr, *nentry;
71403+ struct inodev_entry *ientry;
71404+ unsigned int len = strlen(name);
71405+ unsigned int key = full_name_hash(name, len);
71406+ unsigned int index = key % polstate->name_set.n_size;
71407+
71408+ curr = &polstate->name_set.n_hash[index];
71409+
71410+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71411+ curr = &((*curr)->next);
71412+
71413+ if (*curr != NULL)
71414+ return 1;
71415+
71416+ nentry = acl_alloc(sizeof (struct name_entry));
71417+ if (nentry == NULL)
71418+ return 0;
71419+ ientry = acl_alloc(sizeof (struct inodev_entry));
71420+ if (ientry == NULL)
71421+ return 0;
71422+ ientry->nentry = nentry;
71423+
71424+ nentry->key = key;
71425+ nentry->name = name;
71426+ nentry->inode = inode;
71427+ nentry->device = device;
71428+ nentry->len = len;
71429+ nentry->deleted = deleted;
71430+
71431+ nentry->prev = NULL;
71432+ curr = &polstate->name_set.n_hash[index];
71433+ if (*curr != NULL)
71434+ (*curr)->prev = nentry;
71435+ nentry->next = *curr;
71436+ *curr = nentry;
71437+
71438+ /* insert us into the table searchable by inode/dev */
71439+ __insert_inodev_entry(polstate, ientry);
71440+
71441+ return 1;
71442+}
71443+
71444+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71445+
71446+static void *
71447+create_table(__u32 * len, int elementsize)
71448+{
71449+ unsigned int table_sizes[] = {
71450+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71451+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71452+ 4194301, 8388593, 16777213, 33554393, 67108859
71453+ };
71454+ void *newtable = NULL;
71455+ unsigned int pwr = 0;
71456+
71457+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71458+ table_sizes[pwr] <= *len)
71459+ pwr++;
71460+
71461+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71462+ return newtable;
71463+
71464+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71465+ newtable =
71466+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71467+ else
71468+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71469+
71470+ *len = table_sizes[pwr];
71471+
71472+ return newtable;
71473+}
71474+
71475+static int
71476+init_variables(const struct gr_arg *arg, bool reload)
71477+{
71478+ struct task_struct *reaper = init_pid_ns.child_reaper;
71479+ unsigned int stacksize;
71480+
71481+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71482+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71483+ polstate->name_set.n_size = arg->role_db.num_objects;
71484+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71485+
71486+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71487+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71488+ return 1;
71489+
71490+ if (!reload) {
71491+ if (!gr_init_uidset())
71492+ return 1;
71493+ }
71494+
71495+ /* set up the stack that holds allocation info */
71496+
71497+ stacksize = arg->role_db.num_pointers + 5;
71498+
71499+ if (!acl_alloc_stack_init(stacksize))
71500+ return 1;
71501+
71502+ if (!reload) {
71503+ /* grab reference for the real root dentry and vfsmount */
71504+ get_fs_root(reaper->fs, &gr_real_root);
71505+
71506+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71507+ 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);
71508+#endif
71509+
71510+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71511+ if (fakefs_obj_rw == NULL)
71512+ return 1;
71513+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71514+
71515+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71516+ if (fakefs_obj_rwx == NULL)
71517+ return 1;
71518+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71519+ }
71520+
71521+ polstate->subj_map_set.s_hash =
71522+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71523+ polstate->acl_role_set.r_hash =
71524+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71525+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71526+ polstate->inodev_set.i_hash =
71527+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71528+
71529+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71530+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71531+ return 1;
71532+
71533+ memset(polstate->subj_map_set.s_hash, 0,
71534+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71535+ memset(polstate->acl_role_set.r_hash, 0,
71536+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71537+ memset(polstate->name_set.n_hash, 0,
71538+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71539+ memset(polstate->inodev_set.i_hash, 0,
71540+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71541+
71542+ return 0;
71543+}
71544+
71545+/* free information not needed after startup
71546+ currently contains user->kernel pointer mappings for subjects
71547+*/
71548+
71549+static void
71550+free_init_variables(void)
71551+{
71552+ __u32 i;
71553+
71554+ if (polstate->subj_map_set.s_hash) {
71555+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71556+ if (polstate->subj_map_set.s_hash[i]) {
71557+ kfree(polstate->subj_map_set.s_hash[i]);
71558+ polstate->subj_map_set.s_hash[i] = NULL;
71559+ }
71560+ }
71561+
71562+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71563+ PAGE_SIZE)
71564+ kfree(polstate->subj_map_set.s_hash);
71565+ else
71566+ vfree(polstate->subj_map_set.s_hash);
71567+ }
71568+
71569+ return;
71570+}
71571+
71572+static void
71573+free_variables(bool reload)
71574+{
71575+ struct acl_subject_label *s;
71576+ struct acl_role_label *r;
71577+ struct task_struct *task, *task2;
71578+ unsigned int x;
71579+
71580+ if (!reload) {
71581+ gr_clear_learn_entries();
71582+
71583+ read_lock(&tasklist_lock);
71584+ do_each_thread(task2, task) {
71585+ task->acl_sp_role = 0;
71586+ task->acl_role_id = 0;
71587+ task->inherited = 0;
71588+ task->acl = NULL;
71589+ task->role = NULL;
71590+ } while_each_thread(task2, task);
71591+ read_unlock(&tasklist_lock);
71592+
71593+ kfree(fakefs_obj_rw);
71594+ fakefs_obj_rw = NULL;
71595+ kfree(fakefs_obj_rwx);
71596+ fakefs_obj_rwx = NULL;
71597+
71598+ /* release the reference to the real root dentry and vfsmount */
71599+ path_put(&gr_real_root);
71600+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71601+ }
71602+
71603+ /* free all object hash tables */
71604+
71605+ FOR_EACH_ROLE_START(r)
71606+ if (r->subj_hash == NULL)
71607+ goto next_role;
71608+ FOR_EACH_SUBJECT_START(r, s, x)
71609+ if (s->obj_hash == NULL)
71610+ break;
71611+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71612+ kfree(s->obj_hash);
71613+ else
71614+ vfree(s->obj_hash);
71615+ FOR_EACH_SUBJECT_END(s, x)
71616+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71617+ if (s->obj_hash == NULL)
71618+ break;
71619+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71620+ kfree(s->obj_hash);
71621+ else
71622+ vfree(s->obj_hash);
71623+ FOR_EACH_NESTED_SUBJECT_END(s)
71624+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71625+ kfree(r->subj_hash);
71626+ else
71627+ vfree(r->subj_hash);
71628+ r->subj_hash = NULL;
71629+next_role:
71630+ FOR_EACH_ROLE_END(r)
71631+
71632+ acl_free_all();
71633+
71634+ if (polstate->acl_role_set.r_hash) {
71635+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71636+ PAGE_SIZE)
71637+ kfree(polstate->acl_role_set.r_hash);
71638+ else
71639+ vfree(polstate->acl_role_set.r_hash);
71640+ }
71641+ if (polstate->name_set.n_hash) {
71642+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71643+ PAGE_SIZE)
71644+ kfree(polstate->name_set.n_hash);
71645+ else
71646+ vfree(polstate->name_set.n_hash);
71647+ }
71648+
71649+ if (polstate->inodev_set.i_hash) {
71650+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71651+ PAGE_SIZE)
71652+ kfree(polstate->inodev_set.i_hash);
71653+ else
71654+ vfree(polstate->inodev_set.i_hash);
71655+ }
71656+
71657+ if (!reload)
71658+ gr_free_uidset();
71659+
71660+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71661+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71662+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71663+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71664+
71665+ polstate->default_role = NULL;
71666+ polstate->kernel_role = NULL;
71667+ polstate->role_list = NULL;
71668+
71669+ return;
71670+}
71671+
71672+static struct acl_subject_label *
71673+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71674+
71675+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71676+{
71677+ unsigned int len = strnlen_user(*name, maxlen);
71678+ char *tmp;
71679+
71680+ if (!len || len >= maxlen)
71681+ return -EINVAL;
71682+
71683+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71684+ return -ENOMEM;
71685+
71686+ if (copy_from_user(tmp, *name, len))
71687+ return -EFAULT;
71688+
71689+ tmp[len-1] = '\0';
71690+ *name = tmp;
71691+
71692+ return 0;
71693+}
71694+
71695+static int
71696+copy_user_glob(struct acl_object_label *obj)
71697+{
71698+ struct acl_object_label *g_tmp, **guser;
71699+ int error;
71700+
71701+ if (obj->globbed == NULL)
71702+ return 0;
71703+
71704+ guser = &obj->globbed;
71705+ while (*guser) {
71706+ g_tmp = (struct acl_object_label *)
71707+ acl_alloc(sizeof (struct acl_object_label));
71708+ if (g_tmp == NULL)
71709+ return -ENOMEM;
71710+
71711+ if (copy_acl_object_label(g_tmp, *guser))
71712+ return -EFAULT;
71713+
71714+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71715+ if (error)
71716+ return error;
71717+
71718+ *guser = g_tmp;
71719+ guser = &(g_tmp->next);
71720+ }
71721+
71722+ return 0;
71723+}
71724+
71725+static int
71726+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71727+ struct acl_role_label *role)
71728+{
71729+ struct acl_object_label *o_tmp;
71730+ int ret;
71731+
71732+ while (userp) {
71733+ if ((o_tmp = (struct acl_object_label *)
71734+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71735+ return -ENOMEM;
71736+
71737+ if (copy_acl_object_label(o_tmp, userp))
71738+ return -EFAULT;
71739+
71740+ userp = o_tmp->prev;
71741+
71742+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71743+ if (ret)
71744+ return ret;
71745+
71746+ insert_acl_obj_label(o_tmp, subj);
71747+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71748+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71749+ return -ENOMEM;
71750+
71751+ ret = copy_user_glob(o_tmp);
71752+ if (ret)
71753+ return ret;
71754+
71755+ if (o_tmp->nested) {
71756+ int already_copied;
71757+
71758+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71759+ if (IS_ERR(o_tmp->nested))
71760+ return PTR_ERR(o_tmp->nested);
71761+
71762+ /* insert into nested subject list if we haven't copied this one yet
71763+ to prevent duplicate entries */
71764+ if (!already_copied) {
71765+ o_tmp->nested->next = role->hash->first;
71766+ role->hash->first = o_tmp->nested;
71767+ }
71768+ }
71769+ }
71770+
71771+ return 0;
71772+}
71773+
71774+static __u32
71775+count_user_subjs(struct acl_subject_label *userp)
71776+{
71777+ struct acl_subject_label s_tmp;
71778+ __u32 num = 0;
71779+
71780+ while (userp) {
71781+ if (copy_acl_subject_label(&s_tmp, userp))
71782+ break;
71783+
71784+ userp = s_tmp.prev;
71785+ }
71786+
71787+ return num;
71788+}
71789+
71790+static int
71791+copy_user_allowedips(struct acl_role_label *rolep)
71792+{
71793+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71794+
71795+ ruserip = rolep->allowed_ips;
71796+
71797+ while (ruserip) {
71798+ rlast = rtmp;
71799+
71800+ if ((rtmp = (struct role_allowed_ip *)
71801+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71802+ return -ENOMEM;
71803+
71804+ if (copy_role_allowed_ip(rtmp, ruserip))
71805+ return -EFAULT;
71806+
71807+ ruserip = rtmp->prev;
71808+
71809+ if (!rlast) {
71810+ rtmp->prev = NULL;
71811+ rolep->allowed_ips = rtmp;
71812+ } else {
71813+ rlast->next = rtmp;
71814+ rtmp->prev = rlast;
71815+ }
71816+
71817+ if (!ruserip)
71818+ rtmp->next = NULL;
71819+ }
71820+
71821+ return 0;
71822+}
71823+
71824+static int
71825+copy_user_transitions(struct acl_role_label *rolep)
71826+{
71827+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71828+ int error;
71829+
71830+ rusertp = rolep->transitions;
71831+
71832+ while (rusertp) {
71833+ rlast = rtmp;
71834+
71835+ if ((rtmp = (struct role_transition *)
71836+ acl_alloc(sizeof (struct role_transition))) == NULL)
71837+ return -ENOMEM;
71838+
71839+ if (copy_role_transition(rtmp, rusertp))
71840+ return -EFAULT;
71841+
71842+ rusertp = rtmp->prev;
71843+
71844+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71845+ if (error)
71846+ return error;
71847+
71848+ if (!rlast) {
71849+ rtmp->prev = NULL;
71850+ rolep->transitions = rtmp;
71851+ } else {
71852+ rlast->next = rtmp;
71853+ rtmp->prev = rlast;
71854+ }
71855+
71856+ if (!rusertp)
71857+ rtmp->next = NULL;
71858+ }
71859+
71860+ return 0;
71861+}
71862+
71863+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71864+{
71865+ struct acl_object_label o_tmp;
71866+ __u32 num = 0;
71867+
71868+ while (userp) {
71869+ if (copy_acl_object_label(&o_tmp, userp))
71870+ break;
71871+
71872+ userp = o_tmp.prev;
71873+ num++;
71874+ }
71875+
71876+ return num;
71877+}
71878+
71879+static struct acl_subject_label *
71880+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71881+{
71882+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71883+ __u32 num_objs;
71884+ struct acl_ip_label **i_tmp, *i_utmp2;
71885+ struct gr_hash_struct ghash;
71886+ struct subject_map *subjmap;
71887+ unsigned int i_num;
71888+ int err;
71889+
71890+ if (already_copied != NULL)
71891+ *already_copied = 0;
71892+
71893+ s_tmp = lookup_subject_map(userp);
71894+
71895+ /* we've already copied this subject into the kernel, just return
71896+ the reference to it, and don't copy it over again
71897+ */
71898+ if (s_tmp) {
71899+ if (already_copied != NULL)
71900+ *already_copied = 1;
71901+ return(s_tmp);
71902+ }
71903+
71904+ if ((s_tmp = (struct acl_subject_label *)
71905+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71906+ return ERR_PTR(-ENOMEM);
71907+
71908+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71909+ if (subjmap == NULL)
71910+ return ERR_PTR(-ENOMEM);
71911+
71912+ subjmap->user = userp;
71913+ subjmap->kernel = s_tmp;
71914+ insert_subj_map_entry(subjmap);
71915+
71916+ if (copy_acl_subject_label(s_tmp, userp))
71917+ return ERR_PTR(-EFAULT);
71918+
71919+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71920+ if (err)
71921+ return ERR_PTR(err);
71922+
71923+ if (!strcmp(s_tmp->filename, "/"))
71924+ role->root_label = s_tmp;
71925+
71926+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71927+ return ERR_PTR(-EFAULT);
71928+
71929+ /* copy user and group transition tables */
71930+
71931+ if (s_tmp->user_trans_num) {
71932+ uid_t *uidlist;
71933+
71934+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71935+ if (uidlist == NULL)
71936+ return ERR_PTR(-ENOMEM);
71937+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71938+ return ERR_PTR(-EFAULT);
71939+
71940+ s_tmp->user_transitions = uidlist;
71941+ }
71942+
71943+ if (s_tmp->group_trans_num) {
71944+ gid_t *gidlist;
71945+
71946+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71947+ if (gidlist == NULL)
71948+ return ERR_PTR(-ENOMEM);
71949+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71950+ return ERR_PTR(-EFAULT);
71951+
71952+ s_tmp->group_transitions = gidlist;
71953+ }
71954+
71955+ /* set up object hash table */
71956+ num_objs = count_user_objs(ghash.first);
71957+
71958+ s_tmp->obj_hash_size = num_objs;
71959+ s_tmp->obj_hash =
71960+ (struct acl_object_label **)
71961+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71962+
71963+ if (!s_tmp->obj_hash)
71964+ return ERR_PTR(-ENOMEM);
71965+
71966+ memset(s_tmp->obj_hash, 0,
71967+ s_tmp->obj_hash_size *
71968+ sizeof (struct acl_object_label *));
71969+
71970+ /* add in objects */
71971+ err = copy_user_objs(ghash.first, s_tmp, role);
71972+
71973+ if (err)
71974+ return ERR_PTR(err);
71975+
71976+ /* set pointer for parent subject */
71977+ if (s_tmp->parent_subject) {
71978+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71979+
71980+ if (IS_ERR(s_tmp2))
71981+ return s_tmp2;
71982+
71983+ s_tmp->parent_subject = s_tmp2;
71984+ }
71985+
71986+ /* add in ip acls */
71987+
71988+ if (!s_tmp->ip_num) {
71989+ s_tmp->ips = NULL;
71990+ goto insert;
71991+ }
71992+
71993+ i_tmp =
71994+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71995+ sizeof (struct acl_ip_label *));
71996+
71997+ if (!i_tmp)
71998+ return ERR_PTR(-ENOMEM);
71999+
72000+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72001+ *(i_tmp + i_num) =
72002+ (struct acl_ip_label *)
72003+ acl_alloc(sizeof (struct acl_ip_label));
72004+ if (!*(i_tmp + i_num))
72005+ return ERR_PTR(-ENOMEM);
72006+
72007+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72008+ return ERR_PTR(-EFAULT);
72009+
72010+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72011+ return ERR_PTR(-EFAULT);
72012+
72013+ if ((*(i_tmp + i_num))->iface == NULL)
72014+ continue;
72015+
72016+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72017+ if (err)
72018+ return ERR_PTR(err);
72019+ }
72020+
72021+ s_tmp->ips = i_tmp;
72022+
72023+insert:
72024+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72025+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72026+ return ERR_PTR(-ENOMEM);
72027+
72028+ return s_tmp;
72029+}
72030+
72031+static int
72032+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72033+{
72034+ struct acl_subject_label s_pre;
72035+ struct acl_subject_label * ret;
72036+ int err;
72037+
72038+ while (userp) {
72039+ if (copy_acl_subject_label(&s_pre, userp))
72040+ return -EFAULT;
72041+
72042+ ret = do_copy_user_subj(userp, role, NULL);
72043+
72044+ err = PTR_ERR(ret);
72045+ if (IS_ERR(ret))
72046+ return err;
72047+
72048+ insert_acl_subj_label(ret, role);
72049+
72050+ userp = s_pre.prev;
72051+ }
72052+
72053+ return 0;
72054+}
72055+
72056+static int
72057+copy_user_acl(struct gr_arg *arg)
72058+{
72059+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72060+ struct acl_subject_label *subj_list;
72061+ struct sprole_pw *sptmp;
72062+ struct gr_hash_struct *ghash;
72063+ uid_t *domainlist;
72064+ unsigned int r_num;
72065+ int err = 0;
72066+ __u16 i;
72067+ __u32 num_subjs;
72068+
72069+ /* we need a default and kernel role */
72070+ if (arg->role_db.num_roles < 2)
72071+ return -EINVAL;
72072+
72073+ /* copy special role authentication info from userspace */
72074+
72075+ polstate->num_sprole_pws = arg->num_sprole_pws;
72076+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72077+
72078+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72079+ return -ENOMEM;
72080+
72081+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72082+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72083+ if (!sptmp)
72084+ return -ENOMEM;
72085+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72086+ return -EFAULT;
72087+
72088+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72089+ if (err)
72090+ return err;
72091+
72092+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72093+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72094+#endif
72095+
72096+ polstate->acl_special_roles[i] = sptmp;
72097+ }
72098+
72099+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72100+
72101+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72102+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72103+
72104+ if (!r_tmp)
72105+ return -ENOMEM;
72106+
72107+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72108+ return -EFAULT;
72109+
72110+ if (copy_acl_role_label(r_tmp, r_utmp2))
72111+ return -EFAULT;
72112+
72113+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72114+ if (err)
72115+ return err;
72116+
72117+ if (!strcmp(r_tmp->rolename, "default")
72118+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72119+ polstate->default_role = r_tmp;
72120+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72121+ polstate->kernel_role = r_tmp;
72122+ }
72123+
72124+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72125+ return -ENOMEM;
72126+
72127+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72128+ return -EFAULT;
72129+
72130+ r_tmp->hash = ghash;
72131+
72132+ num_subjs = count_user_subjs(r_tmp->hash->first);
72133+
72134+ r_tmp->subj_hash_size = num_subjs;
72135+ r_tmp->subj_hash =
72136+ (struct acl_subject_label **)
72137+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72138+
72139+ if (!r_tmp->subj_hash)
72140+ return -ENOMEM;
72141+
72142+ err = copy_user_allowedips(r_tmp);
72143+ if (err)
72144+ return err;
72145+
72146+ /* copy domain info */
72147+ if (r_tmp->domain_children != NULL) {
72148+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72149+ if (domainlist == NULL)
72150+ return -ENOMEM;
72151+
72152+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72153+ return -EFAULT;
72154+
72155+ r_tmp->domain_children = domainlist;
72156+ }
72157+
72158+ err = copy_user_transitions(r_tmp);
72159+ if (err)
72160+ return err;
72161+
72162+ memset(r_tmp->subj_hash, 0,
72163+ r_tmp->subj_hash_size *
72164+ sizeof (struct acl_subject_label *));
72165+
72166+ /* acquire the list of subjects, then NULL out
72167+ the list prior to parsing the subjects for this role,
72168+ as during this parsing the list is replaced with a list
72169+ of *nested* subjects for the role
72170+ */
72171+ subj_list = r_tmp->hash->first;
72172+
72173+ /* set nested subject list to null */
72174+ r_tmp->hash->first = NULL;
72175+
72176+ err = copy_user_subjs(subj_list, r_tmp);
72177+
72178+ if (err)
72179+ return err;
72180+
72181+ insert_acl_role_label(r_tmp);
72182+ }
72183+
72184+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72185+ return -EINVAL;
72186+
72187+ return err;
72188+}
72189+
72190+static int gracl_reload_apply_policies(void *reload)
72191+{
72192+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72193+ struct task_struct *task, *task2;
72194+ struct acl_role_label *role, *rtmp;
72195+ struct acl_subject_label *subj;
72196+ const struct cred *cred;
72197+ int role_applied;
72198+ int ret = 0;
72199+
72200+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72201+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72202+
72203+ /* first make sure we'll be able to apply the new policy cleanly */
72204+ do_each_thread(task2, task) {
72205+ if (task->exec_file == NULL)
72206+ continue;
72207+ role_applied = 0;
72208+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72209+ /* preserve special roles */
72210+ FOR_EACH_ROLE_START(role)
72211+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72212+ rtmp = task->role;
72213+ task->role = role;
72214+ role_applied = 1;
72215+ break;
72216+ }
72217+ FOR_EACH_ROLE_END(role)
72218+ }
72219+ if (!role_applied) {
72220+ cred = __task_cred(task);
72221+ rtmp = task->role;
72222+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72223+ }
72224+ /* this handles non-nested inherited subjects, nested subjects will still
72225+ be dropped currently */
72226+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72227+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72228+ /* change the role back so that we've made no modifications to the policy */
72229+ task->role = rtmp;
72230+
72231+ if (subj == NULL || task->tmpacl == NULL) {
72232+ ret = -EINVAL;
72233+ goto out;
72234+ }
72235+ } while_each_thread(task2, task);
72236+
72237+ /* now actually apply the policy */
72238+
72239+ do_each_thread(task2, task) {
72240+ if (task->exec_file) {
72241+ role_applied = 0;
72242+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72243+ /* preserve special roles */
72244+ FOR_EACH_ROLE_START(role)
72245+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72246+ task->role = role;
72247+ role_applied = 1;
72248+ break;
72249+ }
72250+ FOR_EACH_ROLE_END(role)
72251+ }
72252+ if (!role_applied) {
72253+ cred = __task_cred(task);
72254+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72255+ }
72256+ /* this handles non-nested inherited subjects, nested subjects will still
72257+ be dropped currently */
72258+ if (!reload_state->oldmode && task->inherited)
72259+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72260+ else {
72261+ /* looked up and tagged to the task previously */
72262+ subj = task->tmpacl;
72263+ }
72264+ /* subj will be non-null */
72265+ __gr_apply_subject_to_task(polstate, task, subj);
72266+ if (reload_state->oldmode) {
72267+ task->acl_role_id = 0;
72268+ task->acl_sp_role = 0;
72269+ task->inherited = 0;
72270+ }
72271+ } else {
72272+ // it's a kernel process
72273+ task->role = polstate->kernel_role;
72274+ task->acl = polstate->kernel_role->root_label;
72275+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72276+ task->acl->mode &= ~GR_PROCFIND;
72277+#endif
72278+ }
72279+ } while_each_thread(task2, task);
72280+
72281+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72282+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72283+
72284+out:
72285+
72286+ return ret;
72287+}
72288+
72289+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72290+{
72291+ struct gr_reload_state new_reload_state = { };
72292+ int err;
72293+
72294+ new_reload_state.oldpolicy_ptr = polstate;
72295+ new_reload_state.oldalloc_ptr = current_alloc_state;
72296+ new_reload_state.oldmode = oldmode;
72297+
72298+ current_alloc_state = &new_reload_state.newalloc;
72299+ polstate = &new_reload_state.newpolicy;
72300+
72301+ /* everything relevant is now saved off, copy in the new policy */
72302+ if (init_variables(args, true)) {
72303+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72304+ err = -ENOMEM;
72305+ goto error;
72306+ }
72307+
72308+ err = copy_user_acl(args);
72309+ free_init_variables();
72310+ if (err)
72311+ goto error;
72312+ /* the new policy is copied in, with the old policy available via saved_state
72313+ first go through applying roles, making sure to preserve special roles
72314+ then apply new subjects, making sure to preserve inherited and nested subjects,
72315+ though currently only inherited subjects will be preserved
72316+ */
72317+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72318+ if (err)
72319+ goto error;
72320+
72321+ /* we've now applied the new policy, so restore the old policy state to free it */
72322+ polstate = &new_reload_state.oldpolicy;
72323+ current_alloc_state = &new_reload_state.oldalloc;
72324+ free_variables(true);
72325+
72326+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72327+ to running_polstate/current_alloc_state inside stop_machine
72328+ */
72329+ err = 0;
72330+ goto out;
72331+error:
72332+ /* on error of loading the new policy, we'll just keep the previous
72333+ policy set around
72334+ */
72335+ free_variables(true);
72336+
72337+ /* doesn't affect runtime, but maintains consistent state */
72338+out:
72339+ polstate = new_reload_state.oldpolicy_ptr;
72340+ current_alloc_state = new_reload_state.oldalloc_ptr;
72341+
72342+ return err;
72343+}
72344+
72345+static int
72346+gracl_init(struct gr_arg *args)
72347+{
72348+ int error = 0;
72349+
72350+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72351+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72352+
72353+ if (init_variables(args, false)) {
72354+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72355+ error = -ENOMEM;
72356+ goto out;
72357+ }
72358+
72359+ error = copy_user_acl(args);
72360+ free_init_variables();
72361+ if (error)
72362+ goto out;
72363+
72364+ error = gr_set_acls(0);
72365+ if (error)
72366+ goto out;
72367+
72368+ gr_enable_rbac_system();
72369+
72370+ return 0;
72371+
72372+out:
72373+ free_variables(false);
72374+ return error;
72375+}
72376+
72377+static int
72378+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72379+ unsigned char **sum)
72380+{
72381+ struct acl_role_label *r;
72382+ struct role_allowed_ip *ipp;
72383+ struct role_transition *trans;
72384+ unsigned int i;
72385+ int found = 0;
72386+ u32 curr_ip = current->signal->curr_ip;
72387+
72388+ current->signal->saved_ip = curr_ip;
72389+
72390+ /* check transition table */
72391+
72392+ for (trans = current->role->transitions; trans; trans = trans->next) {
72393+ if (!strcmp(rolename, trans->rolename)) {
72394+ found = 1;
72395+ break;
72396+ }
72397+ }
72398+
72399+ if (!found)
72400+ return 0;
72401+
72402+ /* handle special roles that do not require authentication
72403+ and check ip */
72404+
72405+ FOR_EACH_ROLE_START(r)
72406+ if (!strcmp(rolename, r->rolename) &&
72407+ (r->roletype & GR_ROLE_SPECIAL)) {
72408+ found = 0;
72409+ if (r->allowed_ips != NULL) {
72410+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72411+ if ((ntohl(curr_ip) & ipp->netmask) ==
72412+ (ntohl(ipp->addr) & ipp->netmask))
72413+ found = 1;
72414+ }
72415+ } else
72416+ found = 2;
72417+ if (!found)
72418+ return 0;
72419+
72420+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72421+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72422+ *salt = NULL;
72423+ *sum = NULL;
72424+ return 1;
72425+ }
72426+ }
72427+ FOR_EACH_ROLE_END(r)
72428+
72429+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72430+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72431+ *salt = polstate->acl_special_roles[i]->salt;
72432+ *sum = polstate->acl_special_roles[i]->sum;
72433+ return 1;
72434+ }
72435+ }
72436+
72437+ return 0;
72438+}
72439+
72440+int gr_check_secure_terminal(struct task_struct *task)
72441+{
72442+ struct task_struct *p, *p2, *p3;
72443+ struct files_struct *files;
72444+ struct fdtable *fdt;
72445+ struct file *our_file = NULL, *file;
72446+ int i;
72447+
72448+ if (task->signal->tty == NULL)
72449+ return 1;
72450+
72451+ files = get_files_struct(task);
72452+ if (files != NULL) {
72453+ rcu_read_lock();
72454+ fdt = files_fdtable(files);
72455+ for (i=0; i < fdt->max_fds; i++) {
72456+ file = fcheck_files(files, i);
72457+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72458+ get_file(file);
72459+ our_file = file;
72460+ }
72461+ }
72462+ rcu_read_unlock();
72463+ put_files_struct(files);
72464+ }
72465+
72466+ if (our_file == NULL)
72467+ return 1;
72468+
72469+ read_lock(&tasklist_lock);
72470+ do_each_thread(p2, p) {
72471+ files = get_files_struct(p);
72472+ if (files == NULL ||
72473+ (p->signal && p->signal->tty == task->signal->tty)) {
72474+ if (files != NULL)
72475+ put_files_struct(files);
72476+ continue;
72477+ }
72478+ rcu_read_lock();
72479+ fdt = files_fdtable(files);
72480+ for (i=0; i < fdt->max_fds; i++) {
72481+ file = fcheck_files(files, i);
72482+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72483+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72484+ p3 = task;
72485+ while (task_pid_nr(p3) > 0) {
72486+ if (p3 == p)
72487+ break;
72488+ p3 = p3->real_parent;
72489+ }
72490+ if (p3 == p)
72491+ break;
72492+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72493+ gr_handle_alertkill(p);
72494+ rcu_read_unlock();
72495+ put_files_struct(files);
72496+ read_unlock(&tasklist_lock);
72497+ fput(our_file);
72498+ return 0;
72499+ }
72500+ }
72501+ rcu_read_unlock();
72502+ put_files_struct(files);
72503+ } while_each_thread(p2, p);
72504+ read_unlock(&tasklist_lock);
72505+
72506+ fput(our_file);
72507+ return 1;
72508+}
72509+
72510+ssize_t
72511+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72512+{
72513+ struct gr_arg_wrapper uwrap;
72514+ unsigned char *sprole_salt = NULL;
72515+ unsigned char *sprole_sum = NULL;
72516+ int error = 0;
72517+ int error2 = 0;
72518+ size_t req_count = 0;
72519+ unsigned char oldmode = 0;
72520+
72521+ mutex_lock(&gr_dev_mutex);
72522+
72523+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72524+ error = -EPERM;
72525+ goto out;
72526+ }
72527+
72528+#ifdef CONFIG_COMPAT
72529+ pax_open_kernel();
72530+ if (is_compat_task()) {
72531+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72532+ copy_gr_arg = &copy_gr_arg_compat;
72533+ copy_acl_object_label = &copy_acl_object_label_compat;
72534+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72535+ copy_acl_role_label = &copy_acl_role_label_compat;
72536+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72537+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72538+ copy_role_transition = &copy_role_transition_compat;
72539+ copy_sprole_pw = &copy_sprole_pw_compat;
72540+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72541+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72542+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72543+ } else {
72544+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72545+ copy_gr_arg = &copy_gr_arg_normal;
72546+ copy_acl_object_label = &copy_acl_object_label_normal;
72547+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72548+ copy_acl_role_label = &copy_acl_role_label_normal;
72549+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72550+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72551+ copy_role_transition = &copy_role_transition_normal;
72552+ copy_sprole_pw = &copy_sprole_pw_normal;
72553+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72554+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72555+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72556+ }
72557+ pax_close_kernel();
72558+#endif
72559+
72560+ req_count = get_gr_arg_wrapper_size();
72561+
72562+ if (count != req_count) {
72563+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72564+ error = -EINVAL;
72565+ goto out;
72566+ }
72567+
72568+
72569+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72570+ gr_auth_expires = 0;
72571+ gr_auth_attempts = 0;
72572+ }
72573+
72574+ error = copy_gr_arg_wrapper(buf, &uwrap);
72575+ if (error)
72576+ goto out;
72577+
72578+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72579+ if (error)
72580+ goto out;
72581+
72582+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72583+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72584+ time_after(gr_auth_expires, get_seconds())) {
72585+ error = -EBUSY;
72586+ goto out;
72587+ }
72588+
72589+ /* if non-root trying to do anything other than use a special role,
72590+ do not attempt authentication, do not count towards authentication
72591+ locking
72592+ */
72593+
72594+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72595+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72596+ gr_is_global_nonroot(current_uid())) {
72597+ error = -EPERM;
72598+ goto out;
72599+ }
72600+
72601+ /* ensure pw and special role name are null terminated */
72602+
72603+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72604+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72605+
72606+ /* Okay.
72607+ * We have our enough of the argument structure..(we have yet
72608+ * to copy_from_user the tables themselves) . Copy the tables
72609+ * only if we need them, i.e. for loading operations. */
72610+
72611+ switch (gr_usermode.mode) {
72612+ case GR_STATUS:
72613+ if (gr_acl_is_enabled()) {
72614+ error = 1;
72615+ if (!gr_check_secure_terminal(current))
72616+ error = 3;
72617+ } else
72618+ error = 2;
72619+ goto out;
72620+ case GR_SHUTDOWN:
72621+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72622+ stop_machine(gr_rbac_disable, NULL, NULL);
72623+ free_variables(false);
72624+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72625+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72626+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72627+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72628+ } else if (gr_acl_is_enabled()) {
72629+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72630+ error = -EPERM;
72631+ } else {
72632+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72633+ error = -EAGAIN;
72634+ }
72635+ break;
72636+ case GR_ENABLE:
72637+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72638+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72639+ else {
72640+ if (gr_acl_is_enabled())
72641+ error = -EAGAIN;
72642+ else
72643+ error = error2;
72644+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72645+ }
72646+ break;
72647+ case GR_OLDRELOAD:
72648+ oldmode = 1;
72649+ case GR_RELOAD:
72650+ if (!gr_acl_is_enabled()) {
72651+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72652+ error = -EAGAIN;
72653+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72654+ error2 = gracl_reload(&gr_usermode, oldmode);
72655+ if (!error2)
72656+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72657+ else {
72658+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72659+ error = error2;
72660+ }
72661+ } else {
72662+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72663+ error = -EPERM;
72664+ }
72665+ break;
72666+ case GR_SEGVMOD:
72667+ if (unlikely(!gr_acl_is_enabled())) {
72668+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72669+ error = -EAGAIN;
72670+ break;
72671+ }
72672+
72673+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72674+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72675+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72676+ struct acl_subject_label *segvacl;
72677+ segvacl =
72678+ lookup_acl_subj_label(gr_usermode.segv_inode,
72679+ gr_usermode.segv_device,
72680+ current->role);
72681+ if (segvacl) {
72682+ segvacl->crashes = 0;
72683+ segvacl->expires = 0;
72684+ }
72685+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72686+ gr_remove_uid(gr_usermode.segv_uid);
72687+ }
72688+ } else {
72689+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72690+ error = -EPERM;
72691+ }
72692+ break;
72693+ case GR_SPROLE:
72694+ case GR_SPROLEPAM:
72695+ if (unlikely(!gr_acl_is_enabled())) {
72696+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72697+ error = -EAGAIN;
72698+ break;
72699+ }
72700+
72701+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72702+ current->role->expires = 0;
72703+ current->role->auth_attempts = 0;
72704+ }
72705+
72706+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72707+ time_after(current->role->expires, get_seconds())) {
72708+ error = -EBUSY;
72709+ goto out;
72710+ }
72711+
72712+ if (lookup_special_role_auth
72713+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72714+ && ((!sprole_salt && !sprole_sum)
72715+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72716+ char *p = "";
72717+ assign_special_role(gr_usermode.sp_role);
72718+ read_lock(&tasklist_lock);
72719+ if (current->real_parent)
72720+ p = current->real_parent->role->rolename;
72721+ read_unlock(&tasklist_lock);
72722+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72723+ p, acl_sp_role_value);
72724+ } else {
72725+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72726+ error = -EPERM;
72727+ if(!(current->role->auth_attempts++))
72728+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72729+
72730+ goto out;
72731+ }
72732+ break;
72733+ case GR_UNSPROLE:
72734+ if (unlikely(!gr_acl_is_enabled())) {
72735+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72736+ error = -EAGAIN;
72737+ break;
72738+ }
72739+
72740+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72741+ char *p = "";
72742+ int i = 0;
72743+
72744+ read_lock(&tasklist_lock);
72745+ if (current->real_parent) {
72746+ p = current->real_parent->role->rolename;
72747+ i = current->real_parent->acl_role_id;
72748+ }
72749+ read_unlock(&tasklist_lock);
72750+
72751+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72752+ gr_set_acls(1);
72753+ } else {
72754+ error = -EPERM;
72755+ goto out;
72756+ }
72757+ break;
72758+ default:
72759+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72760+ error = -EINVAL;
72761+ break;
72762+ }
72763+
72764+ if (error != -EPERM)
72765+ goto out;
72766+
72767+ if(!(gr_auth_attempts++))
72768+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72769+
72770+ out:
72771+ mutex_unlock(&gr_dev_mutex);
72772+
72773+ if (!error)
72774+ error = req_count;
72775+
72776+ return error;
72777+}
72778+
72779+int
72780+gr_set_acls(const int type)
72781+{
72782+ struct task_struct *task, *task2;
72783+ struct acl_role_label *role = current->role;
72784+ struct acl_subject_label *subj;
72785+ __u16 acl_role_id = current->acl_role_id;
72786+ const struct cred *cred;
72787+ int ret;
72788+
72789+ rcu_read_lock();
72790+ read_lock(&tasklist_lock);
72791+ read_lock(&grsec_exec_file_lock);
72792+ do_each_thread(task2, task) {
72793+ /* check to see if we're called from the exit handler,
72794+ if so, only replace ACLs that have inherited the admin
72795+ ACL */
72796+
72797+ if (type && (task->role != role ||
72798+ task->acl_role_id != acl_role_id))
72799+ continue;
72800+
72801+ task->acl_role_id = 0;
72802+ task->acl_sp_role = 0;
72803+ task->inherited = 0;
72804+
72805+ if (task->exec_file) {
72806+ cred = __task_cred(task);
72807+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72808+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72809+ if (subj == NULL) {
72810+ ret = -EINVAL;
72811+ read_unlock(&grsec_exec_file_lock);
72812+ read_unlock(&tasklist_lock);
72813+ rcu_read_unlock();
72814+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72815+ return ret;
72816+ }
72817+ __gr_apply_subject_to_task(polstate, task, subj);
72818+ } else {
72819+ // it's a kernel process
72820+ task->role = polstate->kernel_role;
72821+ task->acl = polstate->kernel_role->root_label;
72822+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72823+ task->acl->mode &= ~GR_PROCFIND;
72824+#endif
72825+ }
72826+ } while_each_thread(task2, task);
72827+ read_unlock(&grsec_exec_file_lock);
72828+ read_unlock(&tasklist_lock);
72829+ rcu_read_unlock();
72830+
72831+ return 0;
72832+}
72833diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72834new file mode 100644
72835index 0000000..39645c9
72836--- /dev/null
72837+++ b/grsecurity/gracl_res.c
72838@@ -0,0 +1,68 @@
72839+#include <linux/kernel.h>
72840+#include <linux/sched.h>
72841+#include <linux/gracl.h>
72842+#include <linux/grinternal.h>
72843+
72844+static const char *restab_log[] = {
72845+ [RLIMIT_CPU] = "RLIMIT_CPU",
72846+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72847+ [RLIMIT_DATA] = "RLIMIT_DATA",
72848+ [RLIMIT_STACK] = "RLIMIT_STACK",
72849+ [RLIMIT_CORE] = "RLIMIT_CORE",
72850+ [RLIMIT_RSS] = "RLIMIT_RSS",
72851+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72852+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72853+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72854+ [RLIMIT_AS] = "RLIMIT_AS",
72855+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72856+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72857+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72858+ [RLIMIT_NICE] = "RLIMIT_NICE",
72859+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72860+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72861+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72862+};
72863+
72864+void
72865+gr_log_resource(const struct task_struct *task,
72866+ const int res, const unsigned long wanted, const int gt)
72867+{
72868+ const struct cred *cred;
72869+ unsigned long rlim;
72870+
72871+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72872+ return;
72873+
72874+ // not yet supported resource
72875+ if (unlikely(!restab_log[res]))
72876+ return;
72877+
72878+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72879+ rlim = task_rlimit_max(task, res);
72880+ else
72881+ rlim = task_rlimit(task, res);
72882+
72883+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72884+ return;
72885+
72886+ rcu_read_lock();
72887+ cred = __task_cred(task);
72888+
72889+ if (res == RLIMIT_NPROC &&
72890+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72891+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72892+ goto out_rcu_unlock;
72893+ else if (res == RLIMIT_MEMLOCK &&
72894+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72895+ goto out_rcu_unlock;
72896+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72897+ goto out_rcu_unlock;
72898+ rcu_read_unlock();
72899+
72900+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72901+
72902+ return;
72903+out_rcu_unlock:
72904+ rcu_read_unlock();
72905+ return;
72906+}
72907diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72908new file mode 100644
72909index 0000000..2040e61
72910--- /dev/null
72911+++ b/grsecurity/gracl_segv.c
72912@@ -0,0 +1,313 @@
72913+#include <linux/kernel.h>
72914+#include <linux/mm.h>
72915+#include <asm/uaccess.h>
72916+#include <asm/errno.h>
72917+#include <asm/mman.h>
72918+#include <net/sock.h>
72919+#include <linux/file.h>
72920+#include <linux/fs.h>
72921+#include <linux/net.h>
72922+#include <linux/in.h>
72923+#include <linux/slab.h>
72924+#include <linux/types.h>
72925+#include <linux/sched.h>
72926+#include <linux/timer.h>
72927+#include <linux/gracl.h>
72928+#include <linux/grsecurity.h>
72929+#include <linux/grinternal.h>
72930+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72931+#include <linux/magic.h>
72932+#include <linux/pagemap.h>
72933+#include "../fs/btrfs/async-thread.h"
72934+#include "../fs/btrfs/ctree.h"
72935+#include "../fs/btrfs/btrfs_inode.h"
72936+#endif
72937+
72938+static struct crash_uid *uid_set;
72939+static unsigned short uid_used;
72940+static DEFINE_SPINLOCK(gr_uid_lock);
72941+extern rwlock_t gr_inode_lock;
72942+extern struct acl_subject_label *
72943+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72944+ struct acl_role_label *role);
72945+
72946+static inline dev_t __get_dev(const struct dentry *dentry)
72947+{
72948+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72949+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72950+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72951+ else
72952+#endif
72953+ return dentry->d_sb->s_dev;
72954+}
72955+
72956+int
72957+gr_init_uidset(void)
72958+{
72959+ uid_set =
72960+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72961+ uid_used = 0;
72962+
72963+ return uid_set ? 1 : 0;
72964+}
72965+
72966+void
72967+gr_free_uidset(void)
72968+{
72969+ if (uid_set) {
72970+ struct crash_uid *tmpset;
72971+ spin_lock(&gr_uid_lock);
72972+ tmpset = uid_set;
72973+ uid_set = NULL;
72974+ uid_used = 0;
72975+ spin_unlock(&gr_uid_lock);
72976+ if (tmpset)
72977+ kfree(tmpset);
72978+ }
72979+
72980+ return;
72981+}
72982+
72983+int
72984+gr_find_uid(const uid_t uid)
72985+{
72986+ struct crash_uid *tmp = uid_set;
72987+ uid_t buid;
72988+ int low = 0, high = uid_used - 1, mid;
72989+
72990+ while (high >= low) {
72991+ mid = (low + high) >> 1;
72992+ buid = tmp[mid].uid;
72993+ if (buid == uid)
72994+ return mid;
72995+ if (buid > uid)
72996+ high = mid - 1;
72997+ if (buid < uid)
72998+ low = mid + 1;
72999+ }
73000+
73001+ return -1;
73002+}
73003+
73004+static __inline__ void
73005+gr_insertsort(void)
73006+{
73007+ unsigned short i, j;
73008+ struct crash_uid index;
73009+
73010+ for (i = 1; i < uid_used; i++) {
73011+ index = uid_set[i];
73012+ j = i;
73013+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73014+ uid_set[j] = uid_set[j - 1];
73015+ j--;
73016+ }
73017+ uid_set[j] = index;
73018+ }
73019+
73020+ return;
73021+}
73022+
73023+static __inline__ void
73024+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73025+{
73026+ int loc;
73027+ uid_t uid = GR_GLOBAL_UID(kuid);
73028+
73029+ if (uid_used == GR_UIDTABLE_MAX)
73030+ return;
73031+
73032+ loc = gr_find_uid(uid);
73033+
73034+ if (loc >= 0) {
73035+ uid_set[loc].expires = expires;
73036+ return;
73037+ }
73038+
73039+ uid_set[uid_used].uid = uid;
73040+ uid_set[uid_used].expires = expires;
73041+ uid_used++;
73042+
73043+ gr_insertsort();
73044+
73045+ return;
73046+}
73047+
73048+void
73049+gr_remove_uid(const unsigned short loc)
73050+{
73051+ unsigned short i;
73052+
73053+ for (i = loc + 1; i < uid_used; i++)
73054+ uid_set[i - 1] = uid_set[i];
73055+
73056+ uid_used--;
73057+
73058+ return;
73059+}
73060+
73061+int
73062+gr_check_crash_uid(const kuid_t kuid)
73063+{
73064+ int loc;
73065+ int ret = 0;
73066+ uid_t uid;
73067+
73068+ if (unlikely(!gr_acl_is_enabled()))
73069+ return 0;
73070+
73071+ uid = GR_GLOBAL_UID(kuid);
73072+
73073+ spin_lock(&gr_uid_lock);
73074+ loc = gr_find_uid(uid);
73075+
73076+ if (loc < 0)
73077+ goto out_unlock;
73078+
73079+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73080+ gr_remove_uid(loc);
73081+ else
73082+ ret = 1;
73083+
73084+out_unlock:
73085+ spin_unlock(&gr_uid_lock);
73086+ return ret;
73087+}
73088+
73089+static __inline__ int
73090+proc_is_setxid(const struct cred *cred)
73091+{
73092+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73093+ !uid_eq(cred->uid, cred->fsuid))
73094+ return 1;
73095+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73096+ !gid_eq(cred->gid, cred->fsgid))
73097+ return 1;
73098+
73099+ return 0;
73100+}
73101+
73102+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73103+
73104+void
73105+gr_handle_crash(struct task_struct *task, const int sig)
73106+{
73107+ struct acl_subject_label *curr;
73108+ struct task_struct *tsk, *tsk2;
73109+ const struct cred *cred;
73110+ const struct cred *cred2;
73111+
73112+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73113+ return;
73114+
73115+ if (unlikely(!gr_acl_is_enabled()))
73116+ return;
73117+
73118+ curr = task->acl;
73119+
73120+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73121+ return;
73122+
73123+ if (time_before_eq(curr->expires, get_seconds())) {
73124+ curr->expires = 0;
73125+ curr->crashes = 0;
73126+ }
73127+
73128+ curr->crashes++;
73129+
73130+ if (!curr->expires)
73131+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73132+
73133+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73134+ time_after(curr->expires, get_seconds())) {
73135+ rcu_read_lock();
73136+ cred = __task_cred(task);
73137+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73138+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73139+ spin_lock(&gr_uid_lock);
73140+ gr_insert_uid(cred->uid, curr->expires);
73141+ spin_unlock(&gr_uid_lock);
73142+ curr->expires = 0;
73143+ curr->crashes = 0;
73144+ read_lock(&tasklist_lock);
73145+ do_each_thread(tsk2, tsk) {
73146+ cred2 = __task_cred(tsk);
73147+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73148+ gr_fake_force_sig(SIGKILL, tsk);
73149+ } while_each_thread(tsk2, tsk);
73150+ read_unlock(&tasklist_lock);
73151+ } else {
73152+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73153+ read_lock(&tasklist_lock);
73154+ read_lock(&grsec_exec_file_lock);
73155+ do_each_thread(tsk2, tsk) {
73156+ if (likely(tsk != task)) {
73157+ // if this thread has the same subject as the one that triggered
73158+ // RES_CRASH and it's the same binary, kill it
73159+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73160+ gr_fake_force_sig(SIGKILL, tsk);
73161+ }
73162+ } while_each_thread(tsk2, tsk);
73163+ read_unlock(&grsec_exec_file_lock);
73164+ read_unlock(&tasklist_lock);
73165+ }
73166+ rcu_read_unlock();
73167+ }
73168+
73169+ return;
73170+}
73171+
73172+int
73173+gr_check_crash_exec(const struct file *filp)
73174+{
73175+ struct acl_subject_label *curr;
73176+
73177+ if (unlikely(!gr_acl_is_enabled()))
73178+ return 0;
73179+
73180+ read_lock(&gr_inode_lock);
73181+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73182+ __get_dev(filp->f_path.dentry),
73183+ current->role);
73184+ read_unlock(&gr_inode_lock);
73185+
73186+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73187+ (!curr->crashes && !curr->expires))
73188+ return 0;
73189+
73190+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73191+ time_after(curr->expires, get_seconds()))
73192+ return 1;
73193+ else if (time_before_eq(curr->expires, get_seconds())) {
73194+ curr->crashes = 0;
73195+ curr->expires = 0;
73196+ }
73197+
73198+ return 0;
73199+}
73200+
73201+void
73202+gr_handle_alertkill(struct task_struct *task)
73203+{
73204+ struct acl_subject_label *curracl;
73205+ __u32 curr_ip;
73206+ struct task_struct *p, *p2;
73207+
73208+ if (unlikely(!gr_acl_is_enabled()))
73209+ return;
73210+
73211+ curracl = task->acl;
73212+ curr_ip = task->signal->curr_ip;
73213+
73214+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73215+ read_lock(&tasklist_lock);
73216+ do_each_thread(p2, p) {
73217+ if (p->signal->curr_ip == curr_ip)
73218+ gr_fake_force_sig(SIGKILL, p);
73219+ } while_each_thread(p2, p);
73220+ read_unlock(&tasklist_lock);
73221+ } else if (curracl->mode & GR_KILLPROC)
73222+ gr_fake_force_sig(SIGKILL, task);
73223+
73224+ return;
73225+}
73226diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73227new file mode 100644
73228index 0000000..98011b0
73229--- /dev/null
73230+++ b/grsecurity/gracl_shm.c
73231@@ -0,0 +1,40 @@
73232+#include <linux/kernel.h>
73233+#include <linux/mm.h>
73234+#include <linux/sched.h>
73235+#include <linux/file.h>
73236+#include <linux/ipc.h>
73237+#include <linux/gracl.h>
73238+#include <linux/grsecurity.h>
73239+#include <linux/grinternal.h>
73240+
73241+int
73242+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73243+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73244+{
73245+ struct task_struct *task;
73246+
73247+ if (!gr_acl_is_enabled())
73248+ return 1;
73249+
73250+ rcu_read_lock();
73251+ read_lock(&tasklist_lock);
73252+
73253+ task = find_task_by_vpid(shm_cprid);
73254+
73255+ if (unlikely(!task))
73256+ task = find_task_by_vpid(shm_lapid);
73257+
73258+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73259+ (task_pid_nr(task) == shm_lapid)) &&
73260+ (task->acl->mode & GR_PROTSHM) &&
73261+ (task->acl != current->acl))) {
73262+ read_unlock(&tasklist_lock);
73263+ rcu_read_unlock();
73264+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73265+ return 0;
73266+ }
73267+ read_unlock(&tasklist_lock);
73268+ rcu_read_unlock();
73269+
73270+ return 1;
73271+}
73272diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73273new file mode 100644
73274index 0000000..bc0be01
73275--- /dev/null
73276+++ b/grsecurity/grsec_chdir.c
73277@@ -0,0 +1,19 @@
73278+#include <linux/kernel.h>
73279+#include <linux/sched.h>
73280+#include <linux/fs.h>
73281+#include <linux/file.h>
73282+#include <linux/grsecurity.h>
73283+#include <linux/grinternal.h>
73284+
73285+void
73286+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73287+{
73288+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73289+ if ((grsec_enable_chdir && grsec_enable_group &&
73290+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73291+ !grsec_enable_group)) {
73292+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73293+ }
73294+#endif
73295+ return;
73296+}
73297diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73298new file mode 100644
73299index 0000000..651d6c2
73300--- /dev/null
73301+++ b/grsecurity/grsec_chroot.c
73302@@ -0,0 +1,370 @@
73303+#include <linux/kernel.h>
73304+#include <linux/module.h>
73305+#include <linux/sched.h>
73306+#include <linux/file.h>
73307+#include <linux/fs.h>
73308+#include <linux/mount.h>
73309+#include <linux/types.h>
73310+#include "../fs/mount.h"
73311+#include <linux/grsecurity.h>
73312+#include <linux/grinternal.h>
73313+
73314+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73315+int gr_init_ran;
73316+#endif
73317+
73318+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73319+{
73320+#ifdef CONFIG_GRKERNSEC
73321+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73322+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73323+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73324+ && gr_init_ran
73325+#endif
73326+ )
73327+ task->gr_is_chrooted = 1;
73328+ else {
73329+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73330+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73331+ gr_init_ran = 1;
73332+#endif
73333+ task->gr_is_chrooted = 0;
73334+ }
73335+
73336+ task->gr_chroot_dentry = path->dentry;
73337+#endif
73338+ return;
73339+}
73340+
73341+void gr_clear_chroot_entries(struct task_struct *task)
73342+{
73343+#ifdef CONFIG_GRKERNSEC
73344+ task->gr_is_chrooted = 0;
73345+ task->gr_chroot_dentry = NULL;
73346+#endif
73347+ return;
73348+}
73349+
73350+int
73351+gr_handle_chroot_unix(const pid_t pid)
73352+{
73353+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73354+ struct task_struct *p;
73355+
73356+ if (unlikely(!grsec_enable_chroot_unix))
73357+ return 1;
73358+
73359+ if (likely(!proc_is_chrooted(current)))
73360+ return 1;
73361+
73362+ rcu_read_lock();
73363+ read_lock(&tasklist_lock);
73364+ p = find_task_by_vpid_unrestricted(pid);
73365+ if (unlikely(p && !have_same_root(current, p))) {
73366+ read_unlock(&tasklist_lock);
73367+ rcu_read_unlock();
73368+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73369+ return 0;
73370+ }
73371+ read_unlock(&tasklist_lock);
73372+ rcu_read_unlock();
73373+#endif
73374+ return 1;
73375+}
73376+
73377+int
73378+gr_handle_chroot_nice(void)
73379+{
73380+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73381+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73382+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73383+ return -EPERM;
73384+ }
73385+#endif
73386+ return 0;
73387+}
73388+
73389+int
73390+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73391+{
73392+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73393+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73394+ && proc_is_chrooted(current)) {
73395+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73396+ return -EACCES;
73397+ }
73398+#endif
73399+ return 0;
73400+}
73401+
73402+int
73403+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73404+{
73405+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73406+ struct task_struct *p;
73407+ int ret = 0;
73408+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73409+ return ret;
73410+
73411+ read_lock(&tasklist_lock);
73412+ do_each_pid_task(pid, type, p) {
73413+ if (!have_same_root(current, p)) {
73414+ ret = 1;
73415+ goto out;
73416+ }
73417+ } while_each_pid_task(pid, type, p);
73418+out:
73419+ read_unlock(&tasklist_lock);
73420+ return ret;
73421+#endif
73422+ return 0;
73423+}
73424+
73425+int
73426+gr_pid_is_chrooted(struct task_struct *p)
73427+{
73428+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73429+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73430+ return 0;
73431+
73432+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73433+ !have_same_root(current, p)) {
73434+ return 1;
73435+ }
73436+#endif
73437+ return 0;
73438+}
73439+
73440+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73441+
73442+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73443+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73444+{
73445+ struct path path, currentroot;
73446+ int ret = 0;
73447+
73448+ path.dentry = (struct dentry *)u_dentry;
73449+ path.mnt = (struct vfsmount *)u_mnt;
73450+ get_fs_root(current->fs, &currentroot);
73451+ if (path_is_under(&path, &currentroot))
73452+ ret = 1;
73453+ path_put(&currentroot);
73454+
73455+ return ret;
73456+}
73457+#endif
73458+
73459+int
73460+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73461+{
73462+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73463+ if (!grsec_enable_chroot_fchdir)
73464+ return 1;
73465+
73466+ if (!proc_is_chrooted(current))
73467+ return 1;
73468+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73469+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73470+ return 0;
73471+ }
73472+#endif
73473+ return 1;
73474+}
73475+
73476+int
73477+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73478+ const time_t shm_createtime)
73479+{
73480+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73481+ struct task_struct *p;
73482+ time_t starttime;
73483+
73484+ if (unlikely(!grsec_enable_chroot_shmat))
73485+ return 1;
73486+
73487+ if (likely(!proc_is_chrooted(current)))
73488+ return 1;
73489+
73490+ rcu_read_lock();
73491+ read_lock(&tasklist_lock);
73492+
73493+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73494+ starttime = p->start_time.tv_sec;
73495+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73496+ if (have_same_root(current, p)) {
73497+ goto allow;
73498+ } else {
73499+ read_unlock(&tasklist_lock);
73500+ rcu_read_unlock();
73501+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73502+ return 0;
73503+ }
73504+ }
73505+ /* creator exited, pid reuse, fall through to next check */
73506+ }
73507+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73508+ if (unlikely(!have_same_root(current, p))) {
73509+ read_unlock(&tasklist_lock);
73510+ rcu_read_unlock();
73511+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73512+ return 0;
73513+ }
73514+ }
73515+
73516+allow:
73517+ read_unlock(&tasklist_lock);
73518+ rcu_read_unlock();
73519+#endif
73520+ return 1;
73521+}
73522+
73523+void
73524+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73525+{
73526+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73527+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73528+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73529+#endif
73530+ return;
73531+}
73532+
73533+int
73534+gr_handle_chroot_mknod(const struct dentry *dentry,
73535+ const struct vfsmount *mnt, const int mode)
73536+{
73537+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73538+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73539+ proc_is_chrooted(current)) {
73540+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73541+ return -EPERM;
73542+ }
73543+#endif
73544+ return 0;
73545+}
73546+
73547+int
73548+gr_handle_chroot_mount(const struct dentry *dentry,
73549+ const struct vfsmount *mnt, const char *dev_name)
73550+{
73551+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73552+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73553+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73554+ return -EPERM;
73555+ }
73556+#endif
73557+ return 0;
73558+}
73559+
73560+int
73561+gr_handle_chroot_pivot(void)
73562+{
73563+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73564+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73565+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73566+ return -EPERM;
73567+ }
73568+#endif
73569+ return 0;
73570+}
73571+
73572+int
73573+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73574+{
73575+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73576+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73577+ !gr_is_outside_chroot(dentry, mnt)) {
73578+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73579+ return -EPERM;
73580+ }
73581+#endif
73582+ return 0;
73583+}
73584+
73585+extern const char *captab_log[];
73586+extern int captab_log_entries;
73587+
73588+int
73589+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73590+{
73591+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73592+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73593+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73594+ if (cap_raised(chroot_caps, cap)) {
73595+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73596+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73597+ }
73598+ return 0;
73599+ }
73600+ }
73601+#endif
73602+ return 1;
73603+}
73604+
73605+int
73606+gr_chroot_is_capable(const int cap)
73607+{
73608+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73609+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73610+#endif
73611+ return 1;
73612+}
73613+
73614+int
73615+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73616+{
73617+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73618+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73619+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73620+ if (cap_raised(chroot_caps, cap)) {
73621+ return 0;
73622+ }
73623+ }
73624+#endif
73625+ return 1;
73626+}
73627+
73628+int
73629+gr_chroot_is_capable_nolog(const int cap)
73630+{
73631+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73632+ return gr_task_chroot_is_capable_nolog(current, cap);
73633+#endif
73634+ return 1;
73635+}
73636+
73637+int
73638+gr_handle_chroot_sysctl(const int op)
73639+{
73640+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73641+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73642+ proc_is_chrooted(current))
73643+ return -EACCES;
73644+#endif
73645+ return 0;
73646+}
73647+
73648+void
73649+gr_handle_chroot_chdir(const struct path *path)
73650+{
73651+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73652+ if (grsec_enable_chroot_chdir)
73653+ set_fs_pwd(current->fs, path);
73654+#endif
73655+ return;
73656+}
73657+
73658+int
73659+gr_handle_chroot_chmod(const struct dentry *dentry,
73660+ const struct vfsmount *mnt, const int mode)
73661+{
73662+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73663+ /* allow chmod +s on directories, but not files */
73664+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73665+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73666+ proc_is_chrooted(current)) {
73667+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73668+ return -EPERM;
73669+ }
73670+#endif
73671+ return 0;
73672+}
73673diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73674new file mode 100644
73675index 0000000..4d6fce8
73676--- /dev/null
73677+++ b/grsecurity/grsec_disabled.c
73678@@ -0,0 +1,433 @@
73679+#include <linux/kernel.h>
73680+#include <linux/module.h>
73681+#include <linux/sched.h>
73682+#include <linux/file.h>
73683+#include <linux/fs.h>
73684+#include <linux/kdev_t.h>
73685+#include <linux/net.h>
73686+#include <linux/in.h>
73687+#include <linux/ip.h>
73688+#include <linux/skbuff.h>
73689+#include <linux/sysctl.h>
73690+
73691+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73692+void
73693+pax_set_initial_flags(struct linux_binprm *bprm)
73694+{
73695+ return;
73696+}
73697+#endif
73698+
73699+#ifdef CONFIG_SYSCTL
73700+__u32
73701+gr_handle_sysctl(const struct ctl_table * table, const int op)
73702+{
73703+ return 0;
73704+}
73705+#endif
73706+
73707+#ifdef CONFIG_TASKSTATS
73708+int gr_is_taskstats_denied(int pid)
73709+{
73710+ return 0;
73711+}
73712+#endif
73713+
73714+int
73715+gr_acl_is_enabled(void)
73716+{
73717+ return 0;
73718+}
73719+
73720+void
73721+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73722+{
73723+ return;
73724+}
73725+
73726+int
73727+gr_handle_rawio(const struct inode *inode)
73728+{
73729+ return 0;
73730+}
73731+
73732+void
73733+gr_acl_handle_psacct(struct task_struct *task, const long code)
73734+{
73735+ return;
73736+}
73737+
73738+int
73739+gr_handle_ptrace(struct task_struct *task, const long request)
73740+{
73741+ return 0;
73742+}
73743+
73744+int
73745+gr_handle_proc_ptrace(struct task_struct *task)
73746+{
73747+ return 0;
73748+}
73749+
73750+int
73751+gr_set_acls(const int type)
73752+{
73753+ return 0;
73754+}
73755+
73756+int
73757+gr_check_hidden_task(const struct task_struct *tsk)
73758+{
73759+ return 0;
73760+}
73761+
73762+int
73763+gr_check_protected_task(const struct task_struct *task)
73764+{
73765+ return 0;
73766+}
73767+
73768+int
73769+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73770+{
73771+ return 0;
73772+}
73773+
73774+void
73775+gr_copy_label(struct task_struct *tsk)
73776+{
73777+ return;
73778+}
73779+
73780+void
73781+gr_set_pax_flags(struct task_struct *task)
73782+{
73783+ return;
73784+}
73785+
73786+int
73787+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73788+ const int unsafe_share)
73789+{
73790+ return 0;
73791+}
73792+
73793+void
73794+gr_handle_delete(const ino_t ino, const dev_t dev)
73795+{
73796+ return;
73797+}
73798+
73799+void
73800+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73801+{
73802+ return;
73803+}
73804+
73805+void
73806+gr_handle_crash(struct task_struct *task, const int sig)
73807+{
73808+ return;
73809+}
73810+
73811+int
73812+gr_check_crash_exec(const struct file *filp)
73813+{
73814+ return 0;
73815+}
73816+
73817+int
73818+gr_check_crash_uid(const kuid_t uid)
73819+{
73820+ return 0;
73821+}
73822+
73823+void
73824+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73825+ struct dentry *old_dentry,
73826+ struct dentry *new_dentry,
73827+ struct vfsmount *mnt, const __u8 replace)
73828+{
73829+ return;
73830+}
73831+
73832+int
73833+gr_search_socket(const int family, const int type, const int protocol)
73834+{
73835+ return 1;
73836+}
73837+
73838+int
73839+gr_search_connectbind(const int mode, const struct socket *sock,
73840+ const struct sockaddr_in *addr)
73841+{
73842+ return 0;
73843+}
73844+
73845+void
73846+gr_handle_alertkill(struct task_struct *task)
73847+{
73848+ return;
73849+}
73850+
73851+__u32
73852+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73853+{
73854+ return 1;
73855+}
73856+
73857+__u32
73858+gr_acl_handle_hidden_file(const struct dentry * dentry,
73859+ const struct vfsmount * mnt)
73860+{
73861+ return 1;
73862+}
73863+
73864+__u32
73865+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73866+ int acc_mode)
73867+{
73868+ return 1;
73869+}
73870+
73871+__u32
73872+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73873+{
73874+ return 1;
73875+}
73876+
73877+__u32
73878+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73879+{
73880+ return 1;
73881+}
73882+
73883+int
73884+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73885+ unsigned int *vm_flags)
73886+{
73887+ return 1;
73888+}
73889+
73890+__u32
73891+gr_acl_handle_truncate(const struct dentry * dentry,
73892+ const struct vfsmount * mnt)
73893+{
73894+ return 1;
73895+}
73896+
73897+__u32
73898+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73899+{
73900+ return 1;
73901+}
73902+
73903+__u32
73904+gr_acl_handle_access(const struct dentry * dentry,
73905+ const struct vfsmount * mnt, const int fmode)
73906+{
73907+ return 1;
73908+}
73909+
73910+__u32
73911+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73912+ umode_t *mode)
73913+{
73914+ return 1;
73915+}
73916+
73917+__u32
73918+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73919+{
73920+ return 1;
73921+}
73922+
73923+__u32
73924+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73925+{
73926+ return 1;
73927+}
73928+
73929+__u32
73930+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73931+{
73932+ return 1;
73933+}
73934+
73935+void
73936+grsecurity_init(void)
73937+{
73938+ return;
73939+}
73940+
73941+umode_t gr_acl_umask(void)
73942+{
73943+ return 0;
73944+}
73945+
73946+__u32
73947+gr_acl_handle_mknod(const struct dentry * new_dentry,
73948+ const struct dentry * parent_dentry,
73949+ const struct vfsmount * parent_mnt,
73950+ const int mode)
73951+{
73952+ return 1;
73953+}
73954+
73955+__u32
73956+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73957+ const struct dentry * parent_dentry,
73958+ const struct vfsmount * parent_mnt)
73959+{
73960+ return 1;
73961+}
73962+
73963+__u32
73964+gr_acl_handle_symlink(const struct dentry * new_dentry,
73965+ const struct dentry * parent_dentry,
73966+ const struct vfsmount * parent_mnt, const struct filename *from)
73967+{
73968+ return 1;
73969+}
73970+
73971+__u32
73972+gr_acl_handle_link(const struct dentry * new_dentry,
73973+ const struct dentry * parent_dentry,
73974+ const struct vfsmount * parent_mnt,
73975+ const struct dentry * old_dentry,
73976+ const struct vfsmount * old_mnt, const struct filename *to)
73977+{
73978+ return 1;
73979+}
73980+
73981+int
73982+gr_acl_handle_rename(const struct dentry *new_dentry,
73983+ const struct dentry *parent_dentry,
73984+ const struct vfsmount *parent_mnt,
73985+ const struct dentry *old_dentry,
73986+ const struct inode *old_parent_inode,
73987+ const struct vfsmount *old_mnt, const struct filename *newname)
73988+{
73989+ return 0;
73990+}
73991+
73992+int
73993+gr_acl_handle_filldir(const struct file *file, const char *name,
73994+ const int namelen, const ino_t ino)
73995+{
73996+ return 1;
73997+}
73998+
73999+int
74000+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74001+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74002+{
74003+ return 1;
74004+}
74005+
74006+int
74007+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74008+{
74009+ return 0;
74010+}
74011+
74012+int
74013+gr_search_accept(const struct socket *sock)
74014+{
74015+ return 0;
74016+}
74017+
74018+int
74019+gr_search_listen(const struct socket *sock)
74020+{
74021+ return 0;
74022+}
74023+
74024+int
74025+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74026+{
74027+ return 0;
74028+}
74029+
74030+__u32
74031+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74032+{
74033+ return 1;
74034+}
74035+
74036+__u32
74037+gr_acl_handle_creat(const struct dentry * dentry,
74038+ const struct dentry * p_dentry,
74039+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74040+ const int imode)
74041+{
74042+ return 1;
74043+}
74044+
74045+void
74046+gr_acl_handle_exit(void)
74047+{
74048+ return;
74049+}
74050+
74051+int
74052+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74053+{
74054+ return 1;
74055+}
74056+
74057+void
74058+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74059+{
74060+ return;
74061+}
74062+
74063+int
74064+gr_acl_handle_procpidmem(const struct task_struct *task)
74065+{
74066+ return 0;
74067+}
74068+
74069+int
74070+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74071+{
74072+ return 0;
74073+}
74074+
74075+int
74076+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74077+{
74078+ return 0;
74079+}
74080+
74081+int
74082+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74083+{
74084+ return 0;
74085+}
74086+
74087+int
74088+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74089+{
74090+ return 0;
74091+}
74092+
74093+int gr_acl_enable_at_secure(void)
74094+{
74095+ return 0;
74096+}
74097+
74098+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74099+{
74100+ return dentry->d_sb->s_dev;
74101+}
74102+
74103+void gr_put_exec_file(struct task_struct *task)
74104+{
74105+ return;
74106+}
74107+
74108+#ifdef CONFIG_SECURITY
74109+EXPORT_SYMBOL_GPL(gr_check_user_change);
74110+EXPORT_SYMBOL_GPL(gr_check_group_change);
74111+#endif
74112diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74113new file mode 100644
74114index 0000000..f35f454
74115--- /dev/null
74116+++ b/grsecurity/grsec_exec.c
74117@@ -0,0 +1,187 @@
74118+#include <linux/kernel.h>
74119+#include <linux/sched.h>
74120+#include <linux/file.h>
74121+#include <linux/binfmts.h>
74122+#include <linux/fs.h>
74123+#include <linux/types.h>
74124+#include <linux/grdefs.h>
74125+#include <linux/grsecurity.h>
74126+#include <linux/grinternal.h>
74127+#include <linux/capability.h>
74128+#include <linux/module.h>
74129+#include <linux/compat.h>
74130+
74131+#include <asm/uaccess.h>
74132+
74133+#ifdef CONFIG_GRKERNSEC_EXECLOG
74134+static char gr_exec_arg_buf[132];
74135+static DEFINE_MUTEX(gr_exec_arg_mutex);
74136+#endif
74137+
74138+struct user_arg_ptr {
74139+#ifdef CONFIG_COMPAT
74140+ bool is_compat;
74141+#endif
74142+ union {
74143+ const char __user *const __user *native;
74144+#ifdef CONFIG_COMPAT
74145+ const compat_uptr_t __user *compat;
74146+#endif
74147+ } ptr;
74148+};
74149+
74150+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74151+
74152+void
74153+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74154+{
74155+#ifdef CONFIG_GRKERNSEC_EXECLOG
74156+ char *grarg = gr_exec_arg_buf;
74157+ unsigned int i, x, execlen = 0;
74158+ char c;
74159+
74160+ if (!((grsec_enable_execlog && grsec_enable_group &&
74161+ in_group_p(grsec_audit_gid))
74162+ || (grsec_enable_execlog && !grsec_enable_group)))
74163+ return;
74164+
74165+ mutex_lock(&gr_exec_arg_mutex);
74166+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74167+
74168+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74169+ const char __user *p;
74170+ unsigned int len;
74171+
74172+ p = get_user_arg_ptr(argv, i);
74173+ if (IS_ERR(p))
74174+ goto log;
74175+
74176+ len = strnlen_user(p, 128 - execlen);
74177+ if (len > 128 - execlen)
74178+ len = 128 - execlen;
74179+ else if (len > 0)
74180+ len--;
74181+ if (copy_from_user(grarg + execlen, p, len))
74182+ goto log;
74183+
74184+ /* rewrite unprintable characters */
74185+ for (x = 0; x < len; x++) {
74186+ c = *(grarg + execlen + x);
74187+ if (c < 32 || c > 126)
74188+ *(grarg + execlen + x) = ' ';
74189+ }
74190+
74191+ execlen += len;
74192+ *(grarg + execlen) = ' ';
74193+ *(grarg + execlen + 1) = '\0';
74194+ execlen++;
74195+ }
74196+
74197+ log:
74198+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74199+ bprm->file->f_path.mnt, grarg);
74200+ mutex_unlock(&gr_exec_arg_mutex);
74201+#endif
74202+ return;
74203+}
74204+
74205+#ifdef CONFIG_GRKERNSEC
74206+extern int gr_acl_is_capable(const int cap);
74207+extern int gr_acl_is_capable_nolog(const int cap);
74208+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74209+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74210+extern int gr_chroot_is_capable(const int cap);
74211+extern int gr_chroot_is_capable_nolog(const int cap);
74212+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74213+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74214+#endif
74215+
74216+const char *captab_log[] = {
74217+ "CAP_CHOWN",
74218+ "CAP_DAC_OVERRIDE",
74219+ "CAP_DAC_READ_SEARCH",
74220+ "CAP_FOWNER",
74221+ "CAP_FSETID",
74222+ "CAP_KILL",
74223+ "CAP_SETGID",
74224+ "CAP_SETUID",
74225+ "CAP_SETPCAP",
74226+ "CAP_LINUX_IMMUTABLE",
74227+ "CAP_NET_BIND_SERVICE",
74228+ "CAP_NET_BROADCAST",
74229+ "CAP_NET_ADMIN",
74230+ "CAP_NET_RAW",
74231+ "CAP_IPC_LOCK",
74232+ "CAP_IPC_OWNER",
74233+ "CAP_SYS_MODULE",
74234+ "CAP_SYS_RAWIO",
74235+ "CAP_SYS_CHROOT",
74236+ "CAP_SYS_PTRACE",
74237+ "CAP_SYS_PACCT",
74238+ "CAP_SYS_ADMIN",
74239+ "CAP_SYS_BOOT",
74240+ "CAP_SYS_NICE",
74241+ "CAP_SYS_RESOURCE",
74242+ "CAP_SYS_TIME",
74243+ "CAP_SYS_TTY_CONFIG",
74244+ "CAP_MKNOD",
74245+ "CAP_LEASE",
74246+ "CAP_AUDIT_WRITE",
74247+ "CAP_AUDIT_CONTROL",
74248+ "CAP_SETFCAP",
74249+ "CAP_MAC_OVERRIDE",
74250+ "CAP_MAC_ADMIN",
74251+ "CAP_SYSLOG",
74252+ "CAP_WAKE_ALARM"
74253+};
74254+
74255+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74256+
74257+int gr_is_capable(const int cap)
74258+{
74259+#ifdef CONFIG_GRKERNSEC
74260+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74261+ return 1;
74262+ return 0;
74263+#else
74264+ return 1;
74265+#endif
74266+}
74267+
74268+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74269+{
74270+#ifdef CONFIG_GRKERNSEC
74271+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74272+ return 1;
74273+ return 0;
74274+#else
74275+ return 1;
74276+#endif
74277+}
74278+
74279+int gr_is_capable_nolog(const int cap)
74280+{
74281+#ifdef CONFIG_GRKERNSEC
74282+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74283+ return 1;
74284+ return 0;
74285+#else
74286+ return 1;
74287+#endif
74288+}
74289+
74290+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74291+{
74292+#ifdef CONFIG_GRKERNSEC
74293+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74294+ return 1;
74295+ return 0;
74296+#else
74297+ return 1;
74298+#endif
74299+}
74300+
74301+EXPORT_SYMBOL_GPL(gr_is_capable);
74302+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74303+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74304+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74305diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74306new file mode 100644
74307index 0000000..06cc6ea
74308--- /dev/null
74309+++ b/grsecurity/grsec_fifo.c
74310@@ -0,0 +1,24 @@
74311+#include <linux/kernel.h>
74312+#include <linux/sched.h>
74313+#include <linux/fs.h>
74314+#include <linux/file.h>
74315+#include <linux/grinternal.h>
74316+
74317+int
74318+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74319+ const struct dentry *dir, const int flag, const int acc_mode)
74320+{
74321+#ifdef CONFIG_GRKERNSEC_FIFO
74322+ const struct cred *cred = current_cred();
74323+
74324+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74325+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74326+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74327+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74328+ if (!inode_permission(dentry->d_inode, acc_mode))
74329+ 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));
74330+ return -EACCES;
74331+ }
74332+#endif
74333+ return 0;
74334+}
74335diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74336new file mode 100644
74337index 0000000..8ca18bf
74338--- /dev/null
74339+++ b/grsecurity/grsec_fork.c
74340@@ -0,0 +1,23 @@
74341+#include <linux/kernel.h>
74342+#include <linux/sched.h>
74343+#include <linux/grsecurity.h>
74344+#include <linux/grinternal.h>
74345+#include <linux/errno.h>
74346+
74347+void
74348+gr_log_forkfail(const int retval)
74349+{
74350+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74351+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74352+ switch (retval) {
74353+ case -EAGAIN:
74354+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74355+ break;
74356+ case -ENOMEM:
74357+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74358+ break;
74359+ }
74360+ }
74361+#endif
74362+ return;
74363+}
74364diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74365new file mode 100644
74366index 0000000..ae6c028
74367--- /dev/null
74368+++ b/grsecurity/grsec_init.c
74369@@ -0,0 +1,272 @@
74370+#include <linux/kernel.h>
74371+#include <linux/sched.h>
74372+#include <linux/mm.h>
74373+#include <linux/gracl.h>
74374+#include <linux/slab.h>
74375+#include <linux/vmalloc.h>
74376+#include <linux/percpu.h>
74377+#include <linux/module.h>
74378+
74379+int grsec_enable_ptrace_readexec;
74380+int grsec_enable_setxid;
74381+int grsec_enable_symlinkown;
74382+kgid_t grsec_symlinkown_gid;
74383+int grsec_enable_brute;
74384+int grsec_enable_link;
74385+int grsec_enable_dmesg;
74386+int grsec_enable_harden_ptrace;
74387+int grsec_enable_harden_ipc;
74388+int grsec_enable_fifo;
74389+int grsec_enable_execlog;
74390+int grsec_enable_signal;
74391+int grsec_enable_forkfail;
74392+int grsec_enable_audit_ptrace;
74393+int grsec_enable_time;
74394+int grsec_enable_group;
74395+kgid_t grsec_audit_gid;
74396+int grsec_enable_chdir;
74397+int grsec_enable_mount;
74398+int grsec_enable_rofs;
74399+int grsec_deny_new_usb;
74400+int grsec_enable_chroot_findtask;
74401+int grsec_enable_chroot_mount;
74402+int grsec_enable_chroot_shmat;
74403+int grsec_enable_chroot_fchdir;
74404+int grsec_enable_chroot_double;
74405+int grsec_enable_chroot_pivot;
74406+int grsec_enable_chroot_chdir;
74407+int grsec_enable_chroot_chmod;
74408+int grsec_enable_chroot_mknod;
74409+int grsec_enable_chroot_nice;
74410+int grsec_enable_chroot_execlog;
74411+int grsec_enable_chroot_caps;
74412+int grsec_enable_chroot_sysctl;
74413+int grsec_enable_chroot_unix;
74414+int grsec_enable_tpe;
74415+kgid_t grsec_tpe_gid;
74416+int grsec_enable_blackhole;
74417+#ifdef CONFIG_IPV6_MODULE
74418+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74419+#endif
74420+int grsec_lastack_retries;
74421+int grsec_enable_tpe_all;
74422+int grsec_enable_tpe_invert;
74423+int grsec_enable_socket_all;
74424+kgid_t grsec_socket_all_gid;
74425+int grsec_enable_socket_client;
74426+kgid_t grsec_socket_client_gid;
74427+int grsec_enable_socket_server;
74428+kgid_t grsec_socket_server_gid;
74429+int grsec_resource_logging;
74430+int grsec_disable_privio;
74431+int grsec_enable_log_rwxmaps;
74432+int grsec_lock;
74433+
74434+DEFINE_SPINLOCK(grsec_alert_lock);
74435+unsigned long grsec_alert_wtime = 0;
74436+unsigned long grsec_alert_fyet = 0;
74437+
74438+DEFINE_SPINLOCK(grsec_audit_lock);
74439+
74440+DEFINE_RWLOCK(grsec_exec_file_lock);
74441+
74442+char *gr_shared_page[4];
74443+
74444+char *gr_alert_log_fmt;
74445+char *gr_audit_log_fmt;
74446+char *gr_alert_log_buf;
74447+char *gr_audit_log_buf;
74448+
74449+void __init
74450+grsecurity_init(void)
74451+{
74452+ int j;
74453+ /* create the per-cpu shared pages */
74454+
74455+#ifdef CONFIG_X86
74456+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74457+#endif
74458+
74459+ for (j = 0; j < 4; j++) {
74460+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74461+ if (gr_shared_page[j] == NULL) {
74462+ panic("Unable to allocate grsecurity shared page");
74463+ return;
74464+ }
74465+ }
74466+
74467+ /* allocate log buffers */
74468+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74469+ if (!gr_alert_log_fmt) {
74470+ panic("Unable to allocate grsecurity alert log format buffer");
74471+ return;
74472+ }
74473+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74474+ if (!gr_audit_log_fmt) {
74475+ panic("Unable to allocate grsecurity audit log format buffer");
74476+ return;
74477+ }
74478+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74479+ if (!gr_alert_log_buf) {
74480+ panic("Unable to allocate grsecurity alert log buffer");
74481+ return;
74482+ }
74483+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74484+ if (!gr_audit_log_buf) {
74485+ panic("Unable to allocate grsecurity audit log buffer");
74486+ return;
74487+ }
74488+
74489+#ifdef CONFIG_GRKERNSEC_IO
74490+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74491+ grsec_disable_privio = 1;
74492+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74493+ grsec_disable_privio = 1;
74494+#else
74495+ grsec_disable_privio = 0;
74496+#endif
74497+#endif
74498+
74499+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74500+ /* for backward compatibility, tpe_invert always defaults to on if
74501+ enabled in the kernel
74502+ */
74503+ grsec_enable_tpe_invert = 1;
74504+#endif
74505+
74506+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74507+#ifndef CONFIG_GRKERNSEC_SYSCTL
74508+ grsec_lock = 1;
74509+#endif
74510+
74511+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74512+ grsec_enable_log_rwxmaps = 1;
74513+#endif
74514+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74515+ grsec_enable_group = 1;
74516+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74517+#endif
74518+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74519+ grsec_enable_ptrace_readexec = 1;
74520+#endif
74521+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74522+ grsec_enable_chdir = 1;
74523+#endif
74524+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74525+ grsec_enable_harden_ptrace = 1;
74526+#endif
74527+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74528+ grsec_enable_harden_ipc = 1;
74529+#endif
74530+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74531+ grsec_enable_mount = 1;
74532+#endif
74533+#ifdef CONFIG_GRKERNSEC_LINK
74534+ grsec_enable_link = 1;
74535+#endif
74536+#ifdef CONFIG_GRKERNSEC_BRUTE
74537+ grsec_enable_brute = 1;
74538+#endif
74539+#ifdef CONFIG_GRKERNSEC_DMESG
74540+ grsec_enable_dmesg = 1;
74541+#endif
74542+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74543+ grsec_enable_blackhole = 1;
74544+ grsec_lastack_retries = 4;
74545+#endif
74546+#ifdef CONFIG_GRKERNSEC_FIFO
74547+ grsec_enable_fifo = 1;
74548+#endif
74549+#ifdef CONFIG_GRKERNSEC_EXECLOG
74550+ grsec_enable_execlog = 1;
74551+#endif
74552+#ifdef CONFIG_GRKERNSEC_SETXID
74553+ grsec_enable_setxid = 1;
74554+#endif
74555+#ifdef CONFIG_GRKERNSEC_SIGNAL
74556+ grsec_enable_signal = 1;
74557+#endif
74558+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74559+ grsec_enable_forkfail = 1;
74560+#endif
74561+#ifdef CONFIG_GRKERNSEC_TIME
74562+ grsec_enable_time = 1;
74563+#endif
74564+#ifdef CONFIG_GRKERNSEC_RESLOG
74565+ grsec_resource_logging = 1;
74566+#endif
74567+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74568+ grsec_enable_chroot_findtask = 1;
74569+#endif
74570+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74571+ grsec_enable_chroot_unix = 1;
74572+#endif
74573+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74574+ grsec_enable_chroot_mount = 1;
74575+#endif
74576+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74577+ grsec_enable_chroot_fchdir = 1;
74578+#endif
74579+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74580+ grsec_enable_chroot_shmat = 1;
74581+#endif
74582+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74583+ grsec_enable_audit_ptrace = 1;
74584+#endif
74585+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74586+ grsec_enable_chroot_double = 1;
74587+#endif
74588+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74589+ grsec_enable_chroot_pivot = 1;
74590+#endif
74591+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74592+ grsec_enable_chroot_chdir = 1;
74593+#endif
74594+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74595+ grsec_enable_chroot_chmod = 1;
74596+#endif
74597+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74598+ grsec_enable_chroot_mknod = 1;
74599+#endif
74600+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74601+ grsec_enable_chroot_nice = 1;
74602+#endif
74603+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74604+ grsec_enable_chroot_execlog = 1;
74605+#endif
74606+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74607+ grsec_enable_chroot_caps = 1;
74608+#endif
74609+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74610+ grsec_enable_chroot_sysctl = 1;
74611+#endif
74612+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74613+ grsec_enable_symlinkown = 1;
74614+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74615+#endif
74616+#ifdef CONFIG_GRKERNSEC_TPE
74617+ grsec_enable_tpe = 1;
74618+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74619+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74620+ grsec_enable_tpe_all = 1;
74621+#endif
74622+#endif
74623+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74624+ grsec_enable_socket_all = 1;
74625+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74626+#endif
74627+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74628+ grsec_enable_socket_client = 1;
74629+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74630+#endif
74631+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74632+ grsec_enable_socket_server = 1;
74633+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74634+#endif
74635+#endif
74636+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74637+ grsec_deny_new_usb = 1;
74638+#endif
74639+
74640+ return;
74641+}
74642diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74643new file mode 100644
74644index 0000000..1773300
74645--- /dev/null
74646+++ b/grsecurity/grsec_ipc.c
74647@@ -0,0 +1,48 @@
74648+#include <linux/kernel.h>
74649+#include <linux/mm.h>
74650+#include <linux/sched.h>
74651+#include <linux/file.h>
74652+#include <linux/ipc.h>
74653+#include <linux/ipc_namespace.h>
74654+#include <linux/grsecurity.h>
74655+#include <linux/grinternal.h>
74656+
74657+int
74658+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74659+{
74660+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74661+ int write;
74662+ int orig_granted_mode;
74663+ kuid_t euid;
74664+ kgid_t egid;
74665+
74666+ if (!grsec_enable_harden_ipc)
74667+ return 1;
74668+
74669+ euid = current_euid();
74670+ egid = current_egid();
74671+
74672+ write = requested_mode & 00002;
74673+ orig_granted_mode = ipcp->mode;
74674+
74675+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74676+ orig_granted_mode >>= 6;
74677+ else {
74678+ /* if likely wrong permissions, lock to user */
74679+ if (orig_granted_mode & 0007)
74680+ orig_granted_mode = 0;
74681+ /* otherwise do a egid-only check */
74682+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74683+ orig_granted_mode >>= 3;
74684+ /* otherwise, no access */
74685+ else
74686+ orig_granted_mode = 0;
74687+ }
74688+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74689+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74690+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74691+ return 0;
74692+ }
74693+#endif
74694+ return 1;
74695+}
74696diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74697new file mode 100644
74698index 0000000..5e05e20
74699--- /dev/null
74700+++ b/grsecurity/grsec_link.c
74701@@ -0,0 +1,58 @@
74702+#include <linux/kernel.h>
74703+#include <linux/sched.h>
74704+#include <linux/fs.h>
74705+#include <linux/file.h>
74706+#include <linux/grinternal.h>
74707+
74708+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74709+{
74710+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74711+ const struct inode *link_inode = link->dentry->d_inode;
74712+
74713+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74714+ /* ignore root-owned links, e.g. /proc/self */
74715+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74716+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74717+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74718+ return 1;
74719+ }
74720+#endif
74721+ return 0;
74722+}
74723+
74724+int
74725+gr_handle_follow_link(const struct inode *parent,
74726+ const struct inode *inode,
74727+ const struct dentry *dentry, const struct vfsmount *mnt)
74728+{
74729+#ifdef CONFIG_GRKERNSEC_LINK
74730+ const struct cred *cred = current_cred();
74731+
74732+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74733+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74734+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74735+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74736+ return -EACCES;
74737+ }
74738+#endif
74739+ return 0;
74740+}
74741+
74742+int
74743+gr_handle_hardlink(const struct dentry *dentry,
74744+ const struct vfsmount *mnt,
74745+ struct inode *inode, const int mode, const struct filename *to)
74746+{
74747+#ifdef CONFIG_GRKERNSEC_LINK
74748+ const struct cred *cred = current_cred();
74749+
74750+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74751+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74752+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74753+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74754+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74755+ return -EPERM;
74756+ }
74757+#endif
74758+ return 0;
74759+}
74760diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74761new file mode 100644
74762index 0000000..dbe0a6b
74763--- /dev/null
74764+++ b/grsecurity/grsec_log.c
74765@@ -0,0 +1,341 @@
74766+#include <linux/kernel.h>
74767+#include <linux/sched.h>
74768+#include <linux/file.h>
74769+#include <linux/tty.h>
74770+#include <linux/fs.h>
74771+#include <linux/mm.h>
74772+#include <linux/grinternal.h>
74773+
74774+#ifdef CONFIG_TREE_PREEMPT_RCU
74775+#define DISABLE_PREEMPT() preempt_disable()
74776+#define ENABLE_PREEMPT() preempt_enable()
74777+#else
74778+#define DISABLE_PREEMPT()
74779+#define ENABLE_PREEMPT()
74780+#endif
74781+
74782+#define BEGIN_LOCKS(x) \
74783+ DISABLE_PREEMPT(); \
74784+ rcu_read_lock(); \
74785+ read_lock(&tasklist_lock); \
74786+ read_lock(&grsec_exec_file_lock); \
74787+ if (x != GR_DO_AUDIT) \
74788+ spin_lock(&grsec_alert_lock); \
74789+ else \
74790+ spin_lock(&grsec_audit_lock)
74791+
74792+#define END_LOCKS(x) \
74793+ if (x != GR_DO_AUDIT) \
74794+ spin_unlock(&grsec_alert_lock); \
74795+ else \
74796+ spin_unlock(&grsec_audit_lock); \
74797+ read_unlock(&grsec_exec_file_lock); \
74798+ read_unlock(&tasklist_lock); \
74799+ rcu_read_unlock(); \
74800+ ENABLE_PREEMPT(); \
74801+ if (x == GR_DONT_AUDIT) \
74802+ gr_handle_alertkill(current)
74803+
74804+enum {
74805+ FLOODING,
74806+ NO_FLOODING
74807+};
74808+
74809+extern char *gr_alert_log_fmt;
74810+extern char *gr_audit_log_fmt;
74811+extern char *gr_alert_log_buf;
74812+extern char *gr_audit_log_buf;
74813+
74814+static int gr_log_start(int audit)
74815+{
74816+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74817+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74818+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74819+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74820+ unsigned long curr_secs = get_seconds();
74821+
74822+ if (audit == GR_DO_AUDIT)
74823+ goto set_fmt;
74824+
74825+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74826+ grsec_alert_wtime = curr_secs;
74827+ grsec_alert_fyet = 0;
74828+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74829+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74830+ grsec_alert_fyet++;
74831+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74832+ grsec_alert_wtime = curr_secs;
74833+ grsec_alert_fyet++;
74834+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74835+ return FLOODING;
74836+ }
74837+ else return FLOODING;
74838+
74839+set_fmt:
74840+#endif
74841+ memset(buf, 0, PAGE_SIZE);
74842+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74843+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74844+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74845+ } else if (current->signal->curr_ip) {
74846+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74847+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74848+ } else if (gr_acl_is_enabled()) {
74849+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74850+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74851+ } else {
74852+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74853+ strcpy(buf, fmt);
74854+ }
74855+
74856+ return NO_FLOODING;
74857+}
74858+
74859+static void gr_log_middle(int audit, const char *msg, va_list ap)
74860+ __attribute__ ((format (printf, 2, 0)));
74861+
74862+static void gr_log_middle(int audit, const char *msg, va_list ap)
74863+{
74864+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74865+ unsigned int len = strlen(buf);
74866+
74867+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74868+
74869+ return;
74870+}
74871+
74872+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74873+ __attribute__ ((format (printf, 2, 3)));
74874+
74875+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74876+{
74877+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74878+ unsigned int len = strlen(buf);
74879+ va_list ap;
74880+
74881+ va_start(ap, msg);
74882+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74883+ va_end(ap);
74884+
74885+ return;
74886+}
74887+
74888+static void gr_log_end(int audit, int append_default)
74889+{
74890+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74891+ if (append_default) {
74892+ struct task_struct *task = current;
74893+ struct task_struct *parent = task->real_parent;
74894+ const struct cred *cred = __task_cred(task);
74895+ const struct cred *pcred = __task_cred(parent);
74896+ unsigned int len = strlen(buf);
74897+
74898+ 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));
74899+ }
74900+
74901+ printk("%s\n", buf);
74902+
74903+ return;
74904+}
74905+
74906+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74907+{
74908+ int logtype;
74909+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74910+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74911+ void *voidptr = NULL;
74912+ int num1 = 0, num2 = 0;
74913+ unsigned long ulong1 = 0, ulong2 = 0;
74914+ struct dentry *dentry = NULL;
74915+ struct vfsmount *mnt = NULL;
74916+ struct file *file = NULL;
74917+ struct task_struct *task = NULL;
74918+ struct vm_area_struct *vma = NULL;
74919+ const struct cred *cred, *pcred;
74920+ va_list ap;
74921+
74922+ BEGIN_LOCKS(audit);
74923+ logtype = gr_log_start(audit);
74924+ if (logtype == FLOODING) {
74925+ END_LOCKS(audit);
74926+ return;
74927+ }
74928+ va_start(ap, argtypes);
74929+ switch (argtypes) {
74930+ case GR_TTYSNIFF:
74931+ task = va_arg(ap, struct task_struct *);
74932+ 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));
74933+ break;
74934+ case GR_SYSCTL_HIDDEN:
74935+ str1 = va_arg(ap, char *);
74936+ gr_log_middle_varargs(audit, msg, result, str1);
74937+ break;
74938+ case GR_RBAC:
74939+ dentry = va_arg(ap, struct dentry *);
74940+ mnt = va_arg(ap, struct vfsmount *);
74941+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74942+ break;
74943+ case GR_RBAC_STR:
74944+ dentry = va_arg(ap, struct dentry *);
74945+ mnt = va_arg(ap, struct vfsmount *);
74946+ str1 = va_arg(ap, char *);
74947+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74948+ break;
74949+ case GR_STR_RBAC:
74950+ str1 = va_arg(ap, char *);
74951+ dentry = va_arg(ap, struct dentry *);
74952+ mnt = va_arg(ap, struct vfsmount *);
74953+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74954+ break;
74955+ case GR_RBAC_MODE2:
74956+ dentry = va_arg(ap, struct dentry *);
74957+ mnt = va_arg(ap, struct vfsmount *);
74958+ str1 = va_arg(ap, char *);
74959+ str2 = va_arg(ap, char *);
74960+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74961+ break;
74962+ case GR_RBAC_MODE3:
74963+ dentry = va_arg(ap, struct dentry *);
74964+ mnt = va_arg(ap, struct vfsmount *);
74965+ str1 = va_arg(ap, char *);
74966+ str2 = va_arg(ap, char *);
74967+ str3 = va_arg(ap, char *);
74968+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74969+ break;
74970+ case GR_FILENAME:
74971+ dentry = va_arg(ap, struct dentry *);
74972+ mnt = va_arg(ap, struct vfsmount *);
74973+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74974+ break;
74975+ case GR_STR_FILENAME:
74976+ str1 = va_arg(ap, char *);
74977+ dentry = va_arg(ap, struct dentry *);
74978+ mnt = va_arg(ap, struct vfsmount *);
74979+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74980+ break;
74981+ case GR_FILENAME_STR:
74982+ dentry = va_arg(ap, struct dentry *);
74983+ mnt = va_arg(ap, struct vfsmount *);
74984+ str1 = va_arg(ap, char *);
74985+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74986+ break;
74987+ case GR_FILENAME_TWO_INT:
74988+ dentry = va_arg(ap, struct dentry *);
74989+ mnt = va_arg(ap, struct vfsmount *);
74990+ num1 = va_arg(ap, int);
74991+ num2 = va_arg(ap, int);
74992+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74993+ break;
74994+ case GR_FILENAME_TWO_INT_STR:
74995+ dentry = va_arg(ap, struct dentry *);
74996+ mnt = va_arg(ap, struct vfsmount *);
74997+ num1 = va_arg(ap, int);
74998+ num2 = va_arg(ap, int);
74999+ str1 = va_arg(ap, char *);
75000+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75001+ break;
75002+ case GR_TEXTREL:
75003+ file = va_arg(ap, struct file *);
75004+ ulong1 = va_arg(ap, unsigned long);
75005+ ulong2 = va_arg(ap, unsigned long);
75006+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75007+ break;
75008+ case GR_PTRACE:
75009+ task = va_arg(ap, struct task_struct *);
75010+ 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));
75011+ break;
75012+ case GR_RESOURCE:
75013+ task = va_arg(ap, struct task_struct *);
75014+ cred = __task_cred(task);
75015+ pcred = __task_cred(task->real_parent);
75016+ ulong1 = va_arg(ap, unsigned long);
75017+ str1 = va_arg(ap, char *);
75018+ ulong2 = va_arg(ap, unsigned long);
75019+ 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));
75020+ break;
75021+ case GR_CAP:
75022+ task = va_arg(ap, struct task_struct *);
75023+ cred = __task_cred(task);
75024+ pcred = __task_cred(task->real_parent);
75025+ str1 = va_arg(ap, char *);
75026+ 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));
75027+ break;
75028+ case GR_SIG:
75029+ str1 = va_arg(ap, char *);
75030+ voidptr = va_arg(ap, void *);
75031+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75032+ break;
75033+ case GR_SIG2:
75034+ task = va_arg(ap, struct task_struct *);
75035+ cred = __task_cred(task);
75036+ pcred = __task_cred(task->real_parent);
75037+ num1 = va_arg(ap, int);
75038+ 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));
75039+ break;
75040+ case GR_CRASH1:
75041+ task = va_arg(ap, struct task_struct *);
75042+ cred = __task_cred(task);
75043+ pcred = __task_cred(task->real_parent);
75044+ ulong1 = va_arg(ap, unsigned long);
75045+ 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);
75046+ break;
75047+ case GR_CRASH2:
75048+ task = va_arg(ap, struct task_struct *);
75049+ cred = __task_cred(task);
75050+ pcred = __task_cred(task->real_parent);
75051+ ulong1 = va_arg(ap, unsigned long);
75052+ 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);
75053+ break;
75054+ case GR_RWXMAP:
75055+ file = va_arg(ap, struct file *);
75056+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75057+ break;
75058+ case GR_RWXMAPVMA:
75059+ vma = va_arg(ap, struct vm_area_struct *);
75060+ if (vma->vm_file)
75061+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75062+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75063+ str1 = "<stack>";
75064+ else if (vma->vm_start <= current->mm->brk &&
75065+ vma->vm_end >= current->mm->start_brk)
75066+ str1 = "<heap>";
75067+ else
75068+ str1 = "<anonymous mapping>";
75069+ gr_log_middle_varargs(audit, msg, str1);
75070+ break;
75071+ case GR_PSACCT:
75072+ {
75073+ unsigned int wday, cday;
75074+ __u8 whr, chr;
75075+ __u8 wmin, cmin;
75076+ __u8 wsec, csec;
75077+ char cur_tty[64] = { 0 };
75078+ char parent_tty[64] = { 0 };
75079+
75080+ task = va_arg(ap, struct task_struct *);
75081+ wday = va_arg(ap, unsigned int);
75082+ cday = va_arg(ap, unsigned int);
75083+ whr = va_arg(ap, int);
75084+ chr = va_arg(ap, int);
75085+ wmin = va_arg(ap, int);
75086+ cmin = va_arg(ap, int);
75087+ wsec = va_arg(ap, int);
75088+ csec = va_arg(ap, int);
75089+ ulong1 = va_arg(ap, unsigned long);
75090+ cred = __task_cred(task);
75091+ pcred = __task_cred(task->real_parent);
75092+
75093+ 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));
75094+ }
75095+ break;
75096+ default:
75097+ gr_log_middle(audit, msg, ap);
75098+ }
75099+ va_end(ap);
75100+ // these don't need DEFAULTSECARGS printed on the end
75101+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75102+ gr_log_end(audit, 0);
75103+ else
75104+ gr_log_end(audit, 1);
75105+ END_LOCKS(audit);
75106+}
75107diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75108new file mode 100644
75109index 0000000..0e39d8c
75110--- /dev/null
75111+++ b/grsecurity/grsec_mem.c
75112@@ -0,0 +1,48 @@
75113+#include <linux/kernel.h>
75114+#include <linux/sched.h>
75115+#include <linux/mm.h>
75116+#include <linux/mman.h>
75117+#include <linux/module.h>
75118+#include <linux/grinternal.h>
75119+
75120+void gr_handle_msr_write(void)
75121+{
75122+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75123+ return;
75124+}
75125+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75126+
75127+void
75128+gr_handle_ioperm(void)
75129+{
75130+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75131+ return;
75132+}
75133+
75134+void
75135+gr_handle_iopl(void)
75136+{
75137+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75138+ return;
75139+}
75140+
75141+void
75142+gr_handle_mem_readwrite(u64 from, u64 to)
75143+{
75144+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75145+ return;
75146+}
75147+
75148+void
75149+gr_handle_vm86(void)
75150+{
75151+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75152+ return;
75153+}
75154+
75155+void
75156+gr_log_badprocpid(const char *entry)
75157+{
75158+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75159+ return;
75160+}
75161diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75162new file mode 100644
75163index 0000000..cd9e124
75164--- /dev/null
75165+++ b/grsecurity/grsec_mount.c
75166@@ -0,0 +1,65 @@
75167+#include <linux/kernel.h>
75168+#include <linux/sched.h>
75169+#include <linux/mount.h>
75170+#include <linux/major.h>
75171+#include <linux/grsecurity.h>
75172+#include <linux/grinternal.h>
75173+
75174+void
75175+gr_log_remount(const char *devname, const int retval)
75176+{
75177+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75178+ if (grsec_enable_mount && (retval >= 0))
75179+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75180+#endif
75181+ return;
75182+}
75183+
75184+void
75185+gr_log_unmount(const char *devname, const int retval)
75186+{
75187+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75188+ if (grsec_enable_mount && (retval >= 0))
75189+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75190+#endif
75191+ return;
75192+}
75193+
75194+void
75195+gr_log_mount(const char *from, const char *to, const int retval)
75196+{
75197+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75198+ if (grsec_enable_mount && (retval >= 0))
75199+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75200+#endif
75201+ return;
75202+}
75203+
75204+int
75205+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75206+{
75207+#ifdef CONFIG_GRKERNSEC_ROFS
75208+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75209+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75210+ return -EPERM;
75211+ } else
75212+ return 0;
75213+#endif
75214+ return 0;
75215+}
75216+
75217+int
75218+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75219+{
75220+#ifdef CONFIG_GRKERNSEC_ROFS
75221+ struct inode *inode = dentry->d_inode;
75222+
75223+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75224+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75225+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75226+ return -EPERM;
75227+ } else
75228+ return 0;
75229+#endif
75230+ return 0;
75231+}
75232diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75233new file mode 100644
75234index 0000000..6ee9d50
75235--- /dev/null
75236+++ b/grsecurity/grsec_pax.c
75237@@ -0,0 +1,45 @@
75238+#include <linux/kernel.h>
75239+#include <linux/sched.h>
75240+#include <linux/mm.h>
75241+#include <linux/file.h>
75242+#include <linux/grinternal.h>
75243+#include <linux/grsecurity.h>
75244+
75245+void
75246+gr_log_textrel(struct vm_area_struct * vma)
75247+{
75248+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75249+ if (grsec_enable_log_rwxmaps)
75250+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75251+#endif
75252+ return;
75253+}
75254+
75255+void gr_log_ptgnustack(struct file *file)
75256+{
75257+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75258+ if (grsec_enable_log_rwxmaps)
75259+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75260+#endif
75261+ return;
75262+}
75263+
75264+void
75265+gr_log_rwxmmap(struct file *file)
75266+{
75267+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75268+ if (grsec_enable_log_rwxmaps)
75269+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75270+#endif
75271+ return;
75272+}
75273+
75274+void
75275+gr_log_rwxmprotect(struct vm_area_struct *vma)
75276+{
75277+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75278+ if (grsec_enable_log_rwxmaps)
75279+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75280+#endif
75281+ return;
75282+}
75283diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75284new file mode 100644
75285index 0000000..2005a3a
75286--- /dev/null
75287+++ b/grsecurity/grsec_proc.c
75288@@ -0,0 +1,20 @@
75289+#include <linux/kernel.h>
75290+#include <linux/sched.h>
75291+#include <linux/grsecurity.h>
75292+#include <linux/grinternal.h>
75293+
75294+int gr_proc_is_restricted(void)
75295+{
75296+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75297+ const struct cred *cred = current_cred();
75298+#endif
75299+
75300+#ifdef CONFIG_GRKERNSEC_PROC_USER
75301+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75302+ return -EACCES;
75303+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75304+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75305+ return -EACCES;
75306+#endif
75307+ return 0;
75308+}
75309diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75310new file mode 100644
75311index 0000000..f7f29aa
75312--- /dev/null
75313+++ b/grsecurity/grsec_ptrace.c
75314@@ -0,0 +1,30 @@
75315+#include <linux/kernel.h>
75316+#include <linux/sched.h>
75317+#include <linux/grinternal.h>
75318+#include <linux/security.h>
75319+
75320+void
75321+gr_audit_ptrace(struct task_struct *task)
75322+{
75323+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75324+ if (grsec_enable_audit_ptrace)
75325+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75326+#endif
75327+ return;
75328+}
75329+
75330+int
75331+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75332+{
75333+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75334+ const struct dentry *dentry = file->f_path.dentry;
75335+ const struct vfsmount *mnt = file->f_path.mnt;
75336+
75337+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75338+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75339+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75340+ return -EACCES;
75341+ }
75342+#endif
75343+ return 0;
75344+}
75345diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75346new file mode 100644
75347index 0000000..3860c7e
75348--- /dev/null
75349+++ b/grsecurity/grsec_sig.c
75350@@ -0,0 +1,236 @@
75351+#include <linux/kernel.h>
75352+#include <linux/sched.h>
75353+#include <linux/fs.h>
75354+#include <linux/delay.h>
75355+#include <linux/grsecurity.h>
75356+#include <linux/grinternal.h>
75357+#include <linux/hardirq.h>
75358+
75359+char *signames[] = {
75360+ [SIGSEGV] = "Segmentation fault",
75361+ [SIGILL] = "Illegal instruction",
75362+ [SIGABRT] = "Abort",
75363+ [SIGBUS] = "Invalid alignment/Bus error"
75364+};
75365+
75366+void
75367+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75368+{
75369+#ifdef CONFIG_GRKERNSEC_SIGNAL
75370+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75371+ (sig == SIGABRT) || (sig == SIGBUS))) {
75372+ if (task_pid_nr(t) == task_pid_nr(current)) {
75373+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75374+ } else {
75375+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75376+ }
75377+ }
75378+#endif
75379+ return;
75380+}
75381+
75382+int
75383+gr_handle_signal(const struct task_struct *p, const int sig)
75384+{
75385+#ifdef CONFIG_GRKERNSEC
75386+ /* ignore the 0 signal for protected task checks */
75387+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75388+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75389+ return -EPERM;
75390+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75391+ return -EPERM;
75392+ }
75393+#endif
75394+ return 0;
75395+}
75396+
75397+#ifdef CONFIG_GRKERNSEC
75398+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75399+
75400+int gr_fake_force_sig(int sig, struct task_struct *t)
75401+{
75402+ unsigned long int flags;
75403+ int ret, blocked, ignored;
75404+ struct k_sigaction *action;
75405+
75406+ spin_lock_irqsave(&t->sighand->siglock, flags);
75407+ action = &t->sighand->action[sig-1];
75408+ ignored = action->sa.sa_handler == SIG_IGN;
75409+ blocked = sigismember(&t->blocked, sig);
75410+ if (blocked || ignored) {
75411+ action->sa.sa_handler = SIG_DFL;
75412+ if (blocked) {
75413+ sigdelset(&t->blocked, sig);
75414+ recalc_sigpending_and_wake(t);
75415+ }
75416+ }
75417+ if (action->sa.sa_handler == SIG_DFL)
75418+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75419+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75420+
75421+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75422+
75423+ return ret;
75424+}
75425+#endif
75426+
75427+#define GR_USER_BAN_TIME (15 * 60)
75428+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75429+
75430+void gr_handle_brute_attach(int dumpable)
75431+{
75432+#ifdef CONFIG_GRKERNSEC_BRUTE
75433+ struct task_struct *p = current;
75434+ kuid_t uid = GLOBAL_ROOT_UID;
75435+ int daemon = 0;
75436+
75437+ if (!grsec_enable_brute)
75438+ return;
75439+
75440+ rcu_read_lock();
75441+ read_lock(&tasklist_lock);
75442+ read_lock(&grsec_exec_file_lock);
75443+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75444+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75445+ p->real_parent->brute = 1;
75446+ daemon = 1;
75447+ } else {
75448+ const struct cred *cred = __task_cred(p), *cred2;
75449+ struct task_struct *tsk, *tsk2;
75450+
75451+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75452+ struct user_struct *user;
75453+
75454+ uid = cred->uid;
75455+
75456+ /* this is put upon execution past expiration */
75457+ user = find_user(uid);
75458+ if (user == NULL)
75459+ goto unlock;
75460+ user->suid_banned = 1;
75461+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75462+ if (user->suid_ban_expires == ~0UL)
75463+ user->suid_ban_expires--;
75464+
75465+ /* only kill other threads of the same binary, from the same user */
75466+ do_each_thread(tsk2, tsk) {
75467+ cred2 = __task_cred(tsk);
75468+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75469+ gr_fake_force_sig(SIGKILL, tsk);
75470+ } while_each_thread(tsk2, tsk);
75471+ }
75472+ }
75473+unlock:
75474+ read_unlock(&grsec_exec_file_lock);
75475+ read_unlock(&tasklist_lock);
75476+ rcu_read_unlock();
75477+
75478+ if (gr_is_global_nonroot(uid))
75479+ 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);
75480+ else if (daemon)
75481+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75482+
75483+#endif
75484+ return;
75485+}
75486+
75487+void gr_handle_brute_check(void)
75488+{
75489+#ifdef CONFIG_GRKERNSEC_BRUTE
75490+ struct task_struct *p = current;
75491+
75492+ if (unlikely(p->brute)) {
75493+ if (!grsec_enable_brute)
75494+ p->brute = 0;
75495+ else if (time_before(get_seconds(), p->brute_expires))
75496+ msleep(30 * 1000);
75497+ }
75498+#endif
75499+ return;
75500+}
75501+
75502+void gr_handle_kernel_exploit(void)
75503+{
75504+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75505+ const struct cred *cred;
75506+ struct task_struct *tsk, *tsk2;
75507+ struct user_struct *user;
75508+ kuid_t uid;
75509+
75510+ if (in_irq() || in_serving_softirq() || in_nmi())
75511+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75512+
75513+ uid = current_uid();
75514+
75515+ if (gr_is_global_root(uid))
75516+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75517+ else {
75518+ /* kill all the processes of this user, hold a reference
75519+ to their creds struct, and prevent them from creating
75520+ another process until system reset
75521+ */
75522+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75523+ GR_GLOBAL_UID(uid));
75524+ /* we intentionally leak this ref */
75525+ user = get_uid(current->cred->user);
75526+ if (user)
75527+ user->kernel_banned = 1;
75528+
75529+ /* kill all processes of this user */
75530+ read_lock(&tasklist_lock);
75531+ do_each_thread(tsk2, tsk) {
75532+ cred = __task_cred(tsk);
75533+ if (uid_eq(cred->uid, uid))
75534+ gr_fake_force_sig(SIGKILL, tsk);
75535+ } while_each_thread(tsk2, tsk);
75536+ read_unlock(&tasklist_lock);
75537+ }
75538+#endif
75539+}
75540+
75541+#ifdef CONFIG_GRKERNSEC_BRUTE
75542+static bool suid_ban_expired(struct user_struct *user)
75543+{
75544+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75545+ user->suid_banned = 0;
75546+ user->suid_ban_expires = 0;
75547+ free_uid(user);
75548+ return true;
75549+ }
75550+
75551+ return false;
75552+}
75553+#endif
75554+
75555+int gr_process_kernel_exec_ban(void)
75556+{
75557+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75558+ if (unlikely(current->cred->user->kernel_banned))
75559+ return -EPERM;
75560+#endif
75561+ return 0;
75562+}
75563+
75564+int gr_process_kernel_setuid_ban(struct user_struct *user)
75565+{
75566+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75567+ if (unlikely(user->kernel_banned))
75568+ gr_fake_force_sig(SIGKILL, current);
75569+#endif
75570+ return 0;
75571+}
75572+
75573+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75574+{
75575+#ifdef CONFIG_GRKERNSEC_BRUTE
75576+ struct user_struct *user = current->cred->user;
75577+ if (unlikely(user->suid_banned)) {
75578+ if (suid_ban_expired(user))
75579+ return 0;
75580+ /* disallow execution of suid binaries only */
75581+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75582+ return -EPERM;
75583+ }
75584+#endif
75585+ return 0;
75586+}
75587diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75588new file mode 100644
75589index 0000000..c0aef3a
75590--- /dev/null
75591+++ b/grsecurity/grsec_sock.c
75592@@ -0,0 +1,244 @@
75593+#include <linux/kernel.h>
75594+#include <linux/module.h>
75595+#include <linux/sched.h>
75596+#include <linux/file.h>
75597+#include <linux/net.h>
75598+#include <linux/in.h>
75599+#include <linux/ip.h>
75600+#include <net/sock.h>
75601+#include <net/inet_sock.h>
75602+#include <linux/grsecurity.h>
75603+#include <linux/grinternal.h>
75604+#include <linux/gracl.h>
75605+
75606+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75607+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75608+
75609+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75610+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75611+
75612+#ifdef CONFIG_UNIX_MODULE
75613+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75614+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75615+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75616+EXPORT_SYMBOL_GPL(gr_handle_create);
75617+#endif
75618+
75619+#ifdef CONFIG_GRKERNSEC
75620+#define gr_conn_table_size 32749
75621+struct conn_table_entry {
75622+ struct conn_table_entry *next;
75623+ struct signal_struct *sig;
75624+};
75625+
75626+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75627+DEFINE_SPINLOCK(gr_conn_table_lock);
75628+
75629+extern const char * gr_socktype_to_name(unsigned char type);
75630+extern const char * gr_proto_to_name(unsigned char proto);
75631+extern const char * gr_sockfamily_to_name(unsigned char family);
75632+
75633+static __inline__ int
75634+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75635+{
75636+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75637+}
75638+
75639+static __inline__ int
75640+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75641+ __u16 sport, __u16 dport)
75642+{
75643+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75644+ sig->gr_sport == sport && sig->gr_dport == dport))
75645+ return 1;
75646+ else
75647+ return 0;
75648+}
75649+
75650+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75651+{
75652+ struct conn_table_entry **match;
75653+ unsigned int index;
75654+
75655+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75656+ sig->gr_sport, sig->gr_dport,
75657+ gr_conn_table_size);
75658+
75659+ newent->sig = sig;
75660+
75661+ match = &gr_conn_table[index];
75662+ newent->next = *match;
75663+ *match = newent;
75664+
75665+ return;
75666+}
75667+
75668+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75669+{
75670+ struct conn_table_entry *match, *last = NULL;
75671+ unsigned int index;
75672+
75673+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75674+ sig->gr_sport, sig->gr_dport,
75675+ gr_conn_table_size);
75676+
75677+ match = gr_conn_table[index];
75678+ while (match && !conn_match(match->sig,
75679+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75680+ sig->gr_dport)) {
75681+ last = match;
75682+ match = match->next;
75683+ }
75684+
75685+ if (match) {
75686+ if (last)
75687+ last->next = match->next;
75688+ else
75689+ gr_conn_table[index] = NULL;
75690+ kfree(match);
75691+ }
75692+
75693+ return;
75694+}
75695+
75696+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75697+ __u16 sport, __u16 dport)
75698+{
75699+ struct conn_table_entry *match;
75700+ unsigned int index;
75701+
75702+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75703+
75704+ match = gr_conn_table[index];
75705+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75706+ match = match->next;
75707+
75708+ if (match)
75709+ return match->sig;
75710+ else
75711+ return NULL;
75712+}
75713+
75714+#endif
75715+
75716+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75717+{
75718+#ifdef CONFIG_GRKERNSEC
75719+ struct signal_struct *sig = task->signal;
75720+ struct conn_table_entry *newent;
75721+
75722+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75723+ if (newent == NULL)
75724+ return;
75725+ /* no bh lock needed since we are called with bh disabled */
75726+ spin_lock(&gr_conn_table_lock);
75727+ gr_del_task_from_ip_table_nolock(sig);
75728+ sig->gr_saddr = inet->inet_rcv_saddr;
75729+ sig->gr_daddr = inet->inet_daddr;
75730+ sig->gr_sport = inet->inet_sport;
75731+ sig->gr_dport = inet->inet_dport;
75732+ gr_add_to_task_ip_table_nolock(sig, newent);
75733+ spin_unlock(&gr_conn_table_lock);
75734+#endif
75735+ return;
75736+}
75737+
75738+void gr_del_task_from_ip_table(struct task_struct *task)
75739+{
75740+#ifdef CONFIG_GRKERNSEC
75741+ spin_lock_bh(&gr_conn_table_lock);
75742+ gr_del_task_from_ip_table_nolock(task->signal);
75743+ spin_unlock_bh(&gr_conn_table_lock);
75744+#endif
75745+ return;
75746+}
75747+
75748+void
75749+gr_attach_curr_ip(const struct sock *sk)
75750+{
75751+#ifdef CONFIG_GRKERNSEC
75752+ struct signal_struct *p, *set;
75753+ const struct inet_sock *inet = inet_sk(sk);
75754+
75755+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75756+ return;
75757+
75758+ set = current->signal;
75759+
75760+ spin_lock_bh(&gr_conn_table_lock);
75761+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75762+ inet->inet_dport, inet->inet_sport);
75763+ if (unlikely(p != NULL)) {
75764+ set->curr_ip = p->curr_ip;
75765+ set->used_accept = 1;
75766+ gr_del_task_from_ip_table_nolock(p);
75767+ spin_unlock_bh(&gr_conn_table_lock);
75768+ return;
75769+ }
75770+ spin_unlock_bh(&gr_conn_table_lock);
75771+
75772+ set->curr_ip = inet->inet_daddr;
75773+ set->used_accept = 1;
75774+#endif
75775+ return;
75776+}
75777+
75778+int
75779+gr_handle_sock_all(const int family, const int type, const int protocol)
75780+{
75781+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75782+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75783+ (family != AF_UNIX)) {
75784+ if (family == AF_INET)
75785+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75786+ else
75787+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75788+ return -EACCES;
75789+ }
75790+#endif
75791+ return 0;
75792+}
75793+
75794+int
75795+gr_handle_sock_server(const struct sockaddr *sck)
75796+{
75797+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75798+ if (grsec_enable_socket_server &&
75799+ in_group_p(grsec_socket_server_gid) &&
75800+ sck && (sck->sa_family != AF_UNIX) &&
75801+ (sck->sa_family != AF_LOCAL)) {
75802+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75803+ return -EACCES;
75804+ }
75805+#endif
75806+ return 0;
75807+}
75808+
75809+int
75810+gr_handle_sock_server_other(const struct sock *sck)
75811+{
75812+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75813+ if (grsec_enable_socket_server &&
75814+ in_group_p(grsec_socket_server_gid) &&
75815+ sck && (sck->sk_family != AF_UNIX) &&
75816+ (sck->sk_family != AF_LOCAL)) {
75817+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75818+ return -EACCES;
75819+ }
75820+#endif
75821+ return 0;
75822+}
75823+
75824+int
75825+gr_handle_sock_client(const struct sockaddr *sck)
75826+{
75827+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75828+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75829+ sck && (sck->sa_family != AF_UNIX) &&
75830+ (sck->sa_family != AF_LOCAL)) {
75831+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75832+ return -EACCES;
75833+ }
75834+#endif
75835+ return 0;
75836+}
75837diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75838new file mode 100644
75839index 0000000..8159888
75840--- /dev/null
75841+++ b/grsecurity/grsec_sysctl.c
75842@@ -0,0 +1,479 @@
75843+#include <linux/kernel.h>
75844+#include <linux/sched.h>
75845+#include <linux/sysctl.h>
75846+#include <linux/grsecurity.h>
75847+#include <linux/grinternal.h>
75848+
75849+int
75850+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75851+{
75852+#ifdef CONFIG_GRKERNSEC_SYSCTL
75853+ if (dirname == NULL || name == NULL)
75854+ return 0;
75855+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75856+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75857+ return -EACCES;
75858+ }
75859+#endif
75860+ return 0;
75861+}
75862+
75863+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75864+static int __maybe_unused __read_only one = 1;
75865+#endif
75866+
75867+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75868+ defined(CONFIG_GRKERNSEC_DENYUSB)
75869+struct ctl_table grsecurity_table[] = {
75870+#ifdef CONFIG_GRKERNSEC_SYSCTL
75871+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75872+#ifdef CONFIG_GRKERNSEC_IO
75873+ {
75874+ .procname = "disable_priv_io",
75875+ .data = &grsec_disable_privio,
75876+ .maxlen = sizeof(int),
75877+ .mode = 0600,
75878+ .proc_handler = &proc_dointvec,
75879+ },
75880+#endif
75881+#endif
75882+#ifdef CONFIG_GRKERNSEC_LINK
75883+ {
75884+ .procname = "linking_restrictions",
75885+ .data = &grsec_enable_link,
75886+ .maxlen = sizeof(int),
75887+ .mode = 0600,
75888+ .proc_handler = &proc_dointvec,
75889+ },
75890+#endif
75891+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75892+ {
75893+ .procname = "enforce_symlinksifowner",
75894+ .data = &grsec_enable_symlinkown,
75895+ .maxlen = sizeof(int),
75896+ .mode = 0600,
75897+ .proc_handler = &proc_dointvec,
75898+ },
75899+ {
75900+ .procname = "symlinkown_gid",
75901+ .data = &grsec_symlinkown_gid,
75902+ .maxlen = sizeof(int),
75903+ .mode = 0600,
75904+ .proc_handler = &proc_dointvec,
75905+ },
75906+#endif
75907+#ifdef CONFIG_GRKERNSEC_BRUTE
75908+ {
75909+ .procname = "deter_bruteforce",
75910+ .data = &grsec_enable_brute,
75911+ .maxlen = sizeof(int),
75912+ .mode = 0600,
75913+ .proc_handler = &proc_dointvec,
75914+ },
75915+#endif
75916+#ifdef CONFIG_GRKERNSEC_FIFO
75917+ {
75918+ .procname = "fifo_restrictions",
75919+ .data = &grsec_enable_fifo,
75920+ .maxlen = sizeof(int),
75921+ .mode = 0600,
75922+ .proc_handler = &proc_dointvec,
75923+ },
75924+#endif
75925+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75926+ {
75927+ .procname = "ptrace_readexec",
75928+ .data = &grsec_enable_ptrace_readexec,
75929+ .maxlen = sizeof(int),
75930+ .mode = 0600,
75931+ .proc_handler = &proc_dointvec,
75932+ },
75933+#endif
75934+#ifdef CONFIG_GRKERNSEC_SETXID
75935+ {
75936+ .procname = "consistent_setxid",
75937+ .data = &grsec_enable_setxid,
75938+ .maxlen = sizeof(int),
75939+ .mode = 0600,
75940+ .proc_handler = &proc_dointvec,
75941+ },
75942+#endif
75943+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75944+ {
75945+ .procname = "ip_blackhole",
75946+ .data = &grsec_enable_blackhole,
75947+ .maxlen = sizeof(int),
75948+ .mode = 0600,
75949+ .proc_handler = &proc_dointvec,
75950+ },
75951+ {
75952+ .procname = "lastack_retries",
75953+ .data = &grsec_lastack_retries,
75954+ .maxlen = sizeof(int),
75955+ .mode = 0600,
75956+ .proc_handler = &proc_dointvec,
75957+ },
75958+#endif
75959+#ifdef CONFIG_GRKERNSEC_EXECLOG
75960+ {
75961+ .procname = "exec_logging",
75962+ .data = &grsec_enable_execlog,
75963+ .maxlen = sizeof(int),
75964+ .mode = 0600,
75965+ .proc_handler = &proc_dointvec,
75966+ },
75967+#endif
75968+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75969+ {
75970+ .procname = "rwxmap_logging",
75971+ .data = &grsec_enable_log_rwxmaps,
75972+ .maxlen = sizeof(int),
75973+ .mode = 0600,
75974+ .proc_handler = &proc_dointvec,
75975+ },
75976+#endif
75977+#ifdef CONFIG_GRKERNSEC_SIGNAL
75978+ {
75979+ .procname = "signal_logging",
75980+ .data = &grsec_enable_signal,
75981+ .maxlen = sizeof(int),
75982+ .mode = 0600,
75983+ .proc_handler = &proc_dointvec,
75984+ },
75985+#endif
75986+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75987+ {
75988+ .procname = "forkfail_logging",
75989+ .data = &grsec_enable_forkfail,
75990+ .maxlen = sizeof(int),
75991+ .mode = 0600,
75992+ .proc_handler = &proc_dointvec,
75993+ },
75994+#endif
75995+#ifdef CONFIG_GRKERNSEC_TIME
75996+ {
75997+ .procname = "timechange_logging",
75998+ .data = &grsec_enable_time,
75999+ .maxlen = sizeof(int),
76000+ .mode = 0600,
76001+ .proc_handler = &proc_dointvec,
76002+ },
76003+#endif
76004+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76005+ {
76006+ .procname = "chroot_deny_shmat",
76007+ .data = &grsec_enable_chroot_shmat,
76008+ .maxlen = sizeof(int),
76009+ .mode = 0600,
76010+ .proc_handler = &proc_dointvec,
76011+ },
76012+#endif
76013+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76014+ {
76015+ .procname = "chroot_deny_unix",
76016+ .data = &grsec_enable_chroot_unix,
76017+ .maxlen = sizeof(int),
76018+ .mode = 0600,
76019+ .proc_handler = &proc_dointvec,
76020+ },
76021+#endif
76022+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76023+ {
76024+ .procname = "chroot_deny_mount",
76025+ .data = &grsec_enable_chroot_mount,
76026+ .maxlen = sizeof(int),
76027+ .mode = 0600,
76028+ .proc_handler = &proc_dointvec,
76029+ },
76030+#endif
76031+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76032+ {
76033+ .procname = "chroot_deny_fchdir",
76034+ .data = &grsec_enable_chroot_fchdir,
76035+ .maxlen = sizeof(int),
76036+ .mode = 0600,
76037+ .proc_handler = &proc_dointvec,
76038+ },
76039+#endif
76040+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76041+ {
76042+ .procname = "chroot_deny_chroot",
76043+ .data = &grsec_enable_chroot_double,
76044+ .maxlen = sizeof(int),
76045+ .mode = 0600,
76046+ .proc_handler = &proc_dointvec,
76047+ },
76048+#endif
76049+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76050+ {
76051+ .procname = "chroot_deny_pivot",
76052+ .data = &grsec_enable_chroot_pivot,
76053+ .maxlen = sizeof(int),
76054+ .mode = 0600,
76055+ .proc_handler = &proc_dointvec,
76056+ },
76057+#endif
76058+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76059+ {
76060+ .procname = "chroot_enforce_chdir",
76061+ .data = &grsec_enable_chroot_chdir,
76062+ .maxlen = sizeof(int),
76063+ .mode = 0600,
76064+ .proc_handler = &proc_dointvec,
76065+ },
76066+#endif
76067+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76068+ {
76069+ .procname = "chroot_deny_chmod",
76070+ .data = &grsec_enable_chroot_chmod,
76071+ .maxlen = sizeof(int),
76072+ .mode = 0600,
76073+ .proc_handler = &proc_dointvec,
76074+ },
76075+#endif
76076+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76077+ {
76078+ .procname = "chroot_deny_mknod",
76079+ .data = &grsec_enable_chroot_mknod,
76080+ .maxlen = sizeof(int),
76081+ .mode = 0600,
76082+ .proc_handler = &proc_dointvec,
76083+ },
76084+#endif
76085+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76086+ {
76087+ .procname = "chroot_restrict_nice",
76088+ .data = &grsec_enable_chroot_nice,
76089+ .maxlen = sizeof(int),
76090+ .mode = 0600,
76091+ .proc_handler = &proc_dointvec,
76092+ },
76093+#endif
76094+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76095+ {
76096+ .procname = "chroot_execlog",
76097+ .data = &grsec_enable_chroot_execlog,
76098+ .maxlen = sizeof(int),
76099+ .mode = 0600,
76100+ .proc_handler = &proc_dointvec,
76101+ },
76102+#endif
76103+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76104+ {
76105+ .procname = "chroot_caps",
76106+ .data = &grsec_enable_chroot_caps,
76107+ .maxlen = sizeof(int),
76108+ .mode = 0600,
76109+ .proc_handler = &proc_dointvec,
76110+ },
76111+#endif
76112+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76113+ {
76114+ .procname = "chroot_deny_sysctl",
76115+ .data = &grsec_enable_chroot_sysctl,
76116+ .maxlen = sizeof(int),
76117+ .mode = 0600,
76118+ .proc_handler = &proc_dointvec,
76119+ },
76120+#endif
76121+#ifdef CONFIG_GRKERNSEC_TPE
76122+ {
76123+ .procname = "tpe",
76124+ .data = &grsec_enable_tpe,
76125+ .maxlen = sizeof(int),
76126+ .mode = 0600,
76127+ .proc_handler = &proc_dointvec,
76128+ },
76129+ {
76130+ .procname = "tpe_gid",
76131+ .data = &grsec_tpe_gid,
76132+ .maxlen = sizeof(int),
76133+ .mode = 0600,
76134+ .proc_handler = &proc_dointvec,
76135+ },
76136+#endif
76137+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76138+ {
76139+ .procname = "tpe_invert",
76140+ .data = &grsec_enable_tpe_invert,
76141+ .maxlen = sizeof(int),
76142+ .mode = 0600,
76143+ .proc_handler = &proc_dointvec,
76144+ },
76145+#endif
76146+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76147+ {
76148+ .procname = "tpe_restrict_all",
76149+ .data = &grsec_enable_tpe_all,
76150+ .maxlen = sizeof(int),
76151+ .mode = 0600,
76152+ .proc_handler = &proc_dointvec,
76153+ },
76154+#endif
76155+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76156+ {
76157+ .procname = "socket_all",
76158+ .data = &grsec_enable_socket_all,
76159+ .maxlen = sizeof(int),
76160+ .mode = 0600,
76161+ .proc_handler = &proc_dointvec,
76162+ },
76163+ {
76164+ .procname = "socket_all_gid",
76165+ .data = &grsec_socket_all_gid,
76166+ .maxlen = sizeof(int),
76167+ .mode = 0600,
76168+ .proc_handler = &proc_dointvec,
76169+ },
76170+#endif
76171+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76172+ {
76173+ .procname = "socket_client",
76174+ .data = &grsec_enable_socket_client,
76175+ .maxlen = sizeof(int),
76176+ .mode = 0600,
76177+ .proc_handler = &proc_dointvec,
76178+ },
76179+ {
76180+ .procname = "socket_client_gid",
76181+ .data = &grsec_socket_client_gid,
76182+ .maxlen = sizeof(int),
76183+ .mode = 0600,
76184+ .proc_handler = &proc_dointvec,
76185+ },
76186+#endif
76187+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76188+ {
76189+ .procname = "socket_server",
76190+ .data = &grsec_enable_socket_server,
76191+ .maxlen = sizeof(int),
76192+ .mode = 0600,
76193+ .proc_handler = &proc_dointvec,
76194+ },
76195+ {
76196+ .procname = "socket_server_gid",
76197+ .data = &grsec_socket_server_gid,
76198+ .maxlen = sizeof(int),
76199+ .mode = 0600,
76200+ .proc_handler = &proc_dointvec,
76201+ },
76202+#endif
76203+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76204+ {
76205+ .procname = "audit_group",
76206+ .data = &grsec_enable_group,
76207+ .maxlen = sizeof(int),
76208+ .mode = 0600,
76209+ .proc_handler = &proc_dointvec,
76210+ },
76211+ {
76212+ .procname = "audit_gid",
76213+ .data = &grsec_audit_gid,
76214+ .maxlen = sizeof(int),
76215+ .mode = 0600,
76216+ .proc_handler = &proc_dointvec,
76217+ },
76218+#endif
76219+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76220+ {
76221+ .procname = "audit_chdir",
76222+ .data = &grsec_enable_chdir,
76223+ .maxlen = sizeof(int),
76224+ .mode = 0600,
76225+ .proc_handler = &proc_dointvec,
76226+ },
76227+#endif
76228+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76229+ {
76230+ .procname = "audit_mount",
76231+ .data = &grsec_enable_mount,
76232+ .maxlen = sizeof(int),
76233+ .mode = 0600,
76234+ .proc_handler = &proc_dointvec,
76235+ },
76236+#endif
76237+#ifdef CONFIG_GRKERNSEC_DMESG
76238+ {
76239+ .procname = "dmesg",
76240+ .data = &grsec_enable_dmesg,
76241+ .maxlen = sizeof(int),
76242+ .mode = 0600,
76243+ .proc_handler = &proc_dointvec,
76244+ },
76245+#endif
76246+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76247+ {
76248+ .procname = "chroot_findtask",
76249+ .data = &grsec_enable_chroot_findtask,
76250+ .maxlen = sizeof(int),
76251+ .mode = 0600,
76252+ .proc_handler = &proc_dointvec,
76253+ },
76254+#endif
76255+#ifdef CONFIG_GRKERNSEC_RESLOG
76256+ {
76257+ .procname = "resource_logging",
76258+ .data = &grsec_resource_logging,
76259+ .maxlen = sizeof(int),
76260+ .mode = 0600,
76261+ .proc_handler = &proc_dointvec,
76262+ },
76263+#endif
76264+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76265+ {
76266+ .procname = "audit_ptrace",
76267+ .data = &grsec_enable_audit_ptrace,
76268+ .maxlen = sizeof(int),
76269+ .mode = 0600,
76270+ .proc_handler = &proc_dointvec,
76271+ },
76272+#endif
76273+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76274+ {
76275+ .procname = "harden_ptrace",
76276+ .data = &grsec_enable_harden_ptrace,
76277+ .maxlen = sizeof(int),
76278+ .mode = 0600,
76279+ .proc_handler = &proc_dointvec,
76280+ },
76281+#endif
76282+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76283+ {
76284+ .procname = "harden_ipc",
76285+ .data = &grsec_enable_harden_ipc,
76286+ .maxlen = sizeof(int),
76287+ .mode = 0600,
76288+ .proc_handler = &proc_dointvec,
76289+ },
76290+#endif
76291+ {
76292+ .procname = "grsec_lock",
76293+ .data = &grsec_lock,
76294+ .maxlen = sizeof(int),
76295+ .mode = 0600,
76296+ .proc_handler = &proc_dointvec,
76297+ },
76298+#endif
76299+#ifdef CONFIG_GRKERNSEC_ROFS
76300+ {
76301+ .procname = "romount_protect",
76302+ .data = &grsec_enable_rofs,
76303+ .maxlen = sizeof(int),
76304+ .mode = 0600,
76305+ .proc_handler = &proc_dointvec_minmax,
76306+ .extra1 = &one,
76307+ .extra2 = &one,
76308+ },
76309+#endif
76310+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76311+ {
76312+ .procname = "deny_new_usb",
76313+ .data = &grsec_deny_new_usb,
76314+ .maxlen = sizeof(int),
76315+ .mode = 0600,
76316+ .proc_handler = &proc_dointvec,
76317+ },
76318+#endif
76319+ { }
76320+};
76321+#endif
76322diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76323new file mode 100644
76324index 0000000..61b514e
76325--- /dev/null
76326+++ b/grsecurity/grsec_time.c
76327@@ -0,0 +1,16 @@
76328+#include <linux/kernel.h>
76329+#include <linux/sched.h>
76330+#include <linux/grinternal.h>
76331+#include <linux/module.h>
76332+
76333+void
76334+gr_log_timechange(void)
76335+{
76336+#ifdef CONFIG_GRKERNSEC_TIME
76337+ if (grsec_enable_time)
76338+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76339+#endif
76340+ return;
76341+}
76342+
76343+EXPORT_SYMBOL_GPL(gr_log_timechange);
76344diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76345new file mode 100644
76346index 0000000..ee57dcf
76347--- /dev/null
76348+++ b/grsecurity/grsec_tpe.c
76349@@ -0,0 +1,73 @@
76350+#include <linux/kernel.h>
76351+#include <linux/sched.h>
76352+#include <linux/file.h>
76353+#include <linux/fs.h>
76354+#include <linux/grinternal.h>
76355+
76356+extern int gr_acl_tpe_check(void);
76357+
76358+int
76359+gr_tpe_allow(const struct file *file)
76360+{
76361+#ifdef CONFIG_GRKERNSEC
76362+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76363+ const struct cred *cred = current_cred();
76364+ char *msg = NULL;
76365+ char *msg2 = NULL;
76366+
76367+ // never restrict root
76368+ if (gr_is_global_root(cred->uid))
76369+ return 1;
76370+
76371+ if (grsec_enable_tpe) {
76372+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76373+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76374+ msg = "not being in trusted group";
76375+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76376+ msg = "being in untrusted group";
76377+#else
76378+ if (in_group_p(grsec_tpe_gid))
76379+ msg = "being in untrusted group";
76380+#endif
76381+ }
76382+ if (!msg && gr_acl_tpe_check())
76383+ msg = "being in untrusted role";
76384+
76385+ // not in any affected group/role
76386+ if (!msg)
76387+ goto next_check;
76388+
76389+ if (gr_is_global_nonroot(inode->i_uid))
76390+ msg2 = "file in non-root-owned directory";
76391+ else if (inode->i_mode & S_IWOTH)
76392+ msg2 = "file in world-writable directory";
76393+ else if (inode->i_mode & S_IWGRP)
76394+ msg2 = "file in group-writable directory";
76395+
76396+ if (msg && msg2) {
76397+ char fullmsg[70] = {0};
76398+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76399+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76400+ return 0;
76401+ }
76402+ msg = NULL;
76403+next_check:
76404+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76405+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76406+ return 1;
76407+
76408+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76409+ msg = "directory not owned by user";
76410+ else if (inode->i_mode & S_IWOTH)
76411+ msg = "file in world-writable directory";
76412+ else if (inode->i_mode & S_IWGRP)
76413+ msg = "file in group-writable directory";
76414+
76415+ if (msg) {
76416+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76417+ return 0;
76418+ }
76419+#endif
76420+#endif
76421+ return 1;
76422+}
76423diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76424new file mode 100644
76425index 0000000..ae02d8e
76426--- /dev/null
76427+++ b/grsecurity/grsec_usb.c
76428@@ -0,0 +1,15 @@
76429+#include <linux/kernel.h>
76430+#include <linux/grinternal.h>
76431+#include <linux/module.h>
76432+
76433+int gr_handle_new_usb(void)
76434+{
76435+#ifdef CONFIG_GRKERNSEC_DENYUSB
76436+ if (grsec_deny_new_usb) {
76437+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76438+ return 1;
76439+ }
76440+#endif
76441+ return 0;
76442+}
76443+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76444diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76445new file mode 100644
76446index 0000000..9f7b1ac
76447--- /dev/null
76448+++ b/grsecurity/grsum.c
76449@@ -0,0 +1,61 @@
76450+#include <linux/err.h>
76451+#include <linux/kernel.h>
76452+#include <linux/sched.h>
76453+#include <linux/mm.h>
76454+#include <linux/scatterlist.h>
76455+#include <linux/crypto.h>
76456+#include <linux/gracl.h>
76457+
76458+
76459+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76460+#error "crypto and sha256 must be built into the kernel"
76461+#endif
76462+
76463+int
76464+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76465+{
76466+ char *p;
76467+ struct crypto_hash *tfm;
76468+ struct hash_desc desc;
76469+ struct scatterlist sg;
76470+ unsigned char temp_sum[GR_SHA_LEN];
76471+ volatile int retval = 0;
76472+ volatile int dummy = 0;
76473+ unsigned int i;
76474+
76475+ sg_init_table(&sg, 1);
76476+
76477+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76478+ if (IS_ERR(tfm)) {
76479+ /* should never happen, since sha256 should be built in */
76480+ return 1;
76481+ }
76482+
76483+ desc.tfm = tfm;
76484+ desc.flags = 0;
76485+
76486+ crypto_hash_init(&desc);
76487+
76488+ p = salt;
76489+ sg_set_buf(&sg, p, GR_SALT_LEN);
76490+ crypto_hash_update(&desc, &sg, sg.length);
76491+
76492+ p = entry->pw;
76493+ sg_set_buf(&sg, p, strlen(p));
76494+
76495+ crypto_hash_update(&desc, &sg, sg.length);
76496+
76497+ crypto_hash_final(&desc, temp_sum);
76498+
76499+ memset(entry->pw, 0, GR_PW_LEN);
76500+
76501+ for (i = 0; i < GR_SHA_LEN; i++)
76502+ if (sum[i] != temp_sum[i])
76503+ retval = 1;
76504+ else
76505+ dummy = 1; // waste a cycle
76506+
76507+ crypto_free_hash(tfm);
76508+
76509+ return retval;
76510+}
76511diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76512index 77ff547..181834f 100644
76513--- a/include/asm-generic/4level-fixup.h
76514+++ b/include/asm-generic/4level-fixup.h
76515@@ -13,8 +13,10 @@
76516 #define pmd_alloc(mm, pud, address) \
76517 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76518 NULL: pmd_offset(pud, address))
76519+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76520
76521 #define pud_alloc(mm, pgd, address) (pgd)
76522+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76523 #define pud_offset(pgd, start) (pgd)
76524 #define pud_none(pud) 0
76525 #define pud_bad(pud) 0
76526diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76527index b7babf0..97f4c4f 100644
76528--- a/include/asm-generic/atomic-long.h
76529+++ b/include/asm-generic/atomic-long.h
76530@@ -22,6 +22,12 @@
76531
76532 typedef atomic64_t atomic_long_t;
76533
76534+#ifdef CONFIG_PAX_REFCOUNT
76535+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76536+#else
76537+typedef atomic64_t atomic_long_unchecked_t;
76538+#endif
76539+
76540 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76541
76542 static inline long atomic_long_read(atomic_long_t *l)
76543@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76544 return (long)atomic64_read(v);
76545 }
76546
76547+#ifdef CONFIG_PAX_REFCOUNT
76548+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76549+{
76550+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76551+
76552+ return (long)atomic64_read_unchecked(v);
76553+}
76554+#endif
76555+
76556 static inline void atomic_long_set(atomic_long_t *l, long i)
76557 {
76558 atomic64_t *v = (atomic64_t *)l;
76559@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76560 atomic64_set(v, i);
76561 }
76562
76563+#ifdef CONFIG_PAX_REFCOUNT
76564+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76565+{
76566+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76567+
76568+ atomic64_set_unchecked(v, i);
76569+}
76570+#endif
76571+
76572 static inline void atomic_long_inc(atomic_long_t *l)
76573 {
76574 atomic64_t *v = (atomic64_t *)l;
76575@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76576 atomic64_inc(v);
76577 }
76578
76579+#ifdef CONFIG_PAX_REFCOUNT
76580+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76581+{
76582+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76583+
76584+ atomic64_inc_unchecked(v);
76585+}
76586+#endif
76587+
76588 static inline void atomic_long_dec(atomic_long_t *l)
76589 {
76590 atomic64_t *v = (atomic64_t *)l;
76591@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76592 atomic64_dec(v);
76593 }
76594
76595+#ifdef CONFIG_PAX_REFCOUNT
76596+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76597+{
76598+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76599+
76600+ atomic64_dec_unchecked(v);
76601+}
76602+#endif
76603+
76604 static inline void atomic_long_add(long i, atomic_long_t *l)
76605 {
76606 atomic64_t *v = (atomic64_t *)l;
76607@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76608 atomic64_add(i, v);
76609 }
76610
76611+#ifdef CONFIG_PAX_REFCOUNT
76612+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76613+{
76614+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76615+
76616+ atomic64_add_unchecked(i, v);
76617+}
76618+#endif
76619+
76620 static inline void atomic_long_sub(long i, atomic_long_t *l)
76621 {
76622 atomic64_t *v = (atomic64_t *)l;
76623@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76624 atomic64_sub(i, v);
76625 }
76626
76627+#ifdef CONFIG_PAX_REFCOUNT
76628+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76629+{
76630+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76631+
76632+ atomic64_sub_unchecked(i, v);
76633+}
76634+#endif
76635+
76636 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76637 {
76638 atomic64_t *v = (atomic64_t *)l;
76639@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76640 return atomic64_add_negative(i, v);
76641 }
76642
76643-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76644+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76645 {
76646 atomic64_t *v = (atomic64_t *)l;
76647
76648 return (long)atomic64_add_return(i, v);
76649 }
76650
76651+#ifdef CONFIG_PAX_REFCOUNT
76652+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76653+{
76654+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76655+
76656+ return (long)atomic64_add_return_unchecked(i, v);
76657+}
76658+#endif
76659+
76660 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76661 {
76662 atomic64_t *v = (atomic64_t *)l;
76663@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76664 return (long)atomic64_inc_return(v);
76665 }
76666
76667+#ifdef CONFIG_PAX_REFCOUNT
76668+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76669+{
76670+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76671+
76672+ return (long)atomic64_inc_return_unchecked(v);
76673+}
76674+#endif
76675+
76676 static inline long atomic_long_dec_return(atomic_long_t *l)
76677 {
76678 atomic64_t *v = (atomic64_t *)l;
76679@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76680
76681 typedef atomic_t atomic_long_t;
76682
76683+#ifdef CONFIG_PAX_REFCOUNT
76684+typedef atomic_unchecked_t atomic_long_unchecked_t;
76685+#else
76686+typedef atomic_t atomic_long_unchecked_t;
76687+#endif
76688+
76689 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76690 static inline long atomic_long_read(atomic_long_t *l)
76691 {
76692@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76693 return (long)atomic_read(v);
76694 }
76695
76696+#ifdef CONFIG_PAX_REFCOUNT
76697+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76698+{
76699+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76700+
76701+ return (long)atomic_read_unchecked(v);
76702+}
76703+#endif
76704+
76705 static inline void atomic_long_set(atomic_long_t *l, long i)
76706 {
76707 atomic_t *v = (atomic_t *)l;
76708@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76709 atomic_set(v, i);
76710 }
76711
76712+#ifdef CONFIG_PAX_REFCOUNT
76713+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76714+{
76715+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76716+
76717+ atomic_set_unchecked(v, i);
76718+}
76719+#endif
76720+
76721 static inline void atomic_long_inc(atomic_long_t *l)
76722 {
76723 atomic_t *v = (atomic_t *)l;
76724@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76725 atomic_inc(v);
76726 }
76727
76728+#ifdef CONFIG_PAX_REFCOUNT
76729+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76730+{
76731+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76732+
76733+ atomic_inc_unchecked(v);
76734+}
76735+#endif
76736+
76737 static inline void atomic_long_dec(atomic_long_t *l)
76738 {
76739 atomic_t *v = (atomic_t *)l;
76740@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76741 atomic_dec(v);
76742 }
76743
76744+#ifdef CONFIG_PAX_REFCOUNT
76745+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76746+{
76747+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76748+
76749+ atomic_dec_unchecked(v);
76750+}
76751+#endif
76752+
76753 static inline void atomic_long_add(long i, atomic_long_t *l)
76754 {
76755 atomic_t *v = (atomic_t *)l;
76756@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76757 atomic_add(i, v);
76758 }
76759
76760+#ifdef CONFIG_PAX_REFCOUNT
76761+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76762+{
76763+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76764+
76765+ atomic_add_unchecked(i, v);
76766+}
76767+#endif
76768+
76769 static inline void atomic_long_sub(long i, atomic_long_t *l)
76770 {
76771 atomic_t *v = (atomic_t *)l;
76772@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76773 atomic_sub(i, v);
76774 }
76775
76776+#ifdef CONFIG_PAX_REFCOUNT
76777+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76778+{
76779+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76780+
76781+ atomic_sub_unchecked(i, v);
76782+}
76783+#endif
76784+
76785 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76786 {
76787 atomic_t *v = (atomic_t *)l;
76788@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76789 return (long)atomic_add_return(i, v);
76790 }
76791
76792+#ifdef CONFIG_PAX_REFCOUNT
76793+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76794+{
76795+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76796+
76797+ return (long)atomic_add_return_unchecked(i, v);
76798+}
76799+
76800+#endif
76801+
76802 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76803 {
76804 atomic_t *v = (atomic_t *)l;
76805@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76806 return (long)atomic_inc_return(v);
76807 }
76808
76809+#ifdef CONFIG_PAX_REFCOUNT
76810+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76811+{
76812+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76813+
76814+ return (long)atomic_inc_return_unchecked(v);
76815+}
76816+#endif
76817+
76818 static inline long atomic_long_dec_return(atomic_long_t *l)
76819 {
76820 atomic_t *v = (atomic_t *)l;
76821@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76822
76823 #endif /* BITS_PER_LONG == 64 */
76824
76825+#ifdef CONFIG_PAX_REFCOUNT
76826+static inline void pax_refcount_needs_these_functions(void)
76827+{
76828+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76829+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76830+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76831+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76832+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76833+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76834+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76835+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76836+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76837+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76838+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76839+#ifdef CONFIG_X86
76840+ atomic_clear_mask_unchecked(0, NULL);
76841+ atomic_set_mask_unchecked(0, NULL);
76842+#endif
76843+
76844+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76845+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76846+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76847+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76848+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76849+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76850+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76851+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76852+}
76853+#else
76854+#define atomic_read_unchecked(v) atomic_read(v)
76855+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76856+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76857+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76858+#define atomic_inc_unchecked(v) atomic_inc(v)
76859+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76860+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76861+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76862+#define atomic_dec_unchecked(v) atomic_dec(v)
76863+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76864+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76865+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76866+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76867+
76868+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76869+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76870+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76871+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76872+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76873+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76874+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76875+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76876+#endif
76877+
76878 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76879diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76880index 33bd2de..f31bff97 100644
76881--- a/include/asm-generic/atomic.h
76882+++ b/include/asm-generic/atomic.h
76883@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76884 * Atomically clears the bits set in @mask from @v
76885 */
76886 #ifndef atomic_clear_mask
76887-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76888+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76889 {
76890 unsigned long flags;
76891
76892diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76893index b18ce4f..2ee2843 100644
76894--- a/include/asm-generic/atomic64.h
76895+++ b/include/asm-generic/atomic64.h
76896@@ -16,6 +16,8 @@ typedef struct {
76897 long long counter;
76898 } atomic64_t;
76899
76900+typedef atomic64_t atomic64_unchecked_t;
76901+
76902 #define ATOMIC64_INIT(i) { (i) }
76903
76904 extern long long atomic64_read(const atomic64_t *v);
76905@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76906 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76907 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76908
76909+#define atomic64_read_unchecked(v) atomic64_read(v)
76910+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76911+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76912+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76913+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76914+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76915+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76916+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76917+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76918+
76919 #endif /* _ASM_GENERIC_ATOMIC64_H */
76920diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76921index a60a7cc..0fe12f2 100644
76922--- a/include/asm-generic/bitops/__fls.h
76923+++ b/include/asm-generic/bitops/__fls.h
76924@@ -9,7 +9,7 @@
76925 *
76926 * Undefined if no set bit exists, so code should check against 0 first.
76927 */
76928-static __always_inline unsigned long __fls(unsigned long word)
76929+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76930 {
76931 int num = BITS_PER_LONG - 1;
76932
76933diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76934index 0576d1f..dad6c71 100644
76935--- a/include/asm-generic/bitops/fls.h
76936+++ b/include/asm-generic/bitops/fls.h
76937@@ -9,7 +9,7 @@
76938 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76939 */
76940
76941-static __always_inline int fls(int x)
76942+static __always_inline int __intentional_overflow(-1) fls(int x)
76943 {
76944 int r = 32;
76945
76946diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76947index b097cf8..3d40e14 100644
76948--- a/include/asm-generic/bitops/fls64.h
76949+++ b/include/asm-generic/bitops/fls64.h
76950@@ -15,7 +15,7 @@
76951 * at position 64.
76952 */
76953 #if BITS_PER_LONG == 32
76954-static __always_inline int fls64(__u64 x)
76955+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76956 {
76957 __u32 h = x >> 32;
76958 if (h)
76959@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76960 return fls(x);
76961 }
76962 #elif BITS_PER_LONG == 64
76963-static __always_inline int fls64(__u64 x)
76964+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76965 {
76966 if (x == 0)
76967 return 0;
76968diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76969index 1bfcfe5..e04c5c9 100644
76970--- a/include/asm-generic/cache.h
76971+++ b/include/asm-generic/cache.h
76972@@ -6,7 +6,7 @@
76973 * cache lines need to provide their own cache.h.
76974 */
76975
76976-#define L1_CACHE_SHIFT 5
76977-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76978+#define L1_CACHE_SHIFT 5UL
76979+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76980
76981 #endif /* __ASM_GENERIC_CACHE_H */
76982diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76983index 0d68a1e..b74a761 100644
76984--- a/include/asm-generic/emergency-restart.h
76985+++ b/include/asm-generic/emergency-restart.h
76986@@ -1,7 +1,7 @@
76987 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76988 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76989
76990-static inline void machine_emergency_restart(void)
76991+static inline __noreturn void machine_emergency_restart(void)
76992 {
76993 machine_restart(NULL);
76994 }
76995diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76996index 90f99c7..00ce236 100644
76997--- a/include/asm-generic/kmap_types.h
76998+++ b/include/asm-generic/kmap_types.h
76999@@ -2,9 +2,9 @@
77000 #define _ASM_GENERIC_KMAP_TYPES_H
77001
77002 #ifdef __WITH_KM_FENCE
77003-# define KM_TYPE_NR 41
77004+# define KM_TYPE_NR 42
77005 #else
77006-# define KM_TYPE_NR 20
77007+# define KM_TYPE_NR 21
77008 #endif
77009
77010 #endif
77011diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77012index 9ceb03b..62b0b8f 100644
77013--- a/include/asm-generic/local.h
77014+++ b/include/asm-generic/local.h
77015@@ -23,24 +23,37 @@ typedef struct
77016 atomic_long_t a;
77017 } local_t;
77018
77019+typedef struct {
77020+ atomic_long_unchecked_t a;
77021+} local_unchecked_t;
77022+
77023 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77024
77025 #define local_read(l) atomic_long_read(&(l)->a)
77026+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77027 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77028+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77029 #define local_inc(l) atomic_long_inc(&(l)->a)
77030+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77031 #define local_dec(l) atomic_long_dec(&(l)->a)
77032+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77033 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77034+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77035 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77036+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77037
77038 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77039 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77040 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77041 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77042 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77043+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77044 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77045 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77046+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77047
77048 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77049+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77050 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77051 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77052 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77053diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77054index 725612b..9cc513a 100644
77055--- a/include/asm-generic/pgtable-nopmd.h
77056+++ b/include/asm-generic/pgtable-nopmd.h
77057@@ -1,14 +1,19 @@
77058 #ifndef _PGTABLE_NOPMD_H
77059 #define _PGTABLE_NOPMD_H
77060
77061-#ifndef __ASSEMBLY__
77062-
77063 #include <asm-generic/pgtable-nopud.h>
77064
77065-struct mm_struct;
77066-
77067 #define __PAGETABLE_PMD_FOLDED
77068
77069+#define PMD_SHIFT PUD_SHIFT
77070+#define PTRS_PER_PMD 1
77071+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77072+#define PMD_MASK (~(PMD_SIZE-1))
77073+
77074+#ifndef __ASSEMBLY__
77075+
77076+struct mm_struct;
77077+
77078 /*
77079 * Having the pmd type consist of a pud gets the size right, and allows
77080 * us to conceptually access the pud entry that this pmd is folded into
77081@@ -16,11 +21,6 @@ struct mm_struct;
77082 */
77083 typedef struct { pud_t pud; } pmd_t;
77084
77085-#define PMD_SHIFT PUD_SHIFT
77086-#define PTRS_PER_PMD 1
77087-#define PMD_SIZE (1UL << PMD_SHIFT)
77088-#define PMD_MASK (~(PMD_SIZE-1))
77089-
77090 /*
77091 * The "pud_xxx()" functions here are trivial for a folded two-level
77092 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77093diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77094index 810431d..0ec4804f 100644
77095--- a/include/asm-generic/pgtable-nopud.h
77096+++ b/include/asm-generic/pgtable-nopud.h
77097@@ -1,10 +1,15 @@
77098 #ifndef _PGTABLE_NOPUD_H
77099 #define _PGTABLE_NOPUD_H
77100
77101-#ifndef __ASSEMBLY__
77102-
77103 #define __PAGETABLE_PUD_FOLDED
77104
77105+#define PUD_SHIFT PGDIR_SHIFT
77106+#define PTRS_PER_PUD 1
77107+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77108+#define PUD_MASK (~(PUD_SIZE-1))
77109+
77110+#ifndef __ASSEMBLY__
77111+
77112 /*
77113 * Having the pud type consist of a pgd gets the size right, and allows
77114 * us to conceptually access the pgd entry that this pud is folded into
77115@@ -12,11 +17,6 @@
77116 */
77117 typedef struct { pgd_t pgd; } pud_t;
77118
77119-#define PUD_SHIFT PGDIR_SHIFT
77120-#define PTRS_PER_PUD 1
77121-#define PUD_SIZE (1UL << PUD_SHIFT)
77122-#define PUD_MASK (~(PUD_SIZE-1))
77123-
77124 /*
77125 * The "pgd_xxx()" functions here are trivial for a folded two-level
77126 * setup: the pud is never bad, and a pud always exists (as it's folded
77127@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77128 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77129
77130 #define pgd_populate(mm, pgd, pud) do { } while (0)
77131+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77132 /*
77133 * (puds are folded into pgds so this doesn't get actually called,
77134 * but the define is needed for a generic inline function.)
77135diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77136index 34c7bdc..38d4f3b 100644
77137--- a/include/asm-generic/pgtable.h
77138+++ b/include/asm-generic/pgtable.h
77139@@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77140 }
77141 #endif /* CONFIG_NUMA_BALANCING */
77142
77143+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77144+#ifdef CONFIG_PAX_KERNEXEC
77145+#error KERNEXEC requires pax_open_kernel
77146+#else
77147+static inline unsigned long pax_open_kernel(void) { return 0; }
77148+#endif
77149+#endif
77150+
77151+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77152+#ifdef CONFIG_PAX_KERNEXEC
77153+#error KERNEXEC requires pax_close_kernel
77154+#else
77155+static inline unsigned long pax_close_kernel(void) { return 0; }
77156+#endif
77157+#endif
77158+
77159 #endif /* CONFIG_MMU */
77160
77161 #endif /* !__ASSEMBLY__ */
77162diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77163index 72d8803..cb9749c 100644
77164--- a/include/asm-generic/uaccess.h
77165+++ b/include/asm-generic/uaccess.h
77166@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77167 return __clear_user(to, n);
77168 }
77169
77170+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77171+#ifdef CONFIG_PAX_MEMORY_UDEREF
77172+#error UDEREF requires pax_open_userland
77173+#else
77174+static inline unsigned long pax_open_userland(void) { return 0; }
77175+#endif
77176+#endif
77177+
77178+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77179+#ifdef CONFIG_PAX_MEMORY_UDEREF
77180+#error UDEREF requires pax_close_userland
77181+#else
77182+static inline unsigned long pax_close_userland(void) { return 0; }
77183+#endif
77184+#endif
77185+
77186 #endif /* __ASM_GENERIC_UACCESS_H */
77187diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77188index bc2121f..2f41f9a 100644
77189--- a/include/asm-generic/vmlinux.lds.h
77190+++ b/include/asm-generic/vmlinux.lds.h
77191@@ -232,6 +232,7 @@
77192 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77193 VMLINUX_SYMBOL(__start_rodata) = .; \
77194 *(.rodata) *(.rodata.*) \
77195+ *(.data..read_only) \
77196 *(__vermagic) /* Kernel version magic */ \
77197 . = ALIGN(8); \
77198 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77199@@ -716,17 +717,18 @@
77200 * section in the linker script will go there too. @phdr should have
77201 * a leading colon.
77202 *
77203- * Note that this macros defines __per_cpu_load as an absolute symbol.
77204+ * Note that this macros defines per_cpu_load as an absolute symbol.
77205 * If there is no need to put the percpu section at a predetermined
77206 * address, use PERCPU_SECTION.
77207 */
77208 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77209- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77210- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77211+ per_cpu_load = .; \
77212+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77213 - LOAD_OFFSET) { \
77214+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77215 PERCPU_INPUT(cacheline) \
77216 } phdr \
77217- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77218+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77219
77220 /**
77221 * PERCPU_SECTION - define output section for percpu area, simple version
77222diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77223index e73c19e..5b89e00 100644
77224--- a/include/crypto/algapi.h
77225+++ b/include/crypto/algapi.h
77226@@ -34,7 +34,7 @@ struct crypto_type {
77227 unsigned int maskclear;
77228 unsigned int maskset;
77229 unsigned int tfmsize;
77230-};
77231+} __do_const;
77232
77233 struct crypto_instance {
77234 struct crypto_alg alg;
77235diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77236index 04a7f31..668d424 100644
77237--- a/include/drm/drmP.h
77238+++ b/include/drm/drmP.h
77239@@ -67,6 +67,7 @@
77240 #include <linux/workqueue.h>
77241 #include <linux/poll.h>
77242 #include <asm/pgalloc.h>
77243+#include <asm/local.h>
77244 #include <drm/drm.h>
77245 #include <drm/drm_sarea.h>
77246 #include <drm/drm_vma_manager.h>
77247@@ -297,10 +298,12 @@ do { \
77248 * \param cmd command.
77249 * \param arg argument.
77250 */
77251-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77252+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77253+ struct drm_file *file_priv);
77254+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77255 struct drm_file *file_priv);
77256
77257-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77258+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77259 unsigned long arg);
77260
77261 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77262@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77263 struct drm_ioctl_desc {
77264 unsigned int cmd;
77265 int flags;
77266- drm_ioctl_t *func;
77267+ drm_ioctl_t func;
77268 unsigned int cmd_drv;
77269 const char *name;
77270-};
77271+} __do_const;
77272
77273 /**
77274 * Creates a driver or general drm_ioctl_desc array entry for the given
77275@@ -1022,7 +1025,8 @@ struct drm_info_list {
77276 int (*show)(struct seq_file*, void*); /** show callback */
77277 u32 driver_features; /**< Required driver features for this entry */
77278 void *data;
77279-};
77280+} __do_const;
77281+typedef struct drm_info_list __no_const drm_info_list_no_const;
77282
77283 /**
77284 * debugfs node structure. This structure represents a debugfs file.
77285@@ -1106,7 +1110,7 @@ struct drm_device {
77286
77287 /** \name Usage Counters */
77288 /*@{ */
77289- int open_count; /**< Outstanding files open */
77290+ local_t open_count; /**< Outstanding files open */
77291 int buf_use; /**< Buffers in use -- cannot alloc */
77292 atomic_t buf_alloc; /**< Buffer allocation in progress */
77293 /*@} */
77294diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77295index b1388b5..e1d1163 100644
77296--- a/include/drm/drm_crtc_helper.h
77297+++ b/include/drm/drm_crtc_helper.h
77298@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77299 struct drm_connector *connector);
77300 /* disable encoder when not in use - more explicit than dpms off */
77301 void (*disable)(struct drm_encoder *encoder);
77302-};
77303+} __no_const;
77304
77305 /**
77306 * drm_connector_helper_funcs - helper operations for connectors
77307diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77308index 940ece4..8cb727f 100644
77309--- a/include/drm/i915_pciids.h
77310+++ b/include/drm/i915_pciids.h
77311@@ -37,7 +37,7 @@
77312 */
77313 #define INTEL_VGA_DEVICE(id, info) { \
77314 0x8086, id, \
77315- ~0, ~0, \
77316+ PCI_ANY_ID, PCI_ANY_ID, \
77317 0x030000, 0xff0000, \
77318 (unsigned long) info }
77319
77320diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77321index 72dcbe8..8db58d7 100644
77322--- a/include/drm/ttm/ttm_memory.h
77323+++ b/include/drm/ttm/ttm_memory.h
77324@@ -48,7 +48,7 @@
77325
77326 struct ttm_mem_shrink {
77327 int (*do_shrink) (struct ttm_mem_shrink *);
77328-};
77329+} __no_const;
77330
77331 /**
77332 * struct ttm_mem_global - Global memory accounting structure.
77333diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77334index 49a8284..9643967 100644
77335--- a/include/drm/ttm/ttm_page_alloc.h
77336+++ b/include/drm/ttm/ttm_page_alloc.h
77337@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77338 */
77339 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77340
77341+struct device;
77342 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77343 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77344
77345diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77346index 4b840e8..155d235 100644
77347--- a/include/keys/asymmetric-subtype.h
77348+++ b/include/keys/asymmetric-subtype.h
77349@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77350 /* Verify the signature on a key of this subtype (optional) */
77351 int (*verify_signature)(const struct key *key,
77352 const struct public_key_signature *sig);
77353-};
77354+} __do_const;
77355
77356 /**
77357 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77358diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77359index c1da539..1dcec55 100644
77360--- a/include/linux/atmdev.h
77361+++ b/include/linux/atmdev.h
77362@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77363 #endif
77364
77365 struct k_atm_aal_stats {
77366-#define __HANDLE_ITEM(i) atomic_t i
77367+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77368 __AAL_STAT_ITEMS
77369 #undef __HANDLE_ITEM
77370 };
77371@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77372 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77373 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77374 struct module *owner;
77375-};
77376+} __do_const ;
77377
77378 struct atmphy_ops {
77379 int (*start)(struct atm_dev *dev);
77380diff --git a/include/linux/audit.h b/include/linux/audit.h
77381index ec1464d..833274b 100644
77382--- a/include/linux/audit.h
77383+++ b/include/linux/audit.h
77384@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77385 extern unsigned int audit_serial(void);
77386 extern int auditsc_get_stamp(struct audit_context *ctx,
77387 struct timespec *t, unsigned int *serial);
77388-extern int audit_set_loginuid(kuid_t loginuid);
77389+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77390
77391 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77392 {
77393diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77394index b4a745d..e3c0942 100644
77395--- a/include/linux/binfmts.h
77396+++ b/include/linux/binfmts.h
77397@@ -45,7 +45,7 @@ struct linux_binprm {
77398 unsigned interp_data;
77399 unsigned long loader, exec;
77400 char tcomm[TASK_COMM_LEN];
77401-};
77402+} __randomize_layout;
77403
77404 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77405 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77406@@ -74,8 +74,10 @@ struct linux_binfmt {
77407 int (*load_binary)(struct linux_binprm *);
77408 int (*load_shlib)(struct file *);
77409 int (*core_dump)(struct coredump_params *cprm);
77410+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77411+ void (*handle_mmap)(struct file *);
77412 unsigned long min_coredump; /* minimal dump size */
77413-};
77414+} __do_const __randomize_layout;
77415
77416 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77417
77418diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77419index be5fd38..d71192a 100644
77420--- a/include/linux/bitops.h
77421+++ b/include/linux/bitops.h
77422@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77423 * @word: value to rotate
77424 * @shift: bits to roll
77425 */
77426-static inline __u32 rol32(__u32 word, unsigned int shift)
77427+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77428 {
77429 return (word << shift) | (word >> (32 - shift));
77430 }
77431@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77432 * @word: value to rotate
77433 * @shift: bits to roll
77434 */
77435-static inline __u32 ror32(__u32 word, unsigned int shift)
77436+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77437 {
77438 return (word >> shift) | (word << (32 - shift));
77439 }
77440@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77441 return (__s32)(value << shift) >> shift;
77442 }
77443
77444-static inline unsigned fls_long(unsigned long l)
77445+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77446 {
77447 if (sizeof(l) == 4)
77448 return fls(l);
77449diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77450index 4afa4f8..1ed7824 100644
77451--- a/include/linux/blkdev.h
77452+++ b/include/linux/blkdev.h
77453@@ -1572,7 +1572,7 @@ struct block_device_operations {
77454 /* this callback is with swap_lock and sometimes page table lock held */
77455 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77456 struct module *owner;
77457-};
77458+} __do_const;
77459
77460 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77461 unsigned long);
77462diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77463index afc1343..9735539 100644
77464--- a/include/linux/blktrace_api.h
77465+++ b/include/linux/blktrace_api.h
77466@@ -25,7 +25,7 @@ struct blk_trace {
77467 struct dentry *dropped_file;
77468 struct dentry *msg_file;
77469 struct list_head running_list;
77470- atomic_t dropped;
77471+ atomic_unchecked_t dropped;
77472 };
77473
77474 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77475diff --git a/include/linux/cache.h b/include/linux/cache.h
77476index 17e7e82..1d7da26 100644
77477--- a/include/linux/cache.h
77478+++ b/include/linux/cache.h
77479@@ -16,6 +16,14 @@
77480 #define __read_mostly
77481 #endif
77482
77483+#ifndef __read_only
77484+#ifdef CONFIG_PAX_KERNEXEC
77485+#error KERNEXEC requires __read_only
77486+#else
77487+#define __read_only __read_mostly
77488+#endif
77489+#endif
77490+
77491 #ifndef ____cacheline_aligned
77492 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77493 #endif
77494diff --git a/include/linux/capability.h b/include/linux/capability.h
77495index a6ee1f9..e1ca49d 100644
77496--- a/include/linux/capability.h
77497+++ b/include/linux/capability.h
77498@@ -212,8 +212,13 @@ extern bool capable(int cap);
77499 extern bool ns_capable(struct user_namespace *ns, int cap);
77500 extern bool inode_capable(const struct inode *inode, int cap);
77501 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77502+extern bool capable_nolog(int cap);
77503+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77504+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77505
77506 /* audit system wants to get cap info from files as well */
77507 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77508
77509+extern int is_privileged_binary(const struct dentry *dentry);
77510+
77511 #endif /* !_LINUX_CAPABILITY_H */
77512diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77513index 8609d57..86e4d79 100644
77514--- a/include/linux/cdrom.h
77515+++ b/include/linux/cdrom.h
77516@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77517
77518 /* driver specifications */
77519 const int capability; /* capability flags */
77520- int n_minors; /* number of active minor devices */
77521 /* handle uniform packets for scsi type devices (scsi,atapi) */
77522 int (*generic_packet) (struct cdrom_device_info *,
77523 struct packet_command *);
77524diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77525index 4ce9056..86caac6 100644
77526--- a/include/linux/cleancache.h
77527+++ b/include/linux/cleancache.h
77528@@ -31,7 +31,7 @@ struct cleancache_ops {
77529 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77530 void (*invalidate_inode)(int, struct cleancache_filekey);
77531 void (*invalidate_fs)(int);
77532-};
77533+} __no_const;
77534
77535 extern struct cleancache_ops *
77536 cleancache_register_ops(struct cleancache_ops *ops);
77537diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77538index 939533d..cf0a57c 100644
77539--- a/include/linux/clk-provider.h
77540+++ b/include/linux/clk-provider.h
77541@@ -166,6 +166,7 @@ struct clk_ops {
77542 unsigned long parent_accuracy);
77543 void (*init)(struct clk_hw *hw);
77544 };
77545+typedef struct clk_ops __no_const clk_ops_no_const;
77546
77547 /**
77548 * struct clk_init_data - holds init data that's common to all clocks and is
77549diff --git a/include/linux/compat.h b/include/linux/compat.h
77550index 3f448c6..df3ce1d 100644
77551--- a/include/linux/compat.h
77552+++ b/include/linux/compat.h
77553@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77554 compat_size_t __user *len_ptr);
77555
77556 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77557-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77558+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77559 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77560 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77561 compat_ssize_t msgsz, int msgflg);
77562@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77563 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77564 compat_ulong_t addr, compat_ulong_t data);
77565 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77566- compat_long_t addr, compat_long_t data);
77567+ compat_ulong_t addr, compat_ulong_t data);
77568
77569 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77570 /*
77571diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77572index 2507fd2..55203f8 100644
77573--- a/include/linux/compiler-gcc4.h
77574+++ b/include/linux/compiler-gcc4.h
77575@@ -39,9 +39,34 @@
77576 # define __compiletime_warning(message) __attribute__((warning(message)))
77577 # define __compiletime_error(message) __attribute__((error(message)))
77578 #endif /* __CHECKER__ */
77579+
77580+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77581+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77582+#define __bos0(ptr) __bos((ptr), 0)
77583+#define __bos1(ptr) __bos((ptr), 1)
77584 #endif /* GCC_VERSION >= 40300 */
77585
77586 #if GCC_VERSION >= 40500
77587+
77588+#ifdef RANDSTRUCT_PLUGIN
77589+#define __randomize_layout __attribute__((randomize_layout))
77590+#define __no_randomize_layout __attribute__((no_randomize_layout))
77591+#endif
77592+
77593+#ifdef CONSTIFY_PLUGIN
77594+#define __no_const __attribute__((no_const))
77595+#define __do_const __attribute__((do_const))
77596+#endif
77597+
77598+#ifdef SIZE_OVERFLOW_PLUGIN
77599+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77600+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77601+#endif
77602+
77603+#ifdef LATENT_ENTROPY_PLUGIN
77604+#define __latent_entropy __attribute__((latent_entropy))
77605+#endif
77606+
77607 /*
77608 * Mark a position in code as unreachable. This can be used to
77609 * suppress control flow warnings after asm blocks that transfer
77610diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77611index 2472740..4857634 100644
77612--- a/include/linux/compiler.h
77613+++ b/include/linux/compiler.h
77614@@ -5,11 +5,14 @@
77615
77616 #ifdef __CHECKER__
77617 # define __user __attribute__((noderef, address_space(1)))
77618+# define __force_user __force __user
77619 # define __kernel __attribute__((address_space(0)))
77620+# define __force_kernel __force __kernel
77621 # define __safe __attribute__((safe))
77622 # define __force __attribute__((force))
77623 # define __nocast __attribute__((nocast))
77624 # define __iomem __attribute__((noderef, address_space(2)))
77625+# define __force_iomem __force __iomem
77626 # define __must_hold(x) __attribute__((context(x,1,1)))
77627 # define __acquires(x) __attribute__((context(x,0,1)))
77628 # define __releases(x) __attribute__((context(x,1,0)))
77629@@ -17,20 +20,37 @@
77630 # define __release(x) __context__(x,-1)
77631 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77632 # define __percpu __attribute__((noderef, address_space(3)))
77633+# define __force_percpu __force __percpu
77634 #ifdef CONFIG_SPARSE_RCU_POINTER
77635 # define __rcu __attribute__((noderef, address_space(4)))
77636+# define __force_rcu __force __rcu
77637 #else
77638 # define __rcu
77639+# define __force_rcu
77640 #endif
77641 extern void __chk_user_ptr(const volatile void __user *);
77642 extern void __chk_io_ptr(const volatile void __iomem *);
77643 #else
77644-# define __user
77645-# define __kernel
77646+# ifdef CHECKER_PLUGIN
77647+//# define __user
77648+//# define __force_user
77649+//# define __kernel
77650+//# define __force_kernel
77651+# else
77652+# ifdef STRUCTLEAK_PLUGIN
77653+# define __user __attribute__((user))
77654+# else
77655+# define __user
77656+# endif
77657+# define __force_user
77658+# define __kernel
77659+# define __force_kernel
77660+# endif
77661 # define __safe
77662 # define __force
77663 # define __nocast
77664 # define __iomem
77665+# define __force_iomem
77666 # define __chk_user_ptr(x) (void)0
77667 # define __chk_io_ptr(x) (void)0
77668 # define __builtin_warning(x, y...) (1)
77669@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77670 # define __release(x) (void)0
77671 # define __cond_lock(x,c) (c)
77672 # define __percpu
77673+# define __force_percpu
77674 # define __rcu
77675+# define __force_rcu
77676 #endif
77677
77678 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77679@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77680 # define __attribute_const__ /* unimplemented */
77681 #endif
77682
77683+#ifndef __randomize_layout
77684+# define __randomize_layout
77685+#endif
77686+
77687+#ifndef __no_randomize_layout
77688+# define __no_randomize_layout
77689+#endif
77690+
77691+#ifndef __no_const
77692+# define __no_const
77693+#endif
77694+
77695+#ifndef __do_const
77696+# define __do_const
77697+#endif
77698+
77699+#ifndef __size_overflow
77700+# define __size_overflow(...)
77701+#endif
77702+
77703+#ifndef __intentional_overflow
77704+# define __intentional_overflow(...)
77705+#endif
77706+
77707+#ifndef __latent_entropy
77708+# define __latent_entropy
77709+#endif
77710+
77711 /*
77712 * Tell gcc if a function is cold. The compiler will assume any path
77713 * directly leading to the call is unlikely.
77714@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77715 #define __cold
77716 #endif
77717
77718+#ifndef __alloc_size
77719+#define __alloc_size(...)
77720+#endif
77721+
77722+#ifndef __bos
77723+#define __bos(ptr, arg)
77724+#endif
77725+
77726+#ifndef __bos0
77727+#define __bos0(ptr)
77728+#endif
77729+
77730+#ifndef __bos1
77731+#define __bos1(ptr)
77732+#endif
77733+
77734 /* Simple shorthand for a section definition */
77735 #ifndef __section
77736 # define __section(S) __attribute__ ((__section__(#S)))
77737@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77738 * use is to mediate communication between process-level code and irq/NMI
77739 * handlers, all running on the same CPU.
77740 */
77741-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77742+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77743+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77744
77745 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77746 #ifdef CONFIG_KPROBES
77747diff --git a/include/linux/completion.h b/include/linux/completion.h
77748index 5d5aaae..0ea9b84 100644
77749--- a/include/linux/completion.h
77750+++ b/include/linux/completion.h
77751@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77752
77753 extern void wait_for_completion(struct completion *);
77754 extern void wait_for_completion_io(struct completion *);
77755-extern int wait_for_completion_interruptible(struct completion *x);
77756-extern int wait_for_completion_killable(struct completion *x);
77757+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77758+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77759 extern unsigned long wait_for_completion_timeout(struct completion *x,
77760- unsigned long timeout);
77761+ unsigned long timeout) __intentional_overflow(-1);
77762 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77763- unsigned long timeout);
77764+ unsigned long timeout) __intentional_overflow(-1);
77765 extern long wait_for_completion_interruptible_timeout(
77766- struct completion *x, unsigned long timeout);
77767+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77768 extern long wait_for_completion_killable_timeout(
77769- struct completion *x, unsigned long timeout);
77770+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77771 extern bool try_wait_for_completion(struct completion *x);
77772 extern bool completion_done(struct completion *x);
77773
77774diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77775index 34025df..d94bbbc 100644
77776--- a/include/linux/configfs.h
77777+++ b/include/linux/configfs.h
77778@@ -125,7 +125,7 @@ struct configfs_attribute {
77779 const char *ca_name;
77780 struct module *ca_owner;
77781 umode_t ca_mode;
77782-};
77783+} __do_const;
77784
77785 /*
77786 * Users often need to create attribute structures for their configurable
77787diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77788index 4d89e0e..5281847 100644
77789--- a/include/linux/cpufreq.h
77790+++ b/include/linux/cpufreq.h
77791@@ -191,6 +191,7 @@ struct global_attr {
77792 ssize_t (*store)(struct kobject *a, struct attribute *b,
77793 const char *c, size_t count);
77794 };
77795+typedef struct global_attr __no_const global_attr_no_const;
77796
77797 #define define_one_global_ro(_name) \
77798 static struct global_attr _name = \
77799@@ -232,7 +233,7 @@ struct cpufreq_driver {
77800 bool boost_supported;
77801 bool boost_enabled;
77802 int (*set_boost) (int state);
77803-};
77804+} __do_const;
77805
77806 /* flags */
77807 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77808diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77809index 50fcbb0..9d2dbd9 100644
77810--- a/include/linux/cpuidle.h
77811+++ b/include/linux/cpuidle.h
77812@@ -50,7 +50,8 @@ struct cpuidle_state {
77813 int index);
77814
77815 int (*enter_dead) (struct cpuidle_device *dev, int index);
77816-};
77817+} __do_const;
77818+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77819
77820 /* Idle State Flags */
77821 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77822@@ -192,7 +193,7 @@ struct cpuidle_governor {
77823 void (*reflect) (struct cpuidle_device *dev, int index);
77824
77825 struct module *owner;
77826-};
77827+} __do_const;
77828
77829 #ifdef CONFIG_CPU_IDLE
77830 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77831diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77832index d08e4d2..95fad61 100644
77833--- a/include/linux/cpumask.h
77834+++ b/include/linux/cpumask.h
77835@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77836 }
77837
77838 /* Valid inputs for n are -1 and 0. */
77839-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77840+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77841 {
77842 return n+1;
77843 }
77844
77845-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77846+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77847 {
77848 return n+1;
77849 }
77850
77851-static inline unsigned int cpumask_next_and(int n,
77852+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77853 const struct cpumask *srcp,
77854 const struct cpumask *andp)
77855 {
77856@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77857 *
77858 * Returns >= nr_cpu_ids if no further cpus set.
77859 */
77860-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77861+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77862 {
77863 /* -1 is a legal arg here. */
77864 if (n != -1)
77865@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77866 *
77867 * Returns >= nr_cpu_ids if no further cpus unset.
77868 */
77869-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77870+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77871 {
77872 /* -1 is a legal arg here. */
77873 if (n != -1)
77874@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77875 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77876 }
77877
77878-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77879+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77880 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77881
77882 /**
77883diff --git a/include/linux/cred.h b/include/linux/cred.h
77884index 04421e8..117e17a 100644
77885--- a/include/linux/cred.h
77886+++ b/include/linux/cred.h
77887@@ -35,7 +35,7 @@ struct group_info {
77888 int nblocks;
77889 kgid_t small_block[NGROUPS_SMALL];
77890 kgid_t *blocks[0];
77891-};
77892+} __randomize_layout;
77893
77894 /**
77895 * get_group_info - Get a reference to a group info structure
77896@@ -136,7 +136,7 @@ struct cred {
77897 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77898 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77899 struct rcu_head rcu; /* RCU deletion hook */
77900-};
77901+} __randomize_layout;
77902
77903 extern void __put_cred(struct cred *);
77904 extern void exit_creds(struct task_struct *);
77905@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77906 static inline void validate_process_creds(void)
77907 {
77908 }
77909+static inline void validate_task_creds(struct task_struct *task)
77910+{
77911+}
77912 #endif
77913
77914 /**
77915diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77916index b92eadf..b4ecdc1 100644
77917--- a/include/linux/crypto.h
77918+++ b/include/linux/crypto.h
77919@@ -373,7 +373,7 @@ struct cipher_tfm {
77920 const u8 *key, unsigned int keylen);
77921 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77922 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77923-};
77924+} __no_const;
77925
77926 struct hash_tfm {
77927 int (*init)(struct hash_desc *desc);
77928@@ -394,13 +394,13 @@ struct compress_tfm {
77929 int (*cot_decompress)(struct crypto_tfm *tfm,
77930 const u8 *src, unsigned int slen,
77931 u8 *dst, unsigned int *dlen);
77932-};
77933+} __no_const;
77934
77935 struct rng_tfm {
77936 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77937 unsigned int dlen);
77938 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77939-};
77940+} __no_const;
77941
77942 #define crt_ablkcipher crt_u.ablkcipher
77943 #define crt_aead crt_u.aead
77944diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77945index 653589e..4ef254a 100644
77946--- a/include/linux/ctype.h
77947+++ b/include/linux/ctype.h
77948@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77949 * Fast implementation of tolower() for internal usage. Do not use in your
77950 * code.
77951 */
77952-static inline char _tolower(const char c)
77953+static inline unsigned char _tolower(const unsigned char c)
77954 {
77955 return c | 0x20;
77956 }
77957diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77958index bf72e9a..4ca7927 100644
77959--- a/include/linux/dcache.h
77960+++ b/include/linux/dcache.h
77961@@ -133,7 +133,7 @@ struct dentry {
77962 } d_u;
77963 struct list_head d_subdirs; /* our children */
77964 struct hlist_node d_alias; /* inode alias list */
77965-};
77966+} __randomize_layout;
77967
77968 /*
77969 * dentry->d_lock spinlock nesting subclasses:
77970diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77971index 7925bf0..d5143d2 100644
77972--- a/include/linux/decompress/mm.h
77973+++ b/include/linux/decompress/mm.h
77974@@ -77,7 +77,7 @@ static void free(void *where)
77975 * warnings when not needed (indeed large_malloc / large_free are not
77976 * needed by inflate */
77977
77978-#define malloc(a) kmalloc(a, GFP_KERNEL)
77979+#define malloc(a) kmalloc((a), GFP_KERNEL)
77980 #define free(a) kfree(a)
77981
77982 #define large_malloc(a) vmalloc(a)
77983diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77984index d48dc00..211ee54 100644
77985--- a/include/linux/devfreq.h
77986+++ b/include/linux/devfreq.h
77987@@ -114,7 +114,7 @@ struct devfreq_governor {
77988 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77989 int (*event_handler)(struct devfreq *devfreq,
77990 unsigned int event, void *data);
77991-};
77992+} __do_const;
77993
77994 /**
77995 * struct devfreq - Device devfreq structure
77996diff --git a/include/linux/device.h b/include/linux/device.h
77997index 952b010..d5b7691 100644
77998--- a/include/linux/device.h
77999+++ b/include/linux/device.h
78000@@ -310,7 +310,7 @@ struct subsys_interface {
78001 struct list_head node;
78002 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78003 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78004-};
78005+} __do_const;
78006
78007 int subsys_interface_register(struct subsys_interface *sif);
78008 void subsys_interface_unregister(struct subsys_interface *sif);
78009@@ -506,7 +506,7 @@ struct device_type {
78010 void (*release)(struct device *dev);
78011
78012 const struct dev_pm_ops *pm;
78013-};
78014+} __do_const;
78015
78016 /* interface for exporting device attributes */
78017 struct device_attribute {
78018@@ -516,11 +516,12 @@ struct device_attribute {
78019 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78020 const char *buf, size_t count);
78021 };
78022+typedef struct device_attribute __no_const device_attribute_no_const;
78023
78024 struct dev_ext_attribute {
78025 struct device_attribute attr;
78026 void *var;
78027-};
78028+} __do_const;
78029
78030 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78031 char *buf);
78032diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78033index fd4aee2..1f28db9 100644
78034--- a/include/linux/dma-mapping.h
78035+++ b/include/linux/dma-mapping.h
78036@@ -54,7 +54,7 @@ struct dma_map_ops {
78037 u64 (*get_required_mask)(struct device *dev);
78038 #endif
78039 int is_phys;
78040-};
78041+} __do_const;
78042
78043 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78044
78045diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78046index c5c92d5..6a5c2b2 100644
78047--- a/include/linux/dmaengine.h
78048+++ b/include/linux/dmaengine.h
78049@@ -1150,9 +1150,9 @@ struct dma_pinned_list {
78050 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78051 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78052
78053-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78054+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78055 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78056-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78057+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78058 struct dma_pinned_list *pinned_list, struct page *page,
78059 unsigned int offset, size_t len);
78060
78061diff --git a/include/linux/efi.h b/include/linux/efi.h
78062index 0a819e7..8ed47f1 100644
78063--- a/include/linux/efi.h
78064+++ b/include/linux/efi.h
78065@@ -768,6 +768,7 @@ struct efivar_operations {
78066 efi_set_variable_t *set_variable;
78067 efi_query_variable_store_t *query_variable_store;
78068 };
78069+typedef struct efivar_operations __no_const efivar_operations_no_const;
78070
78071 struct efivars {
78072 /*
78073diff --git a/include/linux/elf.h b/include/linux/elf.h
78074index 67a5fa7..b817372 100644
78075--- a/include/linux/elf.h
78076+++ b/include/linux/elf.h
78077@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78078 #define elf_note elf32_note
78079 #define elf_addr_t Elf32_Off
78080 #define Elf_Half Elf32_Half
78081+#define elf_dyn Elf32_Dyn
78082
78083 #else
78084
78085@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78086 #define elf_note elf64_note
78087 #define elf_addr_t Elf64_Off
78088 #define Elf_Half Elf64_Half
78089+#define elf_dyn Elf64_Dyn
78090
78091 #endif
78092
78093diff --git a/include/linux/err.h b/include/linux/err.h
78094index 15f92e0..e825a8e 100644
78095--- a/include/linux/err.h
78096+++ b/include/linux/err.h
78097@@ -19,12 +19,12 @@
78098
78099 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78100
78101-static inline void * __must_check ERR_PTR(long error)
78102+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78103 {
78104 return (void *) error;
78105 }
78106
78107-static inline long __must_check PTR_ERR(__force const void *ptr)
78108+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78109 {
78110 return (long) ptr;
78111 }
78112diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78113index 21c59af..6057a03 100644
78114--- a/include/linux/extcon.h
78115+++ b/include/linux/extcon.h
78116@@ -135,7 +135,7 @@ struct extcon_dev {
78117 /* /sys/class/extcon/.../mutually_exclusive/... */
78118 struct attribute_group attr_g_muex;
78119 struct attribute **attrs_muex;
78120- struct device_attribute *d_attrs_muex;
78121+ device_attribute_no_const *d_attrs_muex;
78122 };
78123
78124 /**
78125diff --git a/include/linux/fb.h b/include/linux/fb.h
78126index fe6ac95..898d41d 100644
78127--- a/include/linux/fb.h
78128+++ b/include/linux/fb.h
78129@@ -304,7 +304,7 @@ struct fb_ops {
78130 /* called at KDB enter and leave time to prepare the console */
78131 int (*fb_debug_enter)(struct fb_info *info);
78132 int (*fb_debug_leave)(struct fb_info *info);
78133-};
78134+} __do_const;
78135
78136 #ifdef CONFIG_FB_TILEBLITTING
78137 #define FB_TILE_CURSOR_NONE 0
78138diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78139index 70e8e21..1939916 100644
78140--- a/include/linux/fdtable.h
78141+++ b/include/linux/fdtable.h
78142@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78143 void put_files_struct(struct files_struct *fs);
78144 void reset_files_struct(struct files_struct *);
78145 int unshare_files(struct files_struct **);
78146-struct files_struct *dup_fd(struct files_struct *, int *);
78147+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78148 void do_close_on_exec(struct files_struct *);
78149 int iterate_fd(struct files_struct *, unsigned,
78150 int (*)(const void *, struct file *, unsigned),
78151diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78152index 8293262..2b3b8bd 100644
78153--- a/include/linux/frontswap.h
78154+++ b/include/linux/frontswap.h
78155@@ -11,7 +11,7 @@ struct frontswap_ops {
78156 int (*load)(unsigned, pgoff_t, struct page *);
78157 void (*invalidate_page)(unsigned, pgoff_t);
78158 void (*invalidate_area)(unsigned);
78159-};
78160+} __no_const;
78161
78162 extern bool frontswap_enabled;
78163 extern struct frontswap_ops *
78164diff --git a/include/linux/fs.h b/include/linux/fs.h
78165index 23b2a35..8764ab7 100644
78166--- a/include/linux/fs.h
78167+++ b/include/linux/fs.h
78168@@ -426,7 +426,7 @@ struct address_space {
78169 spinlock_t private_lock; /* for use by the address_space */
78170 struct list_head private_list; /* ditto */
78171 void *private_data; /* ditto */
78172-} __attribute__((aligned(sizeof(long))));
78173+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78174 /*
78175 * On most architectures that alignment is already the case; but
78176 * must be enforced here for CRIS, to let the least significant bit
78177@@ -469,7 +469,7 @@ struct block_device {
78178 int bd_fsfreeze_count;
78179 /* Mutex for freeze */
78180 struct mutex bd_fsfreeze_mutex;
78181-};
78182+} __randomize_layout;
78183
78184 /*
78185 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78186@@ -613,7 +613,7 @@ struct inode {
78187 atomic_t i_readcount; /* struct files open RO */
78188 #endif
78189 void *i_private; /* fs or device private pointer */
78190-};
78191+} __randomize_layout;
78192
78193 static inline int inode_unhashed(struct inode *inode)
78194 {
78195@@ -812,7 +812,7 @@ struct file {
78196 #ifdef CONFIG_DEBUG_WRITECOUNT
78197 unsigned long f_mnt_write_state;
78198 #endif
78199-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78200+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78201
78202 struct file_handle {
78203 __u32 handle_bytes;
78204@@ -982,7 +982,7 @@ struct file_lock {
78205 int state; /* state of grant or error if -ve */
78206 } afs;
78207 } fl_u;
78208-};
78209+} __randomize_layout;
78210
78211 /* The following constant reflects the upper bound of the file/locking space */
78212 #ifndef OFFSET_MAX
78213@@ -1329,7 +1329,7 @@ struct super_block {
78214 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78215 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78216 struct rcu_head rcu;
78217-};
78218+} __randomize_layout;
78219
78220 extern struct timespec current_fs_time(struct super_block *sb);
78221
78222@@ -1551,7 +1551,8 @@ struct file_operations {
78223 long (*fallocate)(struct file *file, int mode, loff_t offset,
78224 loff_t len);
78225 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78226-};
78227+} __do_const __randomize_layout;
78228+typedef struct file_operations __no_const file_operations_no_const;
78229
78230 struct inode_operations {
78231 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78232@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78233 return !IS_DEADDIR(inode);
78234 }
78235
78236+static inline bool is_sidechannel_device(const struct inode *inode)
78237+{
78238+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78239+ umode_t mode = inode->i_mode;
78240+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78241+#else
78242+ return false;
78243+#endif
78244+}
78245+
78246 #endif /* _LINUX_FS_H */
78247diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78248index 0efc3e6..fd23610 100644
78249--- a/include/linux/fs_struct.h
78250+++ b/include/linux/fs_struct.h
78251@@ -6,13 +6,13 @@
78252 #include <linux/seqlock.h>
78253
78254 struct fs_struct {
78255- int users;
78256+ atomic_t users;
78257 spinlock_t lock;
78258 seqcount_t seq;
78259 int umask;
78260 int in_exec;
78261 struct path root, pwd;
78262-};
78263+} __randomize_layout;
78264
78265 extern struct kmem_cache *fs_cachep;
78266
78267diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78268index 7714849..a4a5c7a 100644
78269--- a/include/linux/fscache-cache.h
78270+++ b/include/linux/fscache-cache.h
78271@@ -113,7 +113,7 @@ struct fscache_operation {
78272 fscache_operation_release_t release;
78273 };
78274
78275-extern atomic_t fscache_op_debug_id;
78276+extern atomic_unchecked_t fscache_op_debug_id;
78277 extern void fscache_op_work_func(struct work_struct *work);
78278
78279 extern void fscache_enqueue_operation(struct fscache_operation *);
78280@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78281 INIT_WORK(&op->work, fscache_op_work_func);
78282 atomic_set(&op->usage, 1);
78283 op->state = FSCACHE_OP_ST_INITIALISED;
78284- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78285+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78286 op->processor = processor;
78287 op->release = release;
78288 INIT_LIST_HEAD(&op->pend_link);
78289diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78290index 115bb81..e7b812b 100644
78291--- a/include/linux/fscache.h
78292+++ b/include/linux/fscache.h
78293@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78294 * - this is mandatory for any object that may have data
78295 */
78296 void (*now_uncached)(void *cookie_netfs_data);
78297-};
78298+} __do_const;
78299
78300 /*
78301 * fscache cached network filesystem type
78302diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78303index 1c804b0..1432c2b 100644
78304--- a/include/linux/fsnotify.h
78305+++ b/include/linux/fsnotify.h
78306@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78307 struct inode *inode = file_inode(file);
78308 __u32 mask = FS_ACCESS;
78309
78310+ if (is_sidechannel_device(inode))
78311+ return;
78312+
78313 if (S_ISDIR(inode->i_mode))
78314 mask |= FS_ISDIR;
78315
78316@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78317 struct inode *inode = file_inode(file);
78318 __u32 mask = FS_MODIFY;
78319
78320+ if (is_sidechannel_device(inode))
78321+ return;
78322+
78323 if (S_ISDIR(inode->i_mode))
78324 mask |= FS_ISDIR;
78325
78326@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78327 */
78328 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78329 {
78330- return kstrdup(name, GFP_KERNEL);
78331+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78332 }
78333
78334 /*
78335diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78336index 9f3c275..8bdff5d 100644
78337--- a/include/linux/genhd.h
78338+++ b/include/linux/genhd.h
78339@@ -194,7 +194,7 @@ struct gendisk {
78340 struct kobject *slave_dir;
78341
78342 struct timer_rand_state *random;
78343- atomic_t sync_io; /* RAID */
78344+ atomic_unchecked_t sync_io; /* RAID */
78345 struct disk_events *ev;
78346 #ifdef CONFIG_BLK_DEV_INTEGRITY
78347 struct blk_integrity *integrity;
78348@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78349 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78350
78351 /* drivers/char/random.c */
78352-extern void add_disk_randomness(struct gendisk *disk);
78353+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78354 extern void rand_initialize_disk(struct gendisk *disk);
78355
78356 static inline sector_t get_start_sect(struct block_device *bdev)
78357diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78358index c0894dd..2fbf10c 100644
78359--- a/include/linux/genl_magic_func.h
78360+++ b/include/linux/genl_magic_func.h
78361@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78362 },
78363
78364 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78365-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78366+static struct genl_ops ZZZ_genl_ops[] = {
78367 #include GENL_MAGIC_INCLUDE_FILE
78368 };
78369
78370diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78371index 39b81dc..819dc51 100644
78372--- a/include/linux/gfp.h
78373+++ b/include/linux/gfp.h
78374@@ -36,6 +36,13 @@ struct vm_area_struct;
78375 #define ___GFP_NO_KSWAPD 0x400000u
78376 #define ___GFP_OTHER_NODE 0x800000u
78377 #define ___GFP_WRITE 0x1000000u
78378+
78379+#ifdef CONFIG_PAX_USERCOPY_SLABS
78380+#define ___GFP_USERCOPY 0x2000000u
78381+#else
78382+#define ___GFP_USERCOPY 0
78383+#endif
78384+
78385 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78386
78387 /*
78388@@ -93,6 +100,7 @@ struct vm_area_struct;
78389 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78390 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78391 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78392+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78393
78394 /*
78395 * This may seem redundant, but it's a way of annotating false positives vs.
78396@@ -100,7 +108,7 @@ struct vm_area_struct;
78397 */
78398 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78399
78400-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78401+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78402 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78403
78404 /* This equals 0, but use constants in case they ever change */
78405@@ -158,6 +166,8 @@ struct vm_area_struct;
78406 /* 4GB DMA on some platforms */
78407 #define GFP_DMA32 __GFP_DMA32
78408
78409+#define GFP_USERCOPY __GFP_USERCOPY
78410+
78411 /* Convert GFP flags to their corresponding migrate type */
78412 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78413 {
78414diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78415new file mode 100644
78416index 0000000..edb2cb6
78417--- /dev/null
78418+++ b/include/linux/gracl.h
78419@@ -0,0 +1,340 @@
78420+#ifndef GR_ACL_H
78421+#define GR_ACL_H
78422+
78423+#include <linux/grdefs.h>
78424+#include <linux/resource.h>
78425+#include <linux/capability.h>
78426+#include <linux/dcache.h>
78427+#include <asm/resource.h>
78428+
78429+/* Major status information */
78430+
78431+#define GR_VERSION "grsecurity 3.0"
78432+#define GRSECURITY_VERSION 0x3000
78433+
78434+enum {
78435+ GR_SHUTDOWN = 0,
78436+ GR_ENABLE = 1,
78437+ GR_SPROLE = 2,
78438+ GR_OLDRELOAD = 3,
78439+ GR_SEGVMOD = 4,
78440+ GR_STATUS = 5,
78441+ GR_UNSPROLE = 6,
78442+ GR_PASSSET = 7,
78443+ GR_SPROLEPAM = 8,
78444+ GR_RELOAD = 9,
78445+};
78446+
78447+/* Password setup definitions
78448+ * kernel/grhash.c */
78449+enum {
78450+ GR_PW_LEN = 128,
78451+ GR_SALT_LEN = 16,
78452+ GR_SHA_LEN = 32,
78453+};
78454+
78455+enum {
78456+ GR_SPROLE_LEN = 64,
78457+};
78458+
78459+enum {
78460+ GR_NO_GLOB = 0,
78461+ GR_REG_GLOB,
78462+ GR_CREATE_GLOB
78463+};
78464+
78465+#define GR_NLIMITS 32
78466+
78467+/* Begin Data Structures */
78468+
78469+struct sprole_pw {
78470+ unsigned char *rolename;
78471+ unsigned char salt[GR_SALT_LEN];
78472+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78473+};
78474+
78475+struct name_entry {
78476+ __u32 key;
78477+ ino_t inode;
78478+ dev_t device;
78479+ char *name;
78480+ __u16 len;
78481+ __u8 deleted;
78482+ struct name_entry *prev;
78483+ struct name_entry *next;
78484+};
78485+
78486+struct inodev_entry {
78487+ struct name_entry *nentry;
78488+ struct inodev_entry *prev;
78489+ struct inodev_entry *next;
78490+};
78491+
78492+struct acl_role_db {
78493+ struct acl_role_label **r_hash;
78494+ __u32 r_size;
78495+};
78496+
78497+struct inodev_db {
78498+ struct inodev_entry **i_hash;
78499+ __u32 i_size;
78500+};
78501+
78502+struct name_db {
78503+ struct name_entry **n_hash;
78504+ __u32 n_size;
78505+};
78506+
78507+struct crash_uid {
78508+ uid_t uid;
78509+ unsigned long expires;
78510+};
78511+
78512+struct gr_hash_struct {
78513+ void **table;
78514+ void **nametable;
78515+ void *first;
78516+ __u32 table_size;
78517+ __u32 used_size;
78518+ int type;
78519+};
78520+
78521+/* Userspace Grsecurity ACL data structures */
78522+
78523+struct acl_subject_label {
78524+ char *filename;
78525+ ino_t inode;
78526+ dev_t device;
78527+ __u32 mode;
78528+ kernel_cap_t cap_mask;
78529+ kernel_cap_t cap_lower;
78530+ kernel_cap_t cap_invert_audit;
78531+
78532+ struct rlimit res[GR_NLIMITS];
78533+ __u32 resmask;
78534+
78535+ __u8 user_trans_type;
78536+ __u8 group_trans_type;
78537+ uid_t *user_transitions;
78538+ gid_t *group_transitions;
78539+ __u16 user_trans_num;
78540+ __u16 group_trans_num;
78541+
78542+ __u32 sock_families[2];
78543+ __u32 ip_proto[8];
78544+ __u32 ip_type;
78545+ struct acl_ip_label **ips;
78546+ __u32 ip_num;
78547+ __u32 inaddr_any_override;
78548+
78549+ __u32 crashes;
78550+ unsigned long expires;
78551+
78552+ struct acl_subject_label *parent_subject;
78553+ struct gr_hash_struct *hash;
78554+ struct acl_subject_label *prev;
78555+ struct acl_subject_label *next;
78556+
78557+ struct acl_object_label **obj_hash;
78558+ __u32 obj_hash_size;
78559+ __u16 pax_flags;
78560+};
78561+
78562+struct role_allowed_ip {
78563+ __u32 addr;
78564+ __u32 netmask;
78565+
78566+ struct role_allowed_ip *prev;
78567+ struct role_allowed_ip *next;
78568+};
78569+
78570+struct role_transition {
78571+ char *rolename;
78572+
78573+ struct role_transition *prev;
78574+ struct role_transition *next;
78575+};
78576+
78577+struct acl_role_label {
78578+ char *rolename;
78579+ uid_t uidgid;
78580+ __u16 roletype;
78581+
78582+ __u16 auth_attempts;
78583+ unsigned long expires;
78584+
78585+ struct acl_subject_label *root_label;
78586+ struct gr_hash_struct *hash;
78587+
78588+ struct acl_role_label *prev;
78589+ struct acl_role_label *next;
78590+
78591+ struct role_transition *transitions;
78592+ struct role_allowed_ip *allowed_ips;
78593+ uid_t *domain_children;
78594+ __u16 domain_child_num;
78595+
78596+ umode_t umask;
78597+
78598+ struct acl_subject_label **subj_hash;
78599+ __u32 subj_hash_size;
78600+};
78601+
78602+struct user_acl_role_db {
78603+ struct acl_role_label **r_table;
78604+ __u32 num_pointers; /* Number of allocations to track */
78605+ __u32 num_roles; /* Number of roles */
78606+ __u32 num_domain_children; /* Number of domain children */
78607+ __u32 num_subjects; /* Number of subjects */
78608+ __u32 num_objects; /* Number of objects */
78609+};
78610+
78611+struct acl_object_label {
78612+ char *filename;
78613+ ino_t inode;
78614+ dev_t device;
78615+ __u32 mode;
78616+
78617+ struct acl_subject_label *nested;
78618+ struct acl_object_label *globbed;
78619+
78620+ /* next two structures not used */
78621+
78622+ struct acl_object_label *prev;
78623+ struct acl_object_label *next;
78624+};
78625+
78626+struct acl_ip_label {
78627+ char *iface;
78628+ __u32 addr;
78629+ __u32 netmask;
78630+ __u16 low, high;
78631+ __u8 mode;
78632+ __u32 type;
78633+ __u32 proto[8];
78634+
78635+ /* next two structures not used */
78636+
78637+ struct acl_ip_label *prev;
78638+ struct acl_ip_label *next;
78639+};
78640+
78641+struct gr_arg {
78642+ struct user_acl_role_db role_db;
78643+ unsigned char pw[GR_PW_LEN];
78644+ unsigned char salt[GR_SALT_LEN];
78645+ unsigned char sum[GR_SHA_LEN];
78646+ unsigned char sp_role[GR_SPROLE_LEN];
78647+ struct sprole_pw *sprole_pws;
78648+ dev_t segv_device;
78649+ ino_t segv_inode;
78650+ uid_t segv_uid;
78651+ __u16 num_sprole_pws;
78652+ __u16 mode;
78653+};
78654+
78655+struct gr_arg_wrapper {
78656+ struct gr_arg *arg;
78657+ __u32 version;
78658+ __u32 size;
78659+};
78660+
78661+struct subject_map {
78662+ struct acl_subject_label *user;
78663+ struct acl_subject_label *kernel;
78664+ struct subject_map *prev;
78665+ struct subject_map *next;
78666+};
78667+
78668+struct acl_subj_map_db {
78669+ struct subject_map **s_hash;
78670+ __u32 s_size;
78671+};
78672+
78673+struct gr_policy_state {
78674+ struct sprole_pw **acl_special_roles;
78675+ __u16 num_sprole_pws;
78676+ struct acl_role_label *kernel_role;
78677+ struct acl_role_label *role_list;
78678+ struct acl_role_label *default_role;
78679+ struct acl_role_db acl_role_set;
78680+ struct acl_subj_map_db subj_map_set;
78681+ struct name_db name_set;
78682+ struct inodev_db inodev_set;
78683+};
78684+
78685+struct gr_alloc_state {
78686+ unsigned long alloc_stack_next;
78687+ unsigned long alloc_stack_size;
78688+ void **alloc_stack;
78689+};
78690+
78691+struct gr_reload_state {
78692+ struct gr_policy_state oldpolicy;
78693+ struct gr_alloc_state oldalloc;
78694+ struct gr_policy_state newpolicy;
78695+ struct gr_alloc_state newalloc;
78696+ struct gr_policy_state *oldpolicy_ptr;
78697+ struct gr_alloc_state *oldalloc_ptr;
78698+ unsigned char oldmode;
78699+};
78700+
78701+/* End Data Structures Section */
78702+
78703+/* Hash functions generated by empirical testing by Brad Spengler
78704+ Makes good use of the low bits of the inode. Generally 0-1 times
78705+ in loop for successful match. 0-3 for unsuccessful match.
78706+ Shift/add algorithm with modulus of table size and an XOR*/
78707+
78708+static __inline__ unsigned int
78709+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78710+{
78711+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78712+}
78713+
78714+ static __inline__ unsigned int
78715+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78716+{
78717+ return ((const unsigned long)userp % sz);
78718+}
78719+
78720+static __inline__ unsigned int
78721+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78722+{
78723+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78724+}
78725+
78726+static __inline__ unsigned int
78727+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78728+{
78729+ return full_name_hash((const unsigned char *)name, len) % sz;
78730+}
78731+
78732+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78733+ subj = NULL; \
78734+ iter = 0; \
78735+ while (iter < role->subj_hash_size) { \
78736+ if (subj == NULL) \
78737+ subj = role->subj_hash[iter]; \
78738+ if (subj == NULL) { \
78739+ iter++; \
78740+ continue; \
78741+ }
78742+
78743+#define FOR_EACH_SUBJECT_END(subj,iter) \
78744+ subj = subj->next; \
78745+ if (subj == NULL) \
78746+ iter++; \
78747+ }
78748+
78749+
78750+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78751+ subj = role->hash->first; \
78752+ while (subj != NULL) {
78753+
78754+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78755+ subj = subj->next; \
78756+ }
78757+
78758+#endif
78759+
78760diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78761new file mode 100644
78762index 0000000..33ebd1f
78763--- /dev/null
78764+++ b/include/linux/gracl_compat.h
78765@@ -0,0 +1,156 @@
78766+#ifndef GR_ACL_COMPAT_H
78767+#define GR_ACL_COMPAT_H
78768+
78769+#include <linux/resource.h>
78770+#include <asm/resource.h>
78771+
78772+struct sprole_pw_compat {
78773+ compat_uptr_t rolename;
78774+ unsigned char salt[GR_SALT_LEN];
78775+ unsigned char sum[GR_SHA_LEN];
78776+};
78777+
78778+struct gr_hash_struct_compat {
78779+ compat_uptr_t table;
78780+ compat_uptr_t nametable;
78781+ compat_uptr_t first;
78782+ __u32 table_size;
78783+ __u32 used_size;
78784+ int type;
78785+};
78786+
78787+struct acl_subject_label_compat {
78788+ compat_uptr_t filename;
78789+ compat_ino_t inode;
78790+ __u32 device;
78791+ __u32 mode;
78792+ kernel_cap_t cap_mask;
78793+ kernel_cap_t cap_lower;
78794+ kernel_cap_t cap_invert_audit;
78795+
78796+ struct compat_rlimit res[GR_NLIMITS];
78797+ __u32 resmask;
78798+
78799+ __u8 user_trans_type;
78800+ __u8 group_trans_type;
78801+ compat_uptr_t user_transitions;
78802+ compat_uptr_t group_transitions;
78803+ __u16 user_trans_num;
78804+ __u16 group_trans_num;
78805+
78806+ __u32 sock_families[2];
78807+ __u32 ip_proto[8];
78808+ __u32 ip_type;
78809+ compat_uptr_t ips;
78810+ __u32 ip_num;
78811+ __u32 inaddr_any_override;
78812+
78813+ __u32 crashes;
78814+ compat_ulong_t expires;
78815+
78816+ compat_uptr_t parent_subject;
78817+ compat_uptr_t hash;
78818+ compat_uptr_t prev;
78819+ compat_uptr_t next;
78820+
78821+ compat_uptr_t obj_hash;
78822+ __u32 obj_hash_size;
78823+ __u16 pax_flags;
78824+};
78825+
78826+struct role_allowed_ip_compat {
78827+ __u32 addr;
78828+ __u32 netmask;
78829+
78830+ compat_uptr_t prev;
78831+ compat_uptr_t next;
78832+};
78833+
78834+struct role_transition_compat {
78835+ compat_uptr_t rolename;
78836+
78837+ compat_uptr_t prev;
78838+ compat_uptr_t next;
78839+};
78840+
78841+struct acl_role_label_compat {
78842+ compat_uptr_t rolename;
78843+ uid_t uidgid;
78844+ __u16 roletype;
78845+
78846+ __u16 auth_attempts;
78847+ compat_ulong_t expires;
78848+
78849+ compat_uptr_t root_label;
78850+ compat_uptr_t hash;
78851+
78852+ compat_uptr_t prev;
78853+ compat_uptr_t next;
78854+
78855+ compat_uptr_t transitions;
78856+ compat_uptr_t allowed_ips;
78857+ compat_uptr_t domain_children;
78858+ __u16 domain_child_num;
78859+
78860+ umode_t umask;
78861+
78862+ compat_uptr_t subj_hash;
78863+ __u32 subj_hash_size;
78864+};
78865+
78866+struct user_acl_role_db_compat {
78867+ compat_uptr_t r_table;
78868+ __u32 num_pointers;
78869+ __u32 num_roles;
78870+ __u32 num_domain_children;
78871+ __u32 num_subjects;
78872+ __u32 num_objects;
78873+};
78874+
78875+struct acl_object_label_compat {
78876+ compat_uptr_t filename;
78877+ compat_ino_t inode;
78878+ __u32 device;
78879+ __u32 mode;
78880+
78881+ compat_uptr_t nested;
78882+ compat_uptr_t globbed;
78883+
78884+ compat_uptr_t prev;
78885+ compat_uptr_t next;
78886+};
78887+
78888+struct acl_ip_label_compat {
78889+ compat_uptr_t iface;
78890+ __u32 addr;
78891+ __u32 netmask;
78892+ __u16 low, high;
78893+ __u8 mode;
78894+ __u32 type;
78895+ __u32 proto[8];
78896+
78897+ compat_uptr_t prev;
78898+ compat_uptr_t next;
78899+};
78900+
78901+struct gr_arg_compat {
78902+ struct user_acl_role_db_compat role_db;
78903+ unsigned char pw[GR_PW_LEN];
78904+ unsigned char salt[GR_SALT_LEN];
78905+ unsigned char sum[GR_SHA_LEN];
78906+ unsigned char sp_role[GR_SPROLE_LEN];
78907+ compat_uptr_t sprole_pws;
78908+ __u32 segv_device;
78909+ compat_ino_t segv_inode;
78910+ uid_t segv_uid;
78911+ __u16 num_sprole_pws;
78912+ __u16 mode;
78913+};
78914+
78915+struct gr_arg_wrapper_compat {
78916+ compat_uptr_t arg;
78917+ __u32 version;
78918+ __u32 size;
78919+};
78920+
78921+#endif
78922diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78923new file mode 100644
78924index 0000000..323ecf2
78925--- /dev/null
78926+++ b/include/linux/gralloc.h
78927@@ -0,0 +1,9 @@
78928+#ifndef __GRALLOC_H
78929+#define __GRALLOC_H
78930+
78931+void acl_free_all(void);
78932+int acl_alloc_stack_init(unsigned long size);
78933+void *acl_alloc(unsigned long len);
78934+void *acl_alloc_num(unsigned long num, unsigned long len);
78935+
78936+#endif
78937diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78938new file mode 100644
78939index 0000000..be66033
78940--- /dev/null
78941+++ b/include/linux/grdefs.h
78942@@ -0,0 +1,140 @@
78943+#ifndef GRDEFS_H
78944+#define GRDEFS_H
78945+
78946+/* Begin grsecurity status declarations */
78947+
78948+enum {
78949+ GR_READY = 0x01,
78950+ GR_STATUS_INIT = 0x00 // disabled state
78951+};
78952+
78953+/* Begin ACL declarations */
78954+
78955+/* Role flags */
78956+
78957+enum {
78958+ GR_ROLE_USER = 0x0001,
78959+ GR_ROLE_GROUP = 0x0002,
78960+ GR_ROLE_DEFAULT = 0x0004,
78961+ GR_ROLE_SPECIAL = 0x0008,
78962+ GR_ROLE_AUTH = 0x0010,
78963+ GR_ROLE_NOPW = 0x0020,
78964+ GR_ROLE_GOD = 0x0040,
78965+ GR_ROLE_LEARN = 0x0080,
78966+ GR_ROLE_TPE = 0x0100,
78967+ GR_ROLE_DOMAIN = 0x0200,
78968+ GR_ROLE_PAM = 0x0400,
78969+ GR_ROLE_PERSIST = 0x0800
78970+};
78971+
78972+/* ACL Subject and Object mode flags */
78973+enum {
78974+ GR_DELETED = 0x80000000
78975+};
78976+
78977+/* ACL Object-only mode flags */
78978+enum {
78979+ GR_READ = 0x00000001,
78980+ GR_APPEND = 0x00000002,
78981+ GR_WRITE = 0x00000004,
78982+ GR_EXEC = 0x00000008,
78983+ GR_FIND = 0x00000010,
78984+ GR_INHERIT = 0x00000020,
78985+ GR_SETID = 0x00000040,
78986+ GR_CREATE = 0x00000080,
78987+ GR_DELETE = 0x00000100,
78988+ GR_LINK = 0x00000200,
78989+ GR_AUDIT_READ = 0x00000400,
78990+ GR_AUDIT_APPEND = 0x00000800,
78991+ GR_AUDIT_WRITE = 0x00001000,
78992+ GR_AUDIT_EXEC = 0x00002000,
78993+ GR_AUDIT_FIND = 0x00004000,
78994+ GR_AUDIT_INHERIT= 0x00008000,
78995+ GR_AUDIT_SETID = 0x00010000,
78996+ GR_AUDIT_CREATE = 0x00020000,
78997+ GR_AUDIT_DELETE = 0x00040000,
78998+ GR_AUDIT_LINK = 0x00080000,
78999+ GR_PTRACERD = 0x00100000,
79000+ GR_NOPTRACE = 0x00200000,
79001+ GR_SUPPRESS = 0x00400000,
79002+ GR_NOLEARN = 0x00800000,
79003+ GR_INIT_TRANSFER= 0x01000000
79004+};
79005+
79006+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79007+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79008+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79009+
79010+/* ACL subject-only mode flags */
79011+enum {
79012+ GR_KILL = 0x00000001,
79013+ GR_VIEW = 0x00000002,
79014+ GR_PROTECTED = 0x00000004,
79015+ GR_LEARN = 0x00000008,
79016+ GR_OVERRIDE = 0x00000010,
79017+ /* just a placeholder, this mode is only used in userspace */
79018+ GR_DUMMY = 0x00000020,
79019+ GR_PROTSHM = 0x00000040,
79020+ GR_KILLPROC = 0x00000080,
79021+ GR_KILLIPPROC = 0x00000100,
79022+ /* just a placeholder, this mode is only used in userspace */
79023+ GR_NOTROJAN = 0x00000200,
79024+ GR_PROTPROCFD = 0x00000400,
79025+ GR_PROCACCT = 0x00000800,
79026+ GR_RELAXPTRACE = 0x00001000,
79027+ //GR_NESTED = 0x00002000,
79028+ GR_INHERITLEARN = 0x00004000,
79029+ GR_PROCFIND = 0x00008000,
79030+ GR_POVERRIDE = 0x00010000,
79031+ GR_KERNELAUTH = 0x00020000,
79032+ GR_ATSECURE = 0x00040000,
79033+ GR_SHMEXEC = 0x00080000
79034+};
79035+
79036+enum {
79037+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79038+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79039+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79040+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79041+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79042+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79043+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79044+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79045+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79046+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79047+};
79048+
79049+enum {
79050+ GR_ID_USER = 0x01,
79051+ GR_ID_GROUP = 0x02,
79052+};
79053+
79054+enum {
79055+ GR_ID_ALLOW = 0x01,
79056+ GR_ID_DENY = 0x02,
79057+};
79058+
79059+#define GR_CRASH_RES 31
79060+#define GR_UIDTABLE_MAX 500
79061+
79062+/* begin resource learning section */
79063+enum {
79064+ GR_RLIM_CPU_BUMP = 60,
79065+ GR_RLIM_FSIZE_BUMP = 50000,
79066+ GR_RLIM_DATA_BUMP = 10000,
79067+ GR_RLIM_STACK_BUMP = 1000,
79068+ GR_RLIM_CORE_BUMP = 10000,
79069+ GR_RLIM_RSS_BUMP = 500000,
79070+ GR_RLIM_NPROC_BUMP = 1,
79071+ GR_RLIM_NOFILE_BUMP = 5,
79072+ GR_RLIM_MEMLOCK_BUMP = 50000,
79073+ GR_RLIM_AS_BUMP = 500000,
79074+ GR_RLIM_LOCKS_BUMP = 2,
79075+ GR_RLIM_SIGPENDING_BUMP = 5,
79076+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79077+ GR_RLIM_NICE_BUMP = 1,
79078+ GR_RLIM_RTPRIO_BUMP = 1,
79079+ GR_RLIM_RTTIME_BUMP = 1000000
79080+};
79081+
79082+#endif
79083diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79084new file mode 100644
79085index 0000000..d25522e
79086--- /dev/null
79087+++ b/include/linux/grinternal.h
79088@@ -0,0 +1,229 @@
79089+#ifndef __GRINTERNAL_H
79090+#define __GRINTERNAL_H
79091+
79092+#ifdef CONFIG_GRKERNSEC
79093+
79094+#include <linux/fs.h>
79095+#include <linux/mnt_namespace.h>
79096+#include <linux/nsproxy.h>
79097+#include <linux/gracl.h>
79098+#include <linux/grdefs.h>
79099+#include <linux/grmsg.h>
79100+
79101+void gr_add_learn_entry(const char *fmt, ...)
79102+ __attribute__ ((format (printf, 1, 2)));
79103+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79104+ const struct vfsmount *mnt);
79105+__u32 gr_check_create(const struct dentry *new_dentry,
79106+ const struct dentry *parent,
79107+ const struct vfsmount *mnt, const __u32 mode);
79108+int gr_check_protected_task(const struct task_struct *task);
79109+__u32 to_gr_audit(const __u32 reqmode);
79110+int gr_set_acls(const int type);
79111+int gr_acl_is_enabled(void);
79112+char gr_roletype_to_char(void);
79113+
79114+void gr_handle_alertkill(struct task_struct *task);
79115+char *gr_to_filename(const struct dentry *dentry,
79116+ const struct vfsmount *mnt);
79117+char *gr_to_filename1(const struct dentry *dentry,
79118+ const struct vfsmount *mnt);
79119+char *gr_to_filename2(const struct dentry *dentry,
79120+ const struct vfsmount *mnt);
79121+char *gr_to_filename3(const struct dentry *dentry,
79122+ const struct vfsmount *mnt);
79123+
79124+extern int grsec_enable_ptrace_readexec;
79125+extern int grsec_enable_harden_ptrace;
79126+extern int grsec_enable_link;
79127+extern int grsec_enable_fifo;
79128+extern int grsec_enable_execve;
79129+extern int grsec_enable_shm;
79130+extern int grsec_enable_execlog;
79131+extern int grsec_enable_signal;
79132+extern int grsec_enable_audit_ptrace;
79133+extern int grsec_enable_forkfail;
79134+extern int grsec_enable_time;
79135+extern int grsec_enable_rofs;
79136+extern int grsec_deny_new_usb;
79137+extern int grsec_enable_chroot_shmat;
79138+extern int grsec_enable_chroot_mount;
79139+extern int grsec_enable_chroot_double;
79140+extern int grsec_enable_chroot_pivot;
79141+extern int grsec_enable_chroot_chdir;
79142+extern int grsec_enable_chroot_chmod;
79143+extern int grsec_enable_chroot_mknod;
79144+extern int grsec_enable_chroot_fchdir;
79145+extern int grsec_enable_chroot_nice;
79146+extern int grsec_enable_chroot_execlog;
79147+extern int grsec_enable_chroot_caps;
79148+extern int grsec_enable_chroot_sysctl;
79149+extern int grsec_enable_chroot_unix;
79150+extern int grsec_enable_symlinkown;
79151+extern kgid_t grsec_symlinkown_gid;
79152+extern int grsec_enable_tpe;
79153+extern kgid_t grsec_tpe_gid;
79154+extern int grsec_enable_tpe_all;
79155+extern int grsec_enable_tpe_invert;
79156+extern int grsec_enable_socket_all;
79157+extern kgid_t grsec_socket_all_gid;
79158+extern int grsec_enable_socket_client;
79159+extern kgid_t grsec_socket_client_gid;
79160+extern int grsec_enable_socket_server;
79161+extern kgid_t grsec_socket_server_gid;
79162+extern kgid_t grsec_audit_gid;
79163+extern int grsec_enable_group;
79164+extern int grsec_enable_log_rwxmaps;
79165+extern int grsec_enable_mount;
79166+extern int grsec_enable_chdir;
79167+extern int grsec_resource_logging;
79168+extern int grsec_enable_blackhole;
79169+extern int grsec_lastack_retries;
79170+extern int grsec_enable_brute;
79171+extern int grsec_enable_harden_ipc;
79172+extern int grsec_lock;
79173+
79174+extern spinlock_t grsec_alert_lock;
79175+extern unsigned long grsec_alert_wtime;
79176+extern unsigned long grsec_alert_fyet;
79177+
79178+extern spinlock_t grsec_audit_lock;
79179+
79180+extern rwlock_t grsec_exec_file_lock;
79181+
79182+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79183+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79184+ (tsk)->exec_file->f_path.mnt) : "/")
79185+
79186+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79187+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79188+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79189+
79190+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79191+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79192+ (tsk)->exec_file->f_path.mnt) : "/")
79193+
79194+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79195+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79196+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79197+
79198+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79199+
79200+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79201+
79202+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79203+{
79204+ if (file1 && file2) {
79205+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79206+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79207+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79208+ return true;
79209+ }
79210+
79211+ return false;
79212+}
79213+
79214+#define GR_CHROOT_CAPS {{ \
79215+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79216+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79217+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79218+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79219+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79220+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79221+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79222+
79223+#define security_learn(normal_msg,args...) \
79224+({ \
79225+ read_lock(&grsec_exec_file_lock); \
79226+ gr_add_learn_entry(normal_msg "\n", ## args); \
79227+ read_unlock(&grsec_exec_file_lock); \
79228+})
79229+
79230+enum {
79231+ GR_DO_AUDIT,
79232+ GR_DONT_AUDIT,
79233+ /* used for non-audit messages that we shouldn't kill the task on */
79234+ GR_DONT_AUDIT_GOOD
79235+};
79236+
79237+enum {
79238+ GR_TTYSNIFF,
79239+ GR_RBAC,
79240+ GR_RBAC_STR,
79241+ GR_STR_RBAC,
79242+ GR_RBAC_MODE2,
79243+ GR_RBAC_MODE3,
79244+ GR_FILENAME,
79245+ GR_SYSCTL_HIDDEN,
79246+ GR_NOARGS,
79247+ GR_ONE_INT,
79248+ GR_ONE_INT_TWO_STR,
79249+ GR_ONE_STR,
79250+ GR_STR_INT,
79251+ GR_TWO_STR_INT,
79252+ GR_TWO_INT,
79253+ GR_TWO_U64,
79254+ GR_THREE_INT,
79255+ GR_FIVE_INT_TWO_STR,
79256+ GR_TWO_STR,
79257+ GR_THREE_STR,
79258+ GR_FOUR_STR,
79259+ GR_STR_FILENAME,
79260+ GR_FILENAME_STR,
79261+ GR_FILENAME_TWO_INT,
79262+ GR_FILENAME_TWO_INT_STR,
79263+ GR_TEXTREL,
79264+ GR_PTRACE,
79265+ GR_RESOURCE,
79266+ GR_CAP,
79267+ GR_SIG,
79268+ GR_SIG2,
79269+ GR_CRASH1,
79270+ GR_CRASH2,
79271+ GR_PSACCT,
79272+ GR_RWXMAP,
79273+ GR_RWXMAPVMA
79274+};
79275+
79276+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79277+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79278+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79279+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79280+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79281+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79282+#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)
79283+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79284+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79285+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79286+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79287+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79288+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79289+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79290+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79291+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79292+#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)
79293+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79294+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79295+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79296+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79297+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79298+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79299+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79300+#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)
79301+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79302+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79303+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79304+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79305+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79306+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79307+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79308+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79309+#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)
79310+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79311+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79312+
79313+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79314+
79315+#endif
79316+
79317+#endif
79318diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79319new file mode 100644
79320index 0000000..ba93581
79321--- /dev/null
79322+++ b/include/linux/grmsg.h
79323@@ -0,0 +1,116 @@
79324+#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"
79325+#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"
79326+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79327+#define GR_STOPMOD_MSG "denied modification of module state by "
79328+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79329+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79330+#define GR_IOPERM_MSG "denied use of ioperm() by "
79331+#define GR_IOPL_MSG "denied use of iopl() by "
79332+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79333+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79334+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79335+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79336+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79337+#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"
79338+#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"
79339+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79340+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79341+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79342+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79343+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79344+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79345+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79346+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79347+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79348+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79349+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79350+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79351+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79352+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79353+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79354+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79355+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79356+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79357+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79358+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79359+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79360+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79361+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79362+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79363+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79364+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79365+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79366+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79367+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79368+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79369+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79370+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79371+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79372+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79373+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79374+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79375+#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"
79376+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79377+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79378+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79379+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79380+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79381+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79382+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79383+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79384+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79385+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79386+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79387+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79388+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79389+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79390+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79391+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79392+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79393+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79394+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79395+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79396+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79397+#define GR_NICE_CHROOT_MSG "denied priority change by "
79398+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79399+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79400+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79401+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79402+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79403+#define GR_TIME_MSG "time set by "
79404+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79405+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79406+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79407+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79408+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79409+#define GR_BIND_MSG "denied bind() by "
79410+#define GR_CONNECT_MSG "denied connect() by "
79411+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79412+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79413+#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"
79414+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79415+#define GR_CAP_ACL_MSG "use of %s denied for "
79416+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79417+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79418+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79419+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79420+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79421+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79422+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79423+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79424+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79425+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79426+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79427+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79428+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79429+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79430+#define GR_VM86_MSG "denied use of vm86 by "
79431+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79432+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79433+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79434+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79435+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79436+#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 "
79437+#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 "
79438+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79439+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79440diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79441new file mode 100644
79442index 0000000..f2d8c6c
79443--- /dev/null
79444+++ b/include/linux/grsecurity.h
79445@@ -0,0 +1,248 @@
79446+#ifndef GR_SECURITY_H
79447+#define GR_SECURITY_H
79448+#include <linux/fs.h>
79449+#include <linux/fs_struct.h>
79450+#include <linux/binfmts.h>
79451+#include <linux/gracl.h>
79452+
79453+/* notify of brain-dead configs */
79454+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79455+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79456+#endif
79457+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79458+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79459+#endif
79460+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79461+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79462+#endif
79463+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79464+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79465+#endif
79466+
79467+int gr_handle_new_usb(void);
79468+
79469+void gr_handle_brute_attach(int dumpable);
79470+void gr_handle_brute_check(void);
79471+void gr_handle_kernel_exploit(void);
79472+
79473+char gr_roletype_to_char(void);
79474+
79475+int gr_proc_is_restricted(void);
79476+
79477+int gr_acl_enable_at_secure(void);
79478+
79479+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79480+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79481+
79482+void gr_del_task_from_ip_table(struct task_struct *p);
79483+
79484+int gr_pid_is_chrooted(struct task_struct *p);
79485+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79486+int gr_handle_chroot_nice(void);
79487+int gr_handle_chroot_sysctl(const int op);
79488+int gr_handle_chroot_setpriority(struct task_struct *p,
79489+ const int niceval);
79490+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79491+int gr_handle_chroot_chroot(const struct dentry *dentry,
79492+ const struct vfsmount *mnt);
79493+void gr_handle_chroot_chdir(const struct path *path);
79494+int gr_handle_chroot_chmod(const struct dentry *dentry,
79495+ const struct vfsmount *mnt, const int mode);
79496+int gr_handle_chroot_mknod(const struct dentry *dentry,
79497+ const struct vfsmount *mnt, const int mode);
79498+int gr_handle_chroot_mount(const struct dentry *dentry,
79499+ const struct vfsmount *mnt,
79500+ const char *dev_name);
79501+int gr_handle_chroot_pivot(void);
79502+int gr_handle_chroot_unix(const pid_t pid);
79503+
79504+int gr_handle_rawio(const struct inode *inode);
79505+
79506+void gr_handle_ioperm(void);
79507+void gr_handle_iopl(void);
79508+void gr_handle_msr_write(void);
79509+
79510+umode_t gr_acl_umask(void);
79511+
79512+int gr_tpe_allow(const struct file *file);
79513+
79514+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79515+void gr_clear_chroot_entries(struct task_struct *task);
79516+
79517+void gr_log_forkfail(const int retval);
79518+void gr_log_timechange(void);
79519+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79520+void gr_log_chdir(const struct dentry *dentry,
79521+ const struct vfsmount *mnt);
79522+void gr_log_chroot_exec(const struct dentry *dentry,
79523+ const struct vfsmount *mnt);
79524+void gr_log_remount(const char *devname, const int retval);
79525+void gr_log_unmount(const char *devname, const int retval);
79526+void gr_log_mount(const char *from, const char *to, const int retval);
79527+void gr_log_textrel(struct vm_area_struct *vma);
79528+void gr_log_ptgnustack(struct file *file);
79529+void gr_log_rwxmmap(struct file *file);
79530+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79531+
79532+int gr_handle_follow_link(const struct inode *parent,
79533+ const struct inode *inode,
79534+ const struct dentry *dentry,
79535+ const struct vfsmount *mnt);
79536+int gr_handle_fifo(const struct dentry *dentry,
79537+ const struct vfsmount *mnt,
79538+ const struct dentry *dir, const int flag,
79539+ const int acc_mode);
79540+int gr_handle_hardlink(const struct dentry *dentry,
79541+ const struct vfsmount *mnt,
79542+ struct inode *inode,
79543+ const int mode, const struct filename *to);
79544+
79545+int gr_is_capable(const int cap);
79546+int gr_is_capable_nolog(const int cap);
79547+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79548+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79549+
79550+void gr_copy_label(struct task_struct *tsk);
79551+void gr_handle_crash(struct task_struct *task, const int sig);
79552+int gr_handle_signal(const struct task_struct *p, const int sig);
79553+int gr_check_crash_uid(const kuid_t uid);
79554+int gr_check_protected_task(const struct task_struct *task);
79555+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79556+int gr_acl_handle_mmap(const struct file *file,
79557+ const unsigned long prot);
79558+int gr_acl_handle_mprotect(const struct file *file,
79559+ const unsigned long prot);
79560+int gr_check_hidden_task(const struct task_struct *tsk);
79561+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79562+ const struct vfsmount *mnt);
79563+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79564+ const struct vfsmount *mnt);
79565+__u32 gr_acl_handle_access(const struct dentry *dentry,
79566+ const struct vfsmount *mnt, const int fmode);
79567+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79568+ const struct vfsmount *mnt, umode_t *mode);
79569+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79570+ const struct vfsmount *mnt);
79571+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79572+ const struct vfsmount *mnt);
79573+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79574+ const struct vfsmount *mnt);
79575+int gr_handle_ptrace(struct task_struct *task, const long request);
79576+int gr_handle_proc_ptrace(struct task_struct *task);
79577+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79578+ const struct vfsmount *mnt);
79579+int gr_check_crash_exec(const struct file *filp);
79580+int gr_acl_is_enabled(void);
79581+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79582+ const kgid_t gid);
79583+int gr_set_proc_label(const struct dentry *dentry,
79584+ const struct vfsmount *mnt,
79585+ const int unsafe_flags);
79586+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79587+ const struct vfsmount *mnt);
79588+__u32 gr_acl_handle_open(const struct dentry *dentry,
79589+ const struct vfsmount *mnt, int acc_mode);
79590+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79591+ const struct dentry *p_dentry,
79592+ const struct vfsmount *p_mnt,
79593+ int open_flags, int acc_mode, const int imode);
79594+void gr_handle_create(const struct dentry *dentry,
79595+ const struct vfsmount *mnt);
79596+void gr_handle_proc_create(const struct dentry *dentry,
79597+ const struct inode *inode);
79598+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79599+ const struct dentry *parent_dentry,
79600+ const struct vfsmount *parent_mnt,
79601+ const int mode);
79602+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79603+ const struct dentry *parent_dentry,
79604+ const struct vfsmount *parent_mnt);
79605+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79606+ const struct vfsmount *mnt);
79607+void gr_handle_delete(const ino_t ino, const dev_t dev);
79608+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79609+ const struct vfsmount *mnt);
79610+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79611+ const struct dentry *parent_dentry,
79612+ const struct vfsmount *parent_mnt,
79613+ const struct filename *from);
79614+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79615+ const struct dentry *parent_dentry,
79616+ const struct vfsmount *parent_mnt,
79617+ const struct dentry *old_dentry,
79618+ const struct vfsmount *old_mnt, const struct filename *to);
79619+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79620+int gr_acl_handle_rename(struct dentry *new_dentry,
79621+ struct dentry *parent_dentry,
79622+ const struct vfsmount *parent_mnt,
79623+ struct dentry *old_dentry,
79624+ struct inode *old_parent_inode,
79625+ struct vfsmount *old_mnt, const struct filename *newname);
79626+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79627+ struct dentry *old_dentry,
79628+ struct dentry *new_dentry,
79629+ struct vfsmount *mnt, const __u8 replace);
79630+__u32 gr_check_link(const struct dentry *new_dentry,
79631+ const struct dentry *parent_dentry,
79632+ const struct vfsmount *parent_mnt,
79633+ const struct dentry *old_dentry,
79634+ const struct vfsmount *old_mnt);
79635+int gr_acl_handle_filldir(const struct file *file, const char *name,
79636+ const unsigned int namelen, const ino_t ino);
79637+
79638+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79639+ const struct vfsmount *mnt);
79640+void gr_acl_handle_exit(void);
79641+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79642+int gr_acl_handle_procpidmem(const struct task_struct *task);
79643+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79644+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79645+void gr_audit_ptrace(struct task_struct *task);
79646+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79647+void gr_put_exec_file(struct task_struct *task);
79648+
79649+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79650+
79651+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79652+extern void gr_learn_resource(const struct task_struct *task, const int res,
79653+ const unsigned long wanted, const int gt);
79654+#else
79655+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79656+ const unsigned long wanted, const int gt)
79657+{
79658+}
79659+#endif
79660+
79661+#ifdef CONFIG_GRKERNSEC_RESLOG
79662+extern void gr_log_resource(const struct task_struct *task, const int res,
79663+ const unsigned long wanted, const int gt);
79664+#else
79665+static inline void gr_log_resource(const struct task_struct *task, const int res,
79666+ const unsigned long wanted, const int gt)
79667+{
79668+}
79669+#endif
79670+
79671+#ifdef CONFIG_GRKERNSEC
79672+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79673+void gr_handle_vm86(void);
79674+void gr_handle_mem_readwrite(u64 from, u64 to);
79675+
79676+void gr_log_badprocpid(const char *entry);
79677+
79678+extern int grsec_enable_dmesg;
79679+extern int grsec_disable_privio;
79680+
79681+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79682+extern kgid_t grsec_proc_gid;
79683+#endif
79684+
79685+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79686+extern int grsec_enable_chroot_findtask;
79687+#endif
79688+#ifdef CONFIG_GRKERNSEC_SETXID
79689+extern int grsec_enable_setxid;
79690+#endif
79691+#endif
79692+
79693+#endif
79694diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79695new file mode 100644
79696index 0000000..e7ffaaf
79697--- /dev/null
79698+++ b/include/linux/grsock.h
79699@@ -0,0 +1,19 @@
79700+#ifndef __GRSOCK_H
79701+#define __GRSOCK_H
79702+
79703+extern void gr_attach_curr_ip(const struct sock *sk);
79704+extern int gr_handle_sock_all(const int family, const int type,
79705+ const int protocol);
79706+extern int gr_handle_sock_server(const struct sockaddr *sck);
79707+extern int gr_handle_sock_server_other(const struct sock *sck);
79708+extern int gr_handle_sock_client(const struct sockaddr *sck);
79709+extern int gr_search_connect(struct socket * sock,
79710+ struct sockaddr_in * addr);
79711+extern int gr_search_bind(struct socket * sock,
79712+ struct sockaddr_in * addr);
79713+extern int gr_search_listen(struct socket * sock);
79714+extern int gr_search_accept(struct socket * sock);
79715+extern int gr_search_socket(const int domain, const int type,
79716+ const int protocol);
79717+
79718+#endif
79719diff --git a/include/linux/hash.h b/include/linux/hash.h
79720index bd1754c..8240892 100644
79721--- a/include/linux/hash.h
79722+++ b/include/linux/hash.h
79723@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79724 struct fast_hash_ops {
79725 u32 (*hash)(const void *data, u32 len, u32 seed);
79726 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79727-};
79728+} __no_const;
79729
79730 /**
79731 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79732diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79733index 7fb31da..08b5114 100644
79734--- a/include/linux/highmem.h
79735+++ b/include/linux/highmem.h
79736@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79737 kunmap_atomic(kaddr);
79738 }
79739
79740+static inline void sanitize_highpage(struct page *page)
79741+{
79742+ void *kaddr;
79743+ unsigned long flags;
79744+
79745+ local_irq_save(flags);
79746+ kaddr = kmap_atomic(page);
79747+ clear_page(kaddr);
79748+ kunmap_atomic(kaddr);
79749+ local_irq_restore(flags);
79750+}
79751+
79752 static inline void zero_user_segments(struct page *page,
79753 unsigned start1, unsigned end1,
79754 unsigned start2, unsigned end2)
79755diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79756index 1c7b89a..7dda400 100644
79757--- a/include/linux/hwmon-sysfs.h
79758+++ b/include/linux/hwmon-sysfs.h
79759@@ -25,7 +25,8 @@
79760 struct sensor_device_attribute{
79761 struct device_attribute dev_attr;
79762 int index;
79763-};
79764+} __do_const;
79765+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79766 #define to_sensor_dev_attr(_dev_attr) \
79767 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79768
79769@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79770 struct device_attribute dev_attr;
79771 u8 index;
79772 u8 nr;
79773-};
79774+} __do_const;
79775+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79776 #define to_sensor_dev_attr_2(_dev_attr) \
79777 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79778
79779diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79780index deddeb8..bcaf62d 100644
79781--- a/include/linux/i2c.h
79782+++ b/include/linux/i2c.h
79783@@ -378,6 +378,7 @@ struct i2c_algorithm {
79784 /* To determine what the adapter supports */
79785 u32 (*functionality) (struct i2c_adapter *);
79786 };
79787+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79788
79789 /**
79790 * struct i2c_bus_recovery_info - I2C bus recovery information
79791diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79792index d23c3c2..eb63c81 100644
79793--- a/include/linux/i2o.h
79794+++ b/include/linux/i2o.h
79795@@ -565,7 +565,7 @@ struct i2o_controller {
79796 struct i2o_device *exec; /* Executive */
79797 #if BITS_PER_LONG == 64
79798 spinlock_t context_list_lock; /* lock for context_list */
79799- atomic_t context_list_counter; /* needed for unique contexts */
79800+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79801 struct list_head context_list; /* list of context id's
79802 and pointers */
79803 #endif
79804diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79805index aff7ad8..3942bbd 100644
79806--- a/include/linux/if_pppox.h
79807+++ b/include/linux/if_pppox.h
79808@@ -76,7 +76,7 @@ struct pppox_proto {
79809 int (*ioctl)(struct socket *sock, unsigned int cmd,
79810 unsigned long arg);
79811 struct module *owner;
79812-};
79813+} __do_const;
79814
79815 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79816 extern void unregister_pppox_proto(int proto_num);
79817diff --git a/include/linux/init.h b/include/linux/init.h
79818index e168880..d9b489d 100644
79819--- a/include/linux/init.h
79820+++ b/include/linux/init.h
79821@@ -37,9 +37,17 @@
79822 * section.
79823 */
79824
79825+#define add_init_latent_entropy __latent_entropy
79826+
79827+#ifdef CONFIG_MEMORY_HOTPLUG
79828+#define add_meminit_latent_entropy
79829+#else
79830+#define add_meminit_latent_entropy __latent_entropy
79831+#endif
79832+
79833 /* These are for everybody (although not all archs will actually
79834 discard it in modules) */
79835-#define __init __section(.init.text) __cold notrace
79836+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79837 #define __initdata __section(.init.data)
79838 #define __initconst __constsection(.init.rodata)
79839 #define __exitdata __section(.exit.data)
79840@@ -100,7 +108,7 @@
79841 #define __cpuexitconst
79842
79843 /* Used for MEMORY_HOTPLUG */
79844-#define __meminit __section(.meminit.text) __cold notrace
79845+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79846 #define __meminitdata __section(.meminit.data)
79847 #define __meminitconst __constsection(.meminit.rodata)
79848 #define __memexit __section(.memexit.text) __exitused __cold notrace
79849diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79850index 6df7f9f..d0bf699 100644
79851--- a/include/linux/init_task.h
79852+++ b/include/linux/init_task.h
79853@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79854
79855 #define INIT_TASK_COMM "swapper"
79856
79857+#ifdef CONFIG_X86
79858+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79859+#else
79860+#define INIT_TASK_THREAD_INFO
79861+#endif
79862+
79863 #ifdef CONFIG_RT_MUTEXES
79864 # define INIT_RT_MUTEXES(tsk) \
79865 .pi_waiters = RB_ROOT, \
79866@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79867 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79868 .comm = INIT_TASK_COMM, \
79869 .thread = INIT_THREAD, \
79870+ INIT_TASK_THREAD_INFO \
79871 .fs = &init_fs, \
79872 .files = &init_files, \
79873 .signal = &init_signals, \
79874diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79875index a2678d3..e411b1b 100644
79876--- a/include/linux/interrupt.h
79877+++ b/include/linux/interrupt.h
79878@@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79879
79880 struct softirq_action
79881 {
79882- void (*action)(struct softirq_action *);
79883-};
79884+ void (*action)(void);
79885+} __no_const;
79886
79887 asmlinkage void do_softirq(void);
79888 asmlinkage void __do_softirq(void);
79889@@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
79890 }
79891 #endif
79892
79893-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79894+extern void open_softirq(int nr, void (*action)(void));
79895 extern void softirq_init(void);
79896 extern void __raise_softirq_irqoff(unsigned int nr);
79897
79898diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79899index b96a5b2..2732d1c 100644
79900--- a/include/linux/iommu.h
79901+++ b/include/linux/iommu.h
79902@@ -131,7 +131,7 @@ struct iommu_ops {
79903 u32 (*domain_get_windows)(struct iommu_domain *domain);
79904
79905 unsigned long pgsize_bitmap;
79906-};
79907+} __do_const;
79908
79909 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79910 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79911diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79912index 89b7c24..382af74 100644
79913--- a/include/linux/ioport.h
79914+++ b/include/linux/ioport.h
79915@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79916 int adjust_resource(struct resource *res, resource_size_t start,
79917 resource_size_t size);
79918 resource_size_t resource_alignment(struct resource *res);
79919-static inline resource_size_t resource_size(const struct resource *res)
79920+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79921 {
79922 return res->end - res->start + 1;
79923 }
79924diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79925index 35e7eca..6afb7ad 100644
79926--- a/include/linux/ipc_namespace.h
79927+++ b/include/linux/ipc_namespace.h
79928@@ -69,7 +69,7 @@ struct ipc_namespace {
79929 struct user_namespace *user_ns;
79930
79931 unsigned int proc_inum;
79932-};
79933+} __randomize_layout;
79934
79935 extern struct ipc_namespace init_ipc_ns;
79936 extern atomic_t nr_ipc_ns;
79937diff --git a/include/linux/irq.h b/include/linux/irq.h
79938index 7dc1003..407327b 100644
79939--- a/include/linux/irq.h
79940+++ b/include/linux/irq.h
79941@@ -338,7 +338,8 @@ struct irq_chip {
79942 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79943
79944 unsigned long flags;
79945-};
79946+} __do_const;
79947+typedef struct irq_chip __no_const irq_chip_no_const;
79948
79949 /*
79950 * irq_chip specific flags
79951diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79952index 0ceb389..eed3fb8 100644
79953--- a/include/linux/irqchip/arm-gic.h
79954+++ b/include/linux/irqchip/arm-gic.h
79955@@ -73,9 +73,11 @@
79956
79957 #ifndef __ASSEMBLY__
79958
79959+#include <linux/irq.h>
79960+
79961 struct device_node;
79962
79963-extern struct irq_chip gic_arch_extn;
79964+extern irq_chip_no_const gic_arch_extn;
79965
79966 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79967 u32 offset, struct device_node *);
79968diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79969index 1f44466..b481806 100644
79970--- a/include/linux/jiffies.h
79971+++ b/include/linux/jiffies.h
79972@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
79973 /*
79974 * Convert various time units to each other:
79975 */
79976-extern unsigned int jiffies_to_msecs(const unsigned long j);
79977-extern unsigned int jiffies_to_usecs(const unsigned long j);
79978+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79979+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79980
79981-static inline u64 jiffies_to_nsecs(const unsigned long j)
79982+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
79983 {
79984 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
79985 }
79986
79987-extern unsigned long msecs_to_jiffies(const unsigned int m);
79988-extern unsigned long usecs_to_jiffies(const unsigned int u);
79989+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79990+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79991 extern unsigned long timespec_to_jiffies(const struct timespec *value);
79992 extern void jiffies_to_timespec(const unsigned long jiffies,
79993- struct timespec *value);
79994-extern unsigned long timeval_to_jiffies(const struct timeval *value);
79995+ struct timespec *value) __intentional_overflow(-1);
79996+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79997 extern void jiffies_to_timeval(const unsigned long jiffies,
79998 struct timeval *value);
79999
80000diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80001index 6883e19..e854fcb 100644
80002--- a/include/linux/kallsyms.h
80003+++ b/include/linux/kallsyms.h
80004@@ -15,7 +15,8 @@
80005
80006 struct module;
80007
80008-#ifdef CONFIG_KALLSYMS
80009+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80010+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80011 /* Lookup the address for a symbol. Returns 0 if not found. */
80012 unsigned long kallsyms_lookup_name(const char *name);
80013
80014@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80015 /* Stupid that this does nothing, but I didn't create this mess. */
80016 #define __print_symbol(fmt, addr)
80017 #endif /*CONFIG_KALLSYMS*/
80018+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80019+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80020+extern unsigned long kallsyms_lookup_name(const char *name);
80021+extern void __print_symbol(const char *fmt, unsigned long address);
80022+extern int sprint_backtrace(char *buffer, unsigned long address);
80023+extern int sprint_symbol(char *buffer, unsigned long address);
80024+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80025+const char *kallsyms_lookup(unsigned long addr,
80026+ unsigned long *symbolsize,
80027+ unsigned long *offset,
80028+ char **modname, char *namebuf);
80029+extern int kallsyms_lookup_size_offset(unsigned long addr,
80030+ unsigned long *symbolsize,
80031+ unsigned long *offset);
80032+#endif
80033
80034 /* This macro allows us to keep printk typechecking */
80035 static __printf(1, 2)
80036diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80037index a74c3a8..28d3f21 100644
80038--- a/include/linux/key-type.h
80039+++ b/include/linux/key-type.h
80040@@ -131,7 +131,7 @@ struct key_type {
80041 /* internal fields */
80042 struct list_head link; /* link in types list */
80043 struct lock_class_key lock_class; /* key->sem lock class */
80044-};
80045+} __do_const;
80046
80047 extern struct key_type key_type_keyring;
80048
80049diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80050index 6b06d37..c134867 100644
80051--- a/include/linux/kgdb.h
80052+++ b/include/linux/kgdb.h
80053@@ -52,7 +52,7 @@ extern int kgdb_connected;
80054 extern int kgdb_io_module_registered;
80055
80056 extern atomic_t kgdb_setting_breakpoint;
80057-extern atomic_t kgdb_cpu_doing_single_step;
80058+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80059
80060 extern struct task_struct *kgdb_usethread;
80061 extern struct task_struct *kgdb_contthread;
80062@@ -254,7 +254,7 @@ struct kgdb_arch {
80063 void (*correct_hw_break)(void);
80064
80065 void (*enable_nmi)(bool on);
80066-};
80067+} __do_const;
80068
80069 /**
80070 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80071@@ -279,7 +279,7 @@ struct kgdb_io {
80072 void (*pre_exception) (void);
80073 void (*post_exception) (void);
80074 int is_console;
80075-};
80076+} __do_const;
80077
80078 extern struct kgdb_arch arch_kgdb_ops;
80079
80080diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80081index 0555cc6..40116ce 100644
80082--- a/include/linux/kmod.h
80083+++ b/include/linux/kmod.h
80084@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80085 * usually useless though. */
80086 extern __printf(2, 3)
80087 int __request_module(bool wait, const char *name, ...);
80088+extern __printf(3, 4)
80089+int ___request_module(bool wait, char *param_name, const char *name, ...);
80090 #define request_module(mod...) __request_module(true, mod)
80091 #define request_module_nowait(mod...) __request_module(false, mod)
80092 #define try_then_request_module(x, mod...) \
80093@@ -57,6 +59,9 @@ struct subprocess_info {
80094 struct work_struct work;
80095 struct completion *complete;
80096 char *path;
80097+#ifdef CONFIG_GRKERNSEC
80098+ char *origpath;
80099+#endif
80100 char **argv;
80101 char **envp;
80102 int wait;
80103diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80104index 926afb6..58dd6e5 100644
80105--- a/include/linux/kobject.h
80106+++ b/include/linux/kobject.h
80107@@ -116,7 +116,7 @@ struct kobj_type {
80108 struct attribute **default_attrs;
80109 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80110 const void *(*namespace)(struct kobject *kobj);
80111-};
80112+} __do_const;
80113
80114 struct kobj_uevent_env {
80115 char *envp[UEVENT_NUM_ENVP];
80116@@ -139,6 +139,7 @@ struct kobj_attribute {
80117 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80118 const char *buf, size_t count);
80119 };
80120+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80121
80122 extern const struct sysfs_ops kobj_sysfs_ops;
80123
80124@@ -166,7 +167,7 @@ struct kset {
80125 spinlock_t list_lock;
80126 struct kobject kobj;
80127 const struct kset_uevent_ops *uevent_ops;
80128-};
80129+} __randomize_layout;
80130
80131 extern void kset_init(struct kset *kset);
80132 extern int __must_check kset_register(struct kset *kset);
80133diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80134index df32d25..fb52e27 100644
80135--- a/include/linux/kobject_ns.h
80136+++ b/include/linux/kobject_ns.h
80137@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80138 const void *(*netlink_ns)(struct sock *sk);
80139 const void *(*initial_ns)(void);
80140 void (*drop_ns)(void *);
80141-};
80142+} __do_const;
80143
80144 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80145 int kobj_ns_type_registered(enum kobj_ns_type type);
80146diff --git a/include/linux/kref.h b/include/linux/kref.h
80147index 484604d..0f6c5b6 100644
80148--- a/include/linux/kref.h
80149+++ b/include/linux/kref.h
80150@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80151 static inline int kref_sub(struct kref *kref, unsigned int count,
80152 void (*release)(struct kref *kref))
80153 {
80154- WARN_ON(release == NULL);
80155+ BUG_ON(release == NULL);
80156
80157 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80158 release(kref);
80159diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80160index b8e9a43..632678d 100644
80161--- a/include/linux/kvm_host.h
80162+++ b/include/linux/kvm_host.h
80163@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80164 {
80165 }
80166 #endif
80167-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80168+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80169 struct module *module);
80170 void kvm_exit(void);
80171
80172@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80173 struct kvm_guest_debug *dbg);
80174 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80175
80176-int kvm_arch_init(void *opaque);
80177+int kvm_arch_init(const void *opaque);
80178 void kvm_arch_exit(void);
80179
80180 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80181diff --git a/include/linux/libata.h b/include/linux/libata.h
80182index bec6dbe..2873d64 100644
80183--- a/include/linux/libata.h
80184+++ b/include/linux/libata.h
80185@@ -975,7 +975,7 @@ struct ata_port_operations {
80186 * fields must be pointers.
80187 */
80188 const struct ata_port_operations *inherits;
80189-};
80190+} __do_const;
80191
80192 struct ata_port_info {
80193 unsigned long flags;
80194diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80195index a6a42dd..6c5ebce 100644
80196--- a/include/linux/linkage.h
80197+++ b/include/linux/linkage.h
80198@@ -36,6 +36,7 @@
80199 #endif
80200
80201 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80202+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80203 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80204
80205 /*
80206diff --git a/include/linux/list.h b/include/linux/list.h
80207index ef95941..82db65a 100644
80208--- a/include/linux/list.h
80209+++ b/include/linux/list.h
80210@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80211 extern void list_del(struct list_head *entry);
80212 #endif
80213
80214+extern void __pax_list_add(struct list_head *new,
80215+ struct list_head *prev,
80216+ struct list_head *next);
80217+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80218+{
80219+ __pax_list_add(new, head, head->next);
80220+}
80221+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80222+{
80223+ __pax_list_add(new, head->prev, head);
80224+}
80225+extern void pax_list_del(struct list_head *entry);
80226+
80227 /**
80228 * list_replace - replace old entry by new one
80229 * @old : the element to be replaced
80230@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80231 INIT_LIST_HEAD(entry);
80232 }
80233
80234+extern void pax_list_del_init(struct list_head *entry);
80235+
80236 /**
80237 * list_move - delete from one list and add as another's head
80238 * @list: the entry to move
80239diff --git a/include/linux/math64.h b/include/linux/math64.h
80240index c45c089..298841c 100644
80241--- a/include/linux/math64.h
80242+++ b/include/linux/math64.h
80243@@ -15,7 +15,7 @@
80244 * This is commonly provided by 32bit archs to provide an optimized 64bit
80245 * divide.
80246 */
80247-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80248+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80249 {
80250 *remainder = dividend % divisor;
80251 return dividend / divisor;
80252@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80253 /**
80254 * div64_u64 - unsigned 64bit divide with 64bit divisor
80255 */
80256-static inline u64 div64_u64(u64 dividend, u64 divisor)
80257+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80258 {
80259 return dividend / divisor;
80260 }
80261@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80262 #define div64_ul(x, y) div_u64((x), (y))
80263
80264 #ifndef div_u64_rem
80265-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80266+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80267 {
80268 *remainder = do_div(dividend, divisor);
80269 return dividend;
80270@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80271 #endif
80272
80273 #ifndef div64_u64
80274-extern u64 div64_u64(u64 dividend, u64 divisor);
80275+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80276 #endif
80277
80278 #ifndef div64_s64
80279@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80280 * divide.
80281 */
80282 #ifndef div_u64
80283-static inline u64 div_u64(u64 dividend, u32 divisor)
80284+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80285 {
80286 u32 remainder;
80287 return div_u64_rem(dividend, divisor, &remainder);
80288diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80289index 5f1ea75..5125ac5 100644
80290--- a/include/linux/mempolicy.h
80291+++ b/include/linux/mempolicy.h
80292@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80293 }
80294
80295 #define vma_policy(vma) ((vma)->vm_policy)
80296+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80297+{
80298+ vma->vm_policy = pol;
80299+}
80300
80301 static inline void mpol_get(struct mempolicy *pol)
80302 {
80303@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80304 }
80305
80306 #define vma_policy(vma) NULL
80307+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80308+{
80309+}
80310
80311 static inline int
80312 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80313diff --git a/include/linux/mm.h b/include/linux/mm.h
80314index c1b7414..5ea2ad8 100644
80315--- a/include/linux/mm.h
80316+++ b/include/linux/mm.h
80317@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80318 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80319 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80320 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80321+
80322+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80323+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80324+#endif
80325+
80326 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80327
80328 #ifdef CONFIG_MEM_SOFT_DIRTY
80329@@ -229,8 +234,8 @@ struct vm_operations_struct {
80330 /* called by access_process_vm when get_user_pages() fails, typically
80331 * for use by special VMAs that can switch between memory and hardware
80332 */
80333- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80334- void *buf, int len, int write);
80335+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80336+ void *buf, size_t len, int write);
80337 #ifdef CONFIG_NUMA
80338 /*
80339 * set_policy() op must add a reference to any non-NULL @new mempolicy
80340@@ -260,6 +265,7 @@ struct vm_operations_struct {
80341 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80342 unsigned long size, pgoff_t pgoff);
80343 };
80344+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80345
80346 struct mmu_gather;
80347 struct inode;
80348@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80349 unsigned long *pfn);
80350 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80351 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80352-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80353- void *buf, int len, int write);
80354+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80355+ void *buf, size_t len, int write);
80356
80357 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80358 loff_t const holebegin, loff_t const holelen)
80359@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80360 }
80361 #endif
80362
80363-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80364-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80365- void *buf, int len, int write);
80366+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80367+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80368+ void *buf, size_t len, int write);
80369
80370 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80371 unsigned long start, unsigned long nr_pages,
80372@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80373 int set_page_dirty_lock(struct page *page);
80374 int clear_page_dirty_for_io(struct page *page);
80375
80376-/* Is the vma a continuation of the stack vma above it? */
80377-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80378-{
80379- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80380-}
80381-
80382-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80383- unsigned long addr)
80384-{
80385- return (vma->vm_flags & VM_GROWSDOWN) &&
80386- (vma->vm_start == addr) &&
80387- !vma_growsdown(vma->vm_prev, addr);
80388-}
80389-
80390-/* Is the vma a continuation of the stack vma below it? */
80391-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80392-{
80393- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80394-}
80395-
80396-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80397- unsigned long addr)
80398-{
80399- return (vma->vm_flags & VM_GROWSUP) &&
80400- (vma->vm_end == addr) &&
80401- !vma_growsup(vma->vm_next, addr);
80402-}
80403-
80404 extern pid_t
80405 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80406
80407@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80408 }
80409 #endif
80410
80411+#ifdef CONFIG_MMU
80412+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80413+#else
80414+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80415+{
80416+ return __pgprot(0);
80417+}
80418+#endif
80419+
80420 int vma_wants_writenotify(struct vm_area_struct *vma);
80421
80422 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80423@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80424 {
80425 return 0;
80426 }
80427+
80428+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80429+ unsigned long address)
80430+{
80431+ return 0;
80432+}
80433 #else
80434 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80435+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80436 #endif
80437
80438 #ifdef __PAGETABLE_PMD_FOLDED
80439@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80440 {
80441 return 0;
80442 }
80443+
80444+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80445+ unsigned long address)
80446+{
80447+ return 0;
80448+}
80449 #else
80450 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80451+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80452 #endif
80453
80454 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80455@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80456 NULL: pud_offset(pgd, address);
80457 }
80458
80459+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80460+{
80461+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80462+ NULL: pud_offset(pgd, address);
80463+}
80464+
80465 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80466 {
80467 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80468 NULL: pmd_offset(pud, address);
80469 }
80470+
80471+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80472+{
80473+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80474+ NULL: pmd_offset(pud, address);
80475+}
80476 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80477
80478 #if USE_SPLIT_PTE_PTLOCKS
80479@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80480 unsigned long addr, unsigned long len,
80481 unsigned long flags, struct page **pages);
80482
80483-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80484+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80485
80486 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80487 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80488@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80489 unsigned long len, unsigned long prot, unsigned long flags,
80490 unsigned long pgoff, unsigned long *populate);
80491 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80492+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80493
80494 #ifdef CONFIG_MMU
80495 extern int __mm_populate(unsigned long addr, unsigned long len,
80496@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80497 unsigned long high_limit;
80498 unsigned long align_mask;
80499 unsigned long align_offset;
80500+ unsigned long threadstack_offset;
80501 };
80502
80503-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80504-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80505+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80506+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80507
80508 /*
80509 * Search for an unmapped address range.
80510@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80511 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80512 */
80513 static inline unsigned long
80514-vm_unmapped_area(struct vm_unmapped_area_info *info)
80515+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80516 {
80517 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80518 return unmapped_area(info);
80519@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80520 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80521 struct vm_area_struct **pprev);
80522
80523+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80524+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80525+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80526+
80527 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80528 NULL if none. Assume start_addr < end_addr. */
80529 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80530@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80531 return vma;
80532 }
80533
80534-#ifdef CONFIG_MMU
80535-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80536-#else
80537-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80538-{
80539- return __pgprot(0);
80540-}
80541-#endif
80542-
80543 #ifdef CONFIG_NUMA_BALANCING
80544 unsigned long change_prot_numa(struct vm_area_struct *vma,
80545 unsigned long start, unsigned long end);
80546@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80547 static inline void vm_stat_account(struct mm_struct *mm,
80548 unsigned long flags, struct file *file, long pages)
80549 {
80550+
80551+#ifdef CONFIG_PAX_RANDMMAP
80552+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80553+#endif
80554+
80555 mm->total_vm += pages;
80556 }
80557 #endif /* CONFIG_PROC_FS */
80558@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80559 extern int sysctl_memory_failure_early_kill;
80560 extern int sysctl_memory_failure_recovery;
80561 extern void shake_page(struct page *p, int access);
80562-extern atomic_long_t num_poisoned_pages;
80563+extern atomic_long_unchecked_t num_poisoned_pages;
80564 extern int soft_offline_page(struct page *page, int flags);
80565
80566 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80567@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80568 static inline void setup_nr_node_ids(void) {}
80569 #endif
80570
80571+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80572+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80573+#else
80574+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80575+#endif
80576+
80577 #endif /* __KERNEL__ */
80578 #endif /* _LINUX_MM_H */
80579diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80580index 290901a..e99b01c 100644
80581--- a/include/linux/mm_types.h
80582+++ b/include/linux/mm_types.h
80583@@ -307,7 +307,9 @@ struct vm_area_struct {
80584 #ifdef CONFIG_NUMA
80585 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80586 #endif
80587-};
80588+
80589+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80590+} __randomize_layout;
80591
80592 struct core_thread {
80593 struct task_struct *task;
80594@@ -453,7 +455,25 @@ struct mm_struct {
80595 bool tlb_flush_pending;
80596 #endif
80597 struct uprobes_state uprobes_state;
80598-};
80599+
80600+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80601+ unsigned long pax_flags;
80602+#endif
80603+
80604+#ifdef CONFIG_PAX_DLRESOLVE
80605+ unsigned long call_dl_resolve;
80606+#endif
80607+
80608+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80609+ unsigned long call_syscall;
80610+#endif
80611+
80612+#ifdef CONFIG_PAX_ASLR
80613+ unsigned long delta_mmap; /* randomized offset */
80614+ unsigned long delta_stack; /* randomized offset */
80615+#endif
80616+
80617+} __randomize_layout;
80618
80619 static inline void mm_init_cpumask(struct mm_struct *mm)
80620 {
80621diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80622index c5d5278..f0b68c8 100644
80623--- a/include/linux/mmiotrace.h
80624+++ b/include/linux/mmiotrace.h
80625@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80626 /* Called from ioremap.c */
80627 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80628 void __iomem *addr);
80629-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80630+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80631
80632 /* For anyone to insert markers. Remember trailing newline. */
80633 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80634@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80635 {
80636 }
80637
80638-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80639+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80640 {
80641 }
80642
80643diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80644index 9b61b9b..52147d6b 100644
80645--- a/include/linux/mmzone.h
80646+++ b/include/linux/mmzone.h
80647@@ -396,7 +396,7 @@ struct zone {
80648 unsigned long flags; /* zone flags, see below */
80649
80650 /* Zone statistics */
80651- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80652+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80653
80654 /*
80655 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80656diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80657index 45e9214..a7227d6 100644
80658--- a/include/linux/mod_devicetable.h
80659+++ b/include/linux/mod_devicetable.h
80660@@ -13,7 +13,7 @@
80661 typedef unsigned long kernel_ulong_t;
80662 #endif
80663
80664-#define PCI_ANY_ID (~0)
80665+#define PCI_ANY_ID ((__u16)~0)
80666
80667 struct pci_device_id {
80668 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80669@@ -139,7 +139,7 @@ struct usb_device_id {
80670 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80671 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80672
80673-#define HID_ANY_ID (~0)
80674+#define HID_ANY_ID (~0U)
80675 #define HID_BUS_ANY 0xffff
80676 #define HID_GROUP_ANY 0x0000
80677
80678@@ -467,7 +467,7 @@ struct dmi_system_id {
80679 const char *ident;
80680 struct dmi_strmatch matches[4];
80681 void *driver_data;
80682-};
80683+} __do_const;
80684 /*
80685 * struct dmi_device_id appears during expansion of
80686 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80687diff --git a/include/linux/module.h b/include/linux/module.h
80688index eaf60ff..641979a 100644
80689--- a/include/linux/module.h
80690+++ b/include/linux/module.h
80691@@ -17,9 +17,11 @@
80692 #include <linux/moduleparam.h>
80693 #include <linux/tracepoint.h>
80694 #include <linux/export.h>
80695+#include <linux/fs.h>
80696
80697 #include <linux/percpu.h>
80698 #include <asm/module.h>
80699+#include <asm/pgtable.h>
80700
80701 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80702 #define MODULE_SIG_STRING "~Module signature appended~\n"
80703@@ -42,7 +44,7 @@ struct module_kobject {
80704 struct kobject *drivers_dir;
80705 struct module_param_attrs *mp;
80706 struct completion *kobj_completion;
80707-};
80708+} __randomize_layout;
80709
80710 struct module_attribute {
80711 struct attribute attr;
80712@@ -54,12 +56,13 @@ struct module_attribute {
80713 int (*test)(struct module *);
80714 void (*free)(struct module *);
80715 };
80716+typedef struct module_attribute __no_const module_attribute_no_const;
80717
80718 struct module_version_attribute {
80719 struct module_attribute mattr;
80720 const char *module_name;
80721 const char *version;
80722-} __attribute__ ((__aligned__(sizeof(void *))));
80723+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80724
80725 extern ssize_t __modver_version_show(struct module_attribute *,
80726 struct module_kobject *, char *);
80727@@ -238,7 +241,7 @@ struct module {
80728
80729 /* Sysfs stuff. */
80730 struct module_kobject mkobj;
80731- struct module_attribute *modinfo_attrs;
80732+ module_attribute_no_const *modinfo_attrs;
80733 const char *version;
80734 const char *srcversion;
80735 struct kobject *holders_dir;
80736@@ -287,19 +290,16 @@ struct module {
80737 int (*init)(void);
80738
80739 /* If this is non-NULL, vfree after init() returns */
80740- void *module_init;
80741+ void *module_init_rx, *module_init_rw;
80742
80743 /* Here is the actual code + data, vfree'd on unload. */
80744- void *module_core;
80745+ void *module_core_rx, *module_core_rw;
80746
80747 /* Here are the sizes of the init and core sections */
80748- unsigned int init_size, core_size;
80749+ unsigned int init_size_rw, core_size_rw;
80750
80751 /* The size of the executable code in each section. */
80752- unsigned int init_text_size, core_text_size;
80753-
80754- /* Size of RO sections of the module (text+rodata) */
80755- unsigned int init_ro_size, core_ro_size;
80756+ unsigned int init_size_rx, core_size_rx;
80757
80758 /* Arch-specific module values */
80759 struct mod_arch_specific arch;
80760@@ -355,6 +355,10 @@ struct module {
80761 #ifdef CONFIG_EVENT_TRACING
80762 struct ftrace_event_call **trace_events;
80763 unsigned int num_trace_events;
80764+ struct file_operations trace_id;
80765+ struct file_operations trace_enable;
80766+ struct file_operations trace_format;
80767+ struct file_operations trace_filter;
80768 #endif
80769 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80770 unsigned int num_ftrace_callsites;
80771@@ -378,7 +382,7 @@ struct module {
80772 ctor_fn_t *ctors;
80773 unsigned int num_ctors;
80774 #endif
80775-};
80776+} __randomize_layout;
80777 #ifndef MODULE_ARCH_INIT
80778 #define MODULE_ARCH_INIT {}
80779 #endif
80780@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80781 bool is_module_percpu_address(unsigned long addr);
80782 bool is_module_text_address(unsigned long addr);
80783
80784+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80785+{
80786+
80787+#ifdef CONFIG_PAX_KERNEXEC
80788+ if (ktla_ktva(addr) >= (unsigned long)start &&
80789+ ktla_ktva(addr) < (unsigned long)start + size)
80790+ return 1;
80791+#endif
80792+
80793+ return ((void *)addr >= start && (void *)addr < start + size);
80794+}
80795+
80796+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80797+{
80798+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80799+}
80800+
80801+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80802+{
80803+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80804+}
80805+
80806+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80807+{
80808+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80809+}
80810+
80811+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80812+{
80813+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80814+}
80815+
80816 static inline int within_module_core(unsigned long addr, const struct module *mod)
80817 {
80818- return (unsigned long)mod->module_core <= addr &&
80819- addr < (unsigned long)mod->module_core + mod->core_size;
80820+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80821 }
80822
80823 static inline int within_module_init(unsigned long addr, const struct module *mod)
80824 {
80825- return (unsigned long)mod->module_init <= addr &&
80826- addr < (unsigned long)mod->module_init + mod->init_size;
80827+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80828 }
80829
80830 /* Search for module by name: must hold module_mutex. */
80831diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80832index 560ca53..ef621ef 100644
80833--- a/include/linux/moduleloader.h
80834+++ b/include/linux/moduleloader.h
80835@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80836 sections. Returns NULL on failure. */
80837 void *module_alloc(unsigned long size);
80838
80839+#ifdef CONFIG_PAX_KERNEXEC
80840+void *module_alloc_exec(unsigned long size);
80841+#else
80842+#define module_alloc_exec(x) module_alloc(x)
80843+#endif
80844+
80845 /* Free memory returned from module_alloc. */
80846 void module_free(struct module *mod, void *module_region);
80847
80848+#ifdef CONFIG_PAX_KERNEXEC
80849+void module_free_exec(struct module *mod, void *module_region);
80850+#else
80851+#define module_free_exec(x, y) module_free((x), (y))
80852+#endif
80853+
80854 /*
80855 * Apply the given relocation to the (simplified) ELF. Return -error
80856 * or 0.
80857@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80858 unsigned int relsec,
80859 struct module *me)
80860 {
80861+#ifdef CONFIG_MODULES
80862 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80863+#endif
80864 return -ENOEXEC;
80865 }
80866 #endif
80867@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80868 unsigned int relsec,
80869 struct module *me)
80870 {
80871+#ifdef CONFIG_MODULES
80872 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80873+#endif
80874 return -ENOEXEC;
80875 }
80876 #endif
80877diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80878index c3eb102..073c4a6 100644
80879--- a/include/linux/moduleparam.h
80880+++ b/include/linux/moduleparam.h
80881@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80882 * @len is usually just sizeof(string).
80883 */
80884 #define module_param_string(name, string, len, perm) \
80885- static const struct kparam_string __param_string_##name \
80886+ static const struct kparam_string __param_string_##name __used \
80887 = { len, string }; \
80888 __module_param_call(MODULE_PARAM_PREFIX, name, \
80889 &param_ops_string, \
80890@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80891 */
80892 #define module_param_array_named(name, array, type, nump, perm) \
80893 param_check_##type(name, &(array)[0]); \
80894- static const struct kparam_array __param_arr_##name \
80895+ static const struct kparam_array __param_arr_##name __used \
80896 = { .max = ARRAY_SIZE(array), .num = nump, \
80897 .ops = &param_ops_##type, \
80898 .elemsize = sizeof(array[0]), .elem = array }; \
80899diff --git a/include/linux/mount.h b/include/linux/mount.h
80900index 839bac2..a96b37c 100644
80901--- a/include/linux/mount.h
80902+++ b/include/linux/mount.h
80903@@ -59,7 +59,7 @@ struct vfsmount {
80904 struct dentry *mnt_root; /* root of the mounted tree */
80905 struct super_block *mnt_sb; /* pointer to superblock */
80906 int mnt_flags;
80907-};
80908+} __randomize_layout;
80909
80910 struct file; /* forward dec */
80911
80912diff --git a/include/linux/namei.h b/include/linux/namei.h
80913index 492de72..1bddcd4 100644
80914--- a/include/linux/namei.h
80915+++ b/include/linux/namei.h
80916@@ -19,7 +19,7 @@ struct nameidata {
80917 unsigned seq, m_seq;
80918 int last_type;
80919 unsigned depth;
80920- char *saved_names[MAX_NESTED_LINKS + 1];
80921+ const char *saved_names[MAX_NESTED_LINKS + 1];
80922 };
80923
80924 /*
80925@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80926
80927 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80928
80929-static inline void nd_set_link(struct nameidata *nd, char *path)
80930+static inline void nd_set_link(struct nameidata *nd, const char *path)
80931 {
80932 nd->saved_names[nd->depth] = path;
80933 }
80934
80935-static inline char *nd_get_link(struct nameidata *nd)
80936+static inline const char *nd_get_link(const struct nameidata *nd)
80937 {
80938 return nd->saved_names[nd->depth];
80939 }
80940diff --git a/include/linux/net.h b/include/linux/net.h
80941index 94734a6..d8d6931 100644
80942--- a/include/linux/net.h
80943+++ b/include/linux/net.h
80944@@ -192,7 +192,7 @@ struct net_proto_family {
80945 int (*create)(struct net *net, struct socket *sock,
80946 int protocol, int kern);
80947 struct module *owner;
80948-};
80949+} __do_const;
80950
80951 struct iovec;
80952 struct kvec;
80953diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80954index daafd95..74c5d1e 100644
80955--- a/include/linux/netdevice.h
80956+++ b/include/linux/netdevice.h
80957@@ -1146,6 +1146,7 @@ struct net_device_ops {
80958 struct net_device *dev,
80959 void *priv);
80960 };
80961+typedef struct net_device_ops __no_const net_device_ops_no_const;
80962
80963 /*
80964 * The DEVICE structure.
80965@@ -1228,7 +1229,7 @@ struct net_device {
80966 int iflink;
80967
80968 struct net_device_stats stats;
80969- atomic_long_t rx_dropped; /* dropped packets by core network
80970+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80971 * Do not use this in drivers.
80972 */
80973
80974diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80975index 2077489..a15e561 100644
80976--- a/include/linux/netfilter.h
80977+++ b/include/linux/netfilter.h
80978@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80979 #endif
80980 /* Use the module struct to lock set/get code in place */
80981 struct module *owner;
80982-};
80983+} __do_const;
80984
80985 /* Function to register/unregister hook points. */
80986 int nf_register_hook(struct nf_hook_ops *reg);
80987diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80988index 28c7436..2d6156a 100644
80989--- a/include/linux/netfilter/nfnetlink.h
80990+++ b/include/linux/netfilter/nfnetlink.h
80991@@ -19,7 +19,7 @@ struct nfnl_callback {
80992 const struct nlattr * const cda[]);
80993 const struct nla_policy *policy; /* netlink attribute policy */
80994 const u_int16_t attr_count; /* number of nlattr's */
80995-};
80996+} __do_const;
80997
80998 struct nfnetlink_subsystem {
80999 const char *name;
81000diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81001new file mode 100644
81002index 0000000..33f4af8
81003--- /dev/null
81004+++ b/include/linux/netfilter/xt_gradm.h
81005@@ -0,0 +1,9 @@
81006+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81007+#define _LINUX_NETFILTER_XT_GRADM_H 1
81008+
81009+struct xt_gradm_mtinfo {
81010+ __u16 flags;
81011+ __u16 invflags;
81012+};
81013+
81014+#endif
81015diff --git a/include/linux/nls.h b/include/linux/nls.h
81016index 520681b..1d67ed2 100644
81017--- a/include/linux/nls.h
81018+++ b/include/linux/nls.h
81019@@ -31,7 +31,7 @@ struct nls_table {
81020 const unsigned char *charset2upper;
81021 struct module *owner;
81022 struct nls_table *next;
81023-};
81024+} __do_const;
81025
81026 /* this value hold the maximum octet of charset */
81027 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81028diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81029index d14a4c3..a078786 100644
81030--- a/include/linux/notifier.h
81031+++ b/include/linux/notifier.h
81032@@ -54,7 +54,8 @@ struct notifier_block {
81033 notifier_fn_t notifier_call;
81034 struct notifier_block __rcu *next;
81035 int priority;
81036-};
81037+} __do_const;
81038+typedef struct notifier_block __no_const notifier_block_no_const;
81039
81040 struct atomic_notifier_head {
81041 spinlock_t lock;
81042diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81043index b2a0f15..4d7da32 100644
81044--- a/include/linux/oprofile.h
81045+++ b/include/linux/oprofile.h
81046@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81047 int oprofilefs_create_ro_ulong(struct dentry * root,
81048 char const * name, ulong * val);
81049
81050-/** Create a file for read-only access to an atomic_t. */
81051+/** Create a file for read-only access to an atomic_unchecked_t. */
81052 int oprofilefs_create_ro_atomic(struct dentry * root,
81053- char const * name, atomic_t * val);
81054+ char const * name, atomic_unchecked_t * val);
81055
81056 /** create a directory */
81057 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81058diff --git a/include/linux/padata.h b/include/linux/padata.h
81059index 4386946..f50c615 100644
81060--- a/include/linux/padata.h
81061+++ b/include/linux/padata.h
81062@@ -129,7 +129,7 @@ struct parallel_data {
81063 struct padata_serial_queue __percpu *squeue;
81064 atomic_t reorder_objects;
81065 atomic_t refcnt;
81066- atomic_t seq_nr;
81067+ atomic_unchecked_t seq_nr;
81068 struct padata_cpumask cpumask;
81069 spinlock_t lock ____cacheline_aligned;
81070 unsigned int processed;
81071diff --git a/include/linux/path.h b/include/linux/path.h
81072index d137218..be0c176 100644
81073--- a/include/linux/path.h
81074+++ b/include/linux/path.h
81075@@ -1,13 +1,15 @@
81076 #ifndef _LINUX_PATH_H
81077 #define _LINUX_PATH_H
81078
81079+#include <linux/compiler.h>
81080+
81081 struct dentry;
81082 struct vfsmount;
81083
81084 struct path {
81085 struct vfsmount *mnt;
81086 struct dentry *dentry;
81087-};
81088+} __randomize_layout;
81089
81090 extern void path_get(const struct path *);
81091 extern void path_put(const struct path *);
81092diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81093index 5f2e559..7d59314 100644
81094--- a/include/linux/pci_hotplug.h
81095+++ b/include/linux/pci_hotplug.h
81096@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81097 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81098 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81099 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81100-};
81101+} __do_const;
81102+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81103
81104 /**
81105 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81106diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81107index e56b07f..aef789b 100644
81108--- a/include/linux/perf_event.h
81109+++ b/include/linux/perf_event.h
81110@@ -328,8 +328,8 @@ struct perf_event {
81111
81112 enum perf_event_active_state state;
81113 unsigned int attach_state;
81114- local64_t count;
81115- atomic64_t child_count;
81116+ local64_t count; /* PaX: fix it one day */
81117+ atomic64_unchecked_t child_count;
81118
81119 /*
81120 * These are the total time in nanoseconds that the event
81121@@ -380,8 +380,8 @@ struct perf_event {
81122 * These accumulate total time (in nanoseconds) that children
81123 * events have been enabled and running, respectively.
81124 */
81125- atomic64_t child_total_time_enabled;
81126- atomic64_t child_total_time_running;
81127+ atomic64_unchecked_t child_total_time_enabled;
81128+ atomic64_unchecked_t child_total_time_running;
81129
81130 /*
81131 * Protect attach/detach and child_list:
81132@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81133 entry->ip[entry->nr++] = ip;
81134 }
81135
81136-extern int sysctl_perf_event_paranoid;
81137+extern int sysctl_perf_event_legitimately_concerned;
81138 extern int sysctl_perf_event_mlock;
81139 extern int sysctl_perf_event_sample_rate;
81140 extern int sysctl_perf_cpu_time_max_percent;
81141@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81142 loff_t *ppos);
81143
81144
81145+static inline bool perf_paranoid_any(void)
81146+{
81147+ return sysctl_perf_event_legitimately_concerned > 2;
81148+}
81149+
81150 static inline bool perf_paranoid_tracepoint_raw(void)
81151 {
81152- return sysctl_perf_event_paranoid > -1;
81153+ return sysctl_perf_event_legitimately_concerned > -1;
81154 }
81155
81156 static inline bool perf_paranoid_cpu(void)
81157 {
81158- return sysctl_perf_event_paranoid > 0;
81159+ return sysctl_perf_event_legitimately_concerned > 0;
81160 }
81161
81162 static inline bool perf_paranoid_kernel(void)
81163 {
81164- return sysctl_perf_event_paranoid > 1;
81165+ return sysctl_perf_event_legitimately_concerned > 1;
81166 }
81167
81168 extern void perf_event_init(void);
81169@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81170 struct device_attribute attr;
81171 u64 id;
81172 const char *event_str;
81173-};
81174+} __do_const;
81175
81176 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81177 static struct perf_pmu_events_attr _var = { \
81178diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81179index 7246ef3..1539ea4 100644
81180--- a/include/linux/pid_namespace.h
81181+++ b/include/linux/pid_namespace.h
81182@@ -43,7 +43,7 @@ struct pid_namespace {
81183 int hide_pid;
81184 int reboot; /* group exit code if this pidns was rebooted */
81185 unsigned int proc_inum;
81186-};
81187+} __randomize_layout;
81188
81189 extern struct pid_namespace init_pid_ns;
81190
81191diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81192index ab57526..94598804 100644
81193--- a/include/linux/pipe_fs_i.h
81194+++ b/include/linux/pipe_fs_i.h
81195@@ -47,10 +47,10 @@ struct pipe_inode_info {
81196 struct mutex mutex;
81197 wait_queue_head_t wait;
81198 unsigned int nrbufs, curbuf, buffers;
81199- unsigned int readers;
81200- unsigned int writers;
81201- unsigned int files;
81202- unsigned int waiting_writers;
81203+ atomic_t readers;
81204+ atomic_t writers;
81205+ atomic_t files;
81206+ atomic_t waiting_writers;
81207 unsigned int r_counter;
81208 unsigned int w_counter;
81209 struct page *tmp_page;
81210diff --git a/include/linux/pm.h b/include/linux/pm.h
81211index 8c6583a..febb84c 100644
81212--- a/include/linux/pm.h
81213+++ b/include/linux/pm.h
81214@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81215 struct dev_pm_domain {
81216 struct dev_pm_ops ops;
81217 };
81218+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81219
81220 /*
81221 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81222diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81223index 7c1d252..0e7061d 100644
81224--- a/include/linux/pm_domain.h
81225+++ b/include/linux/pm_domain.h
81226@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81227 int (*thaw_early)(struct device *dev);
81228 int (*thaw)(struct device *dev);
81229 bool (*active_wakeup)(struct device *dev);
81230-};
81231+} __no_const;
81232
81233 struct gpd_cpu_data {
81234 unsigned int saved_exit_latency;
81235- struct cpuidle_state *idle_state;
81236+ cpuidle_state_no_const *idle_state;
81237 };
81238
81239 struct generic_pm_domain {
81240diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81241index 16c9a62..f9f0838 100644
81242--- a/include/linux/pm_runtime.h
81243+++ b/include/linux/pm_runtime.h
81244@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81245
81246 static inline void pm_runtime_mark_last_busy(struct device *dev)
81247 {
81248- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81249+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81250 }
81251
81252 #else /* !CONFIG_PM_RUNTIME */
81253diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81254index 195aafc..49a7bc2 100644
81255--- a/include/linux/pnp.h
81256+++ b/include/linux/pnp.h
81257@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81258 struct pnp_fixup {
81259 char id[7];
81260 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81261-};
81262+} __do_const;
81263
81264 /* config parameters */
81265 #define PNP_CONFIG_NORMAL 0x0001
81266diff --git a/include/linux/poison.h b/include/linux/poison.h
81267index 2110a81..13a11bb 100644
81268--- a/include/linux/poison.h
81269+++ b/include/linux/poison.h
81270@@ -19,8 +19,8 @@
81271 * under normal circumstances, used to verify that nobody uses
81272 * non-initialized list entries.
81273 */
81274-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81275-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81276+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81277+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81278
81279 /********** include/linux/timer.h **********/
81280 /*
81281diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81282index d8b187c3..9a9257a 100644
81283--- a/include/linux/power/smartreflex.h
81284+++ b/include/linux/power/smartreflex.h
81285@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81286 int (*notify)(struct omap_sr *sr, u32 status);
81287 u8 notify_flags;
81288 u8 class_type;
81289-};
81290+} __do_const;
81291
81292 /**
81293 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81294diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81295index 4ea1d37..80f4b33 100644
81296--- a/include/linux/ppp-comp.h
81297+++ b/include/linux/ppp-comp.h
81298@@ -84,7 +84,7 @@ struct compressor {
81299 struct module *owner;
81300 /* Extra skb space needed by the compressor algorithm */
81301 unsigned int comp_extra;
81302-};
81303+} __do_const;
81304
81305 /*
81306 * The return value from decompress routine is the length of the
81307diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81308index de83b4e..c4b997d 100644
81309--- a/include/linux/preempt.h
81310+++ b/include/linux/preempt.h
81311@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81312 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81313 #endif
81314
81315+#define raw_preempt_count_add(val) __preempt_count_add(val)
81316+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81317+
81318 #define __preempt_count_inc() __preempt_count_add(1)
81319 #define __preempt_count_dec() __preempt_count_sub(1)
81320
81321 #define preempt_count_inc() preempt_count_add(1)
81322+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81323 #define preempt_count_dec() preempt_count_sub(1)
81324+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81325
81326 #ifdef CONFIG_PREEMPT_COUNT
81327
81328@@ -41,6 +46,12 @@ do { \
81329 barrier(); \
81330 } while (0)
81331
81332+#define raw_preempt_disable() \
81333+do { \
81334+ raw_preempt_count_inc(); \
81335+ barrier(); \
81336+} while (0)
81337+
81338 #define sched_preempt_enable_no_resched() \
81339 do { \
81340 barrier(); \
81341@@ -49,6 +60,12 @@ do { \
81342
81343 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81344
81345+#define raw_preempt_enable_no_resched() \
81346+do { \
81347+ barrier(); \
81348+ raw_preempt_count_dec(); \
81349+} while (0)
81350+
81351 #ifdef CONFIG_PREEMPT
81352 #define preempt_enable() \
81353 do { \
81354@@ -113,8 +130,10 @@ do { \
81355 * region.
81356 */
81357 #define preempt_disable() barrier()
81358+#define raw_preempt_disable() barrier()
81359 #define sched_preempt_enable_no_resched() barrier()
81360 #define preempt_enable_no_resched() barrier()
81361+#define raw_preempt_enable_no_resched() barrier()
81362 #define preempt_enable() barrier()
81363 #define preempt_check_resched() do { } while (0)
81364
81365@@ -128,11 +147,13 @@ do { \
81366 /*
81367 * Modules have no business playing preemption tricks.
81368 */
81369+#ifndef CONFIG_PAX_KERNEXEC
81370 #undef sched_preempt_enable_no_resched
81371 #undef preempt_enable_no_resched
81372 #undef preempt_enable_no_resched_notrace
81373 #undef preempt_check_resched
81374 #endif
81375+#endif
81376
81377 #define preempt_set_need_resched() \
81378 do { \
81379diff --git a/include/linux/printk.h b/include/linux/printk.h
81380index fa47e27..c08e034 100644
81381--- a/include/linux/printk.h
81382+++ b/include/linux/printk.h
81383@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81384 void early_printk(const char *s, ...) { }
81385 #endif
81386
81387+extern int kptr_restrict;
81388+
81389 #ifdef CONFIG_PRINTK
81390 asmlinkage __printf(5, 0)
81391 int vprintk_emit(int facility, int level,
81392@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81393
81394 extern int printk_delay_msec;
81395 extern int dmesg_restrict;
81396-extern int kptr_restrict;
81397
81398 extern void wake_up_klogd(void);
81399
81400diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81401index 608e60a..bbcb1a0 100644
81402--- a/include/linux/proc_fs.h
81403+++ b/include/linux/proc_fs.h
81404@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81405 extern struct proc_dir_entry *proc_symlink(const char *,
81406 struct proc_dir_entry *, const char *);
81407 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81408+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81409 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81410 struct proc_dir_entry *, void *);
81411+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81412+ struct proc_dir_entry *, void *);
81413 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81414 struct proc_dir_entry *);
81415
81416@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81417 return proc_create_data(name, mode, parent, proc_fops, NULL);
81418 }
81419
81420+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81421+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81422+{
81423+#ifdef CONFIG_GRKERNSEC_PROC_USER
81424+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81425+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81426+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81427+#else
81428+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81429+#endif
81430+}
81431+
81432+
81433 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81434 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81435 extern void *PDE_DATA(const struct inode *);
81436@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81437 static inline struct proc_dir_entry *proc_net_mkdir(
81438 struct net *net, const char *name, struct proc_dir_entry *parent)
81439 {
81440- return proc_mkdir_data(name, 0, parent, net);
81441+ return proc_mkdir_data_restrict(name, 0, parent, net);
81442 }
81443
81444 #endif /* _LINUX_PROC_FS_H */
81445diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81446index 34a1e10..70f6bde 100644
81447--- a/include/linux/proc_ns.h
81448+++ b/include/linux/proc_ns.h
81449@@ -14,7 +14,7 @@ struct proc_ns_operations {
81450 void (*put)(void *ns);
81451 int (*install)(struct nsproxy *nsproxy, void *ns);
81452 unsigned int (*inum)(void *ns);
81453-};
81454+} __do_const __randomize_layout;
81455
81456 struct proc_ns {
81457 void *ns;
81458diff --git a/include/linux/quota.h b/include/linux/quota.h
81459index cc7494a..1e27036 100644
81460--- a/include/linux/quota.h
81461+++ b/include/linux/quota.h
81462@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81463
81464 extern bool qid_eq(struct kqid left, struct kqid right);
81465 extern bool qid_lt(struct kqid left, struct kqid right);
81466-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81467+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81468 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81469 extern bool qid_valid(struct kqid qid);
81470
81471diff --git a/include/linux/random.h b/include/linux/random.h
81472index 1cfce0e..b0b9235 100644
81473--- a/include/linux/random.h
81474+++ b/include/linux/random.h
81475@@ -9,9 +9,19 @@
81476 #include <uapi/linux/random.h>
81477
81478 extern void add_device_randomness(const void *, unsigned int);
81479+
81480+static inline void add_latent_entropy(void)
81481+{
81482+
81483+#ifdef LATENT_ENTROPY_PLUGIN
81484+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81485+#endif
81486+
81487+}
81488+
81489 extern void add_input_randomness(unsigned int type, unsigned int code,
81490- unsigned int value);
81491-extern void add_interrupt_randomness(int irq, int irq_flags);
81492+ unsigned int value) __latent_entropy;
81493+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81494
81495 extern void get_random_bytes(void *buf, int nbytes);
81496 extern void get_random_bytes_arch(void *buf, int nbytes);
81497@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81498 extern const struct file_operations random_fops, urandom_fops;
81499 #endif
81500
81501-unsigned int get_random_int(void);
81502+unsigned int __intentional_overflow(-1) get_random_int(void);
81503 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81504
81505-u32 prandom_u32(void);
81506+u32 prandom_u32(void) __intentional_overflow(-1);
81507 void prandom_bytes(void *buf, int nbytes);
81508 void prandom_seed(u32 seed);
81509 void prandom_reseed_late(void);
81510@@ -37,6 +47,11 @@ struct rnd_state {
81511 u32 prandom_u32_state(struct rnd_state *state);
81512 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81513
81514+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81515+{
81516+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81517+}
81518+
81519 /**
81520 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81521 * @ep_ro: right open interval endpoint
81522diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81523index fea49b5..2ac22bb 100644
81524--- a/include/linux/rbtree_augmented.h
81525+++ b/include/linux/rbtree_augmented.h
81526@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81527 old->rbaugmented = rbcompute(old); \
81528 } \
81529 rbstatic const struct rb_augment_callbacks rbname = { \
81530- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81531+ .propagate = rbname ## _propagate, \
81532+ .copy = rbname ## _copy, \
81533+ .rotate = rbname ## _rotate \
81534 };
81535
81536
81537diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81538index dbaf990..52e07b8 100644
81539--- a/include/linux/rculist.h
81540+++ b/include/linux/rculist.h
81541@@ -29,8 +29,8 @@
81542 */
81543 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81544 {
81545- ACCESS_ONCE(list->next) = list;
81546- ACCESS_ONCE(list->prev) = list;
81547+ ACCESS_ONCE_RW(list->next) = list;
81548+ ACCESS_ONCE_RW(list->prev) = list;
81549 }
81550
81551 /*
81552@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81553 struct list_head *prev, struct list_head *next);
81554 #endif
81555
81556+void __pax_list_add_rcu(struct list_head *new,
81557+ struct list_head *prev, struct list_head *next);
81558+
81559 /**
81560 * list_add_rcu - add a new entry to rcu-protected list
81561 * @new: new entry to be added
81562@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81563 __list_add_rcu(new, head, head->next);
81564 }
81565
81566+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81567+{
81568+ __pax_list_add_rcu(new, head, head->next);
81569+}
81570+
81571 /**
81572 * list_add_tail_rcu - add a new entry to rcu-protected list
81573 * @new: new entry to be added
81574@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81575 __list_add_rcu(new, head->prev, head);
81576 }
81577
81578+static inline void pax_list_add_tail_rcu(struct list_head *new,
81579+ struct list_head *head)
81580+{
81581+ __pax_list_add_rcu(new, head->prev, head);
81582+}
81583+
81584 /**
81585 * list_del_rcu - deletes entry from list without re-initialization
81586 * @entry: the element to delete from the list.
81587@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81588 entry->prev = LIST_POISON2;
81589 }
81590
81591+extern void pax_list_del_rcu(struct list_head *entry);
81592+
81593 /**
81594 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81595 * @n: the element to delete from the hash list.
81596diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81597index 72bf3a0..853347f 100644
81598--- a/include/linux/rcupdate.h
81599+++ b/include/linux/rcupdate.h
81600@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81601 #define rcu_assign_pointer(p, v) \
81602 do { \
81603 smp_wmb(); \
81604- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81605+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81606 } while (0)
81607
81608
81609diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81610index 9e7db9e..7d4fd72 100644
81611--- a/include/linux/reboot.h
81612+++ b/include/linux/reboot.h
81613@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81614 */
81615
81616 extern void migrate_to_reboot_cpu(void);
81617-extern void machine_restart(char *cmd);
81618-extern void machine_halt(void);
81619-extern void machine_power_off(void);
81620+extern void machine_restart(char *cmd) __noreturn;
81621+extern void machine_halt(void) __noreturn;
81622+extern void machine_power_off(void) __noreturn;
81623
81624 extern void machine_shutdown(void);
81625 struct pt_regs;
81626@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81627 */
81628
81629 extern void kernel_restart_prepare(char *cmd);
81630-extern void kernel_restart(char *cmd);
81631-extern void kernel_halt(void);
81632-extern void kernel_power_off(void);
81633+extern void kernel_restart(char *cmd) __noreturn;
81634+extern void kernel_halt(void) __noreturn;
81635+extern void kernel_power_off(void) __noreturn;
81636
81637 extern int C_A_D; /* for sysctl */
81638 void ctrl_alt_del(void);
81639@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81640 * Emergency restart, callable from an interrupt handler.
81641 */
81642
81643-extern void emergency_restart(void);
81644+extern void emergency_restart(void) __noreturn;
81645 #include <asm/emergency-restart.h>
81646
81647 #endif /* _LINUX_REBOOT_H */
81648diff --git a/include/linux/regset.h b/include/linux/regset.h
81649index 8e0c9fe..ac4d221 100644
81650--- a/include/linux/regset.h
81651+++ b/include/linux/regset.h
81652@@ -161,7 +161,8 @@ struct user_regset {
81653 unsigned int align;
81654 unsigned int bias;
81655 unsigned int core_note_type;
81656-};
81657+} __do_const;
81658+typedef struct user_regset __no_const user_regset_no_const;
81659
81660 /**
81661 * struct user_regset_view - available regsets
81662diff --git a/include/linux/relay.h b/include/linux/relay.h
81663index d7c8359..818daf5 100644
81664--- a/include/linux/relay.h
81665+++ b/include/linux/relay.h
81666@@ -157,7 +157,7 @@ struct rchan_callbacks
81667 * The callback should return 0 if successful, negative if not.
81668 */
81669 int (*remove_buf_file)(struct dentry *dentry);
81670-};
81671+} __no_const;
81672
81673 /*
81674 * CONFIG_RELAY kernel API, kernel/relay.c
81675diff --git a/include/linux/rio.h b/include/linux/rio.h
81676index b71d573..2f940bd 100644
81677--- a/include/linux/rio.h
81678+++ b/include/linux/rio.h
81679@@ -355,7 +355,7 @@ struct rio_ops {
81680 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81681 u64 rstart, u32 size, u32 flags);
81682 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81683-};
81684+} __no_const;
81685
81686 #define RIO_RESOURCE_MEM 0x00000100
81687 #define RIO_RESOURCE_DOORBELL 0x00000200
81688diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81689index b66c211..13d2915 100644
81690--- a/include/linux/rmap.h
81691+++ b/include/linux/rmap.h
81692@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81693 void anon_vma_init(void); /* create anon_vma_cachep */
81694 int anon_vma_prepare(struct vm_area_struct *);
81695 void unlink_anon_vmas(struct vm_area_struct *);
81696-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81697-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81698+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81699+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81700
81701 static inline void anon_vma_merge(struct vm_area_struct *vma,
81702 struct vm_area_struct *next)
81703diff --git a/include/linux/sched.h b/include/linux/sched.h
81704index a781dec..be1d2a3 100644
81705--- a/include/linux/sched.h
81706+++ b/include/linux/sched.h
81707@@ -129,6 +129,7 @@ struct fs_struct;
81708 struct perf_event_context;
81709 struct blk_plug;
81710 struct filename;
81711+struct linux_binprm;
81712
81713 /*
81714 * List of flags we want to share for kernel threads,
81715@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
81716 extern int in_sched_functions(unsigned long addr);
81717
81718 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81719-extern signed long schedule_timeout(signed long timeout);
81720+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81721 extern signed long schedule_timeout_interruptible(signed long timeout);
81722 extern signed long schedule_timeout_killable(signed long timeout);
81723 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81724@@ -380,6 +381,19 @@ struct nsproxy;
81725 struct user_namespace;
81726
81727 #ifdef CONFIG_MMU
81728+
81729+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81730+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81731+#else
81732+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81733+{
81734+ return 0;
81735+}
81736+#endif
81737+
81738+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81739+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81740+
81741 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81742 extern unsigned long
81743 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81744@@ -677,6 +691,17 @@ struct signal_struct {
81745 #ifdef CONFIG_TASKSTATS
81746 struct taskstats *stats;
81747 #endif
81748+
81749+#ifdef CONFIG_GRKERNSEC
81750+ u32 curr_ip;
81751+ u32 saved_ip;
81752+ u32 gr_saddr;
81753+ u32 gr_daddr;
81754+ u16 gr_sport;
81755+ u16 gr_dport;
81756+ u8 used_accept:1;
81757+#endif
81758+
81759 #ifdef CONFIG_AUDIT
81760 unsigned audit_tty;
81761 unsigned audit_tty_log_passwd;
81762@@ -703,7 +728,7 @@ struct signal_struct {
81763 struct mutex cred_guard_mutex; /* guard against foreign influences on
81764 * credential calculations
81765 * (notably. ptrace) */
81766-};
81767+} __randomize_layout;
81768
81769 /*
81770 * Bits in flags field of signal_struct.
81771@@ -757,6 +782,14 @@ struct user_struct {
81772 struct key *session_keyring; /* UID's default session keyring */
81773 #endif
81774
81775+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81776+ unsigned char kernel_banned;
81777+#endif
81778+#ifdef CONFIG_GRKERNSEC_BRUTE
81779+ unsigned char suid_banned;
81780+ unsigned long suid_ban_expires;
81781+#endif
81782+
81783 /* Hash table maintenance information */
81784 struct hlist_node uidhash_node;
81785 kuid_t uid;
81786@@ -764,7 +797,7 @@ struct user_struct {
81787 #ifdef CONFIG_PERF_EVENTS
81788 atomic_long_t locked_vm;
81789 #endif
81790-};
81791+} __randomize_layout;
81792
81793 extern int uids_sysfs_init(void);
81794
81795@@ -1286,8 +1319,8 @@ struct task_struct {
81796 struct list_head thread_node;
81797
81798 struct completion *vfork_done; /* for vfork() */
81799- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81800- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81801+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81802+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81803
81804 cputime_t utime, stime, utimescaled, stimescaled;
81805 cputime_t gtime;
81806@@ -1312,11 +1345,6 @@ struct task_struct {
81807 struct task_cputime cputime_expires;
81808 struct list_head cpu_timers[3];
81809
81810-/* process credentials */
81811- const struct cred __rcu *real_cred; /* objective and real subjective task
81812- * credentials (COW) */
81813- const struct cred __rcu *cred; /* effective (overridable) subjective task
81814- * credentials (COW) */
81815 char comm[TASK_COMM_LEN]; /* executable name excluding path
81816 - access with [gs]et_task_comm (which lock
81817 it with task_lock())
81818@@ -1333,6 +1361,10 @@ struct task_struct {
81819 #endif
81820 /* CPU-specific state of this task */
81821 struct thread_struct thread;
81822+/* thread_info moved to task_struct */
81823+#ifdef CONFIG_X86
81824+ struct thread_info tinfo;
81825+#endif
81826 /* filesystem information */
81827 struct fs_struct *fs;
81828 /* open file information */
81829@@ -1409,6 +1441,10 @@ struct task_struct {
81830 gfp_t lockdep_reclaim_gfp;
81831 #endif
81832
81833+/* process credentials */
81834+ const struct cred __rcu *real_cred; /* objective and real subjective task
81835+ * credentials (COW) */
81836+
81837 /* journalling filesystem info */
81838 void *journal_info;
81839
81840@@ -1447,6 +1483,10 @@ struct task_struct {
81841 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81842 struct list_head cg_list;
81843 #endif
81844+
81845+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81846+ * credentials (COW) */
81847+
81848 #ifdef CONFIG_FUTEX
81849 struct robust_list_head __user *robust_list;
81850 #ifdef CONFIG_COMPAT
81851@@ -1581,7 +1621,78 @@ struct task_struct {
81852 unsigned int sequential_io;
81853 unsigned int sequential_io_avg;
81854 #endif
81855-};
81856+
81857+#ifdef CONFIG_GRKERNSEC
81858+ /* grsecurity */
81859+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81860+ u64 exec_id;
81861+#endif
81862+#ifdef CONFIG_GRKERNSEC_SETXID
81863+ const struct cred *delayed_cred;
81864+#endif
81865+ struct dentry *gr_chroot_dentry;
81866+ struct acl_subject_label *acl;
81867+ struct acl_subject_label *tmpacl;
81868+ struct acl_role_label *role;
81869+ struct file *exec_file;
81870+ unsigned long brute_expires;
81871+ u16 acl_role_id;
81872+ u8 inherited;
81873+ /* is this the task that authenticated to the special role */
81874+ u8 acl_sp_role;
81875+ u8 is_writable;
81876+ u8 brute;
81877+ u8 gr_is_chrooted;
81878+#endif
81879+
81880+} __randomize_layout;
81881+
81882+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81883+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81884+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81885+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81886+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81887+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81888+
81889+#ifdef CONFIG_PAX_SOFTMODE
81890+extern int pax_softmode;
81891+#endif
81892+
81893+extern int pax_check_flags(unsigned long *);
81894+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81895+
81896+/* if tsk != current then task_lock must be held on it */
81897+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81898+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81899+{
81900+ if (likely(tsk->mm))
81901+ return tsk->mm->pax_flags;
81902+ else
81903+ return 0UL;
81904+}
81905+
81906+/* if tsk != current then task_lock must be held on it */
81907+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81908+{
81909+ if (likely(tsk->mm)) {
81910+ tsk->mm->pax_flags = flags;
81911+ return 0;
81912+ }
81913+ return -EINVAL;
81914+}
81915+#endif
81916+
81917+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81918+extern void pax_set_initial_flags(struct linux_binprm *bprm);
81919+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81920+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81921+#endif
81922+
81923+struct path;
81924+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81925+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81926+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81927+extern void pax_report_refcount_overflow(struct pt_regs *regs);
81928
81929 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81930 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81931@@ -1658,7 +1769,7 @@ struct pid_namespace;
81932 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81933 struct pid_namespace *ns);
81934
81935-static inline pid_t task_pid_nr(struct task_struct *tsk)
81936+static inline pid_t task_pid_nr(const struct task_struct *tsk)
81937 {
81938 return tsk->pid;
81939 }
81940@@ -2112,7 +2223,9 @@ void yield(void);
81941 extern struct exec_domain default_exec_domain;
81942
81943 union thread_union {
81944+#ifndef CONFIG_X86
81945 struct thread_info thread_info;
81946+#endif
81947 unsigned long stack[THREAD_SIZE/sizeof(long)];
81948 };
81949
81950@@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
81951 */
81952
81953 extern struct task_struct *find_task_by_vpid(pid_t nr);
81954+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81955 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81956 struct pid_namespace *ns);
81957
81958@@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81959 extern void exit_itimers(struct signal_struct *);
81960 extern void flush_itimer_signals(void);
81961
81962-extern void do_group_exit(int);
81963+extern __noreturn void do_group_exit(int);
81964
81965 extern int allow_signal(int);
81966 extern int disallow_signal(int);
81967@@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81968
81969 #endif
81970
81971-static inline int object_is_on_stack(void *obj)
81972+static inline int object_starts_on_stack(void *obj)
81973 {
81974- void *stack = task_stack_page(current);
81975+ const void *stack = task_stack_page(current);
81976
81977 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81978 }
81979diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81980index 8045a55..c959cd5 100644
81981--- a/include/linux/sched/sysctl.h
81982+++ b/include/linux/sched/sysctl.h
81983@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81984 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81985
81986 extern int sysctl_max_map_count;
81987+extern unsigned long sysctl_heap_stack_gap;
81988
81989 extern unsigned int sysctl_sched_latency;
81990 extern unsigned int sysctl_sched_min_granularity;
81991diff --git a/include/linux/security.h b/include/linux/security.h
81992index 2fc42d1..4d802f2 100644
81993--- a/include/linux/security.h
81994+++ b/include/linux/security.h
81995@@ -27,6 +27,7 @@
81996 #include <linux/slab.h>
81997 #include <linux/err.h>
81998 #include <linux/string.h>
81999+#include <linux/grsecurity.h>
82000
82001 struct linux_binprm;
82002 struct cred;
82003@@ -116,8 +117,6 @@ struct seq_file;
82004
82005 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82006
82007-void reset_security_ops(void);
82008-
82009 #ifdef CONFIG_MMU
82010 extern unsigned long mmap_min_addr;
82011 extern unsigned long dac_mmap_min_addr;
82012@@ -1719,7 +1718,7 @@ struct security_operations {
82013 struct audit_context *actx);
82014 void (*audit_rule_free) (void *lsmrule);
82015 #endif /* CONFIG_AUDIT */
82016-};
82017+} __randomize_layout;
82018
82019 /* prototypes */
82020 extern int security_init(void);
82021diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82022index dc368b8..e895209 100644
82023--- a/include/linux/semaphore.h
82024+++ b/include/linux/semaphore.h
82025@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82026 }
82027
82028 extern void down(struct semaphore *sem);
82029-extern int __must_check down_interruptible(struct semaphore *sem);
82030+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82031 extern int __must_check down_killable(struct semaphore *sem);
82032 extern int __must_check down_trylock(struct semaphore *sem);
82033 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82034diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82035index 52e0097..383f21d 100644
82036--- a/include/linux/seq_file.h
82037+++ b/include/linux/seq_file.h
82038@@ -27,6 +27,9 @@ struct seq_file {
82039 struct mutex lock;
82040 const struct seq_operations *op;
82041 int poll_event;
82042+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82043+ u64 exec_id;
82044+#endif
82045 #ifdef CONFIG_USER_NS
82046 struct user_namespace *user_ns;
82047 #endif
82048@@ -39,6 +42,7 @@ struct seq_operations {
82049 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82050 int (*show) (struct seq_file *m, void *v);
82051 };
82052+typedef struct seq_operations __no_const seq_operations_no_const;
82053
82054 #define SEQ_SKIP 1
82055
82056@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82057
82058 char *mangle_path(char *s, const char *p, const char *esc);
82059 int seq_open(struct file *, const struct seq_operations *);
82060+int seq_open_restrict(struct file *, const struct seq_operations *);
82061 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82062 loff_t seq_lseek(struct file *, loff_t, int);
82063 int seq_release(struct inode *, struct file *);
82064@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82065 }
82066
82067 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82068+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82069 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82070 int single_release(struct inode *, struct file *);
82071 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82072diff --git a/include/linux/shm.h b/include/linux/shm.h
82073index 1e2cd2e..0288750 100644
82074--- a/include/linux/shm.h
82075+++ b/include/linux/shm.h
82076@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82077
82078 /* The task created the shm object. NULL if the task is dead. */
82079 struct task_struct *shm_creator;
82080+#ifdef CONFIG_GRKERNSEC
82081+ time_t shm_createtime;
82082+ pid_t shm_lapid;
82083+#endif
82084 };
82085
82086 /* shm_mode upper byte flags */
82087diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82088index 15ede6a..80161c3 100644
82089--- a/include/linux/skbuff.h
82090+++ b/include/linux/skbuff.h
82091@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82092 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82093 int node);
82094 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82095-static inline struct sk_buff *alloc_skb(unsigned int size,
82096+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82097 gfp_t priority)
82098 {
82099 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82100@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82101 return skb->inner_transport_header - skb->inner_network_header;
82102 }
82103
82104-static inline int skb_network_offset(const struct sk_buff *skb)
82105+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82106 {
82107 return skb_network_header(skb) - skb->data;
82108 }
82109@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82110 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82111 */
82112 #ifndef NET_SKB_PAD
82113-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82114+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82115 #endif
82116
82117 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82118@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82119 int *err);
82120 unsigned int datagram_poll(struct file *file, struct socket *sock,
82121 struct poll_table_struct *wait);
82122-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82123+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82124 struct iovec *to, int size);
82125 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82126 struct iovec *iov);
82127@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82128 nf_bridge_put(skb->nf_bridge);
82129 skb->nf_bridge = NULL;
82130 #endif
82131+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82132+ skb->nf_trace = 0;
82133+#endif
82134 }
82135
82136 static inline void nf_reset_trace(struct sk_buff *skb)
82137diff --git a/include/linux/slab.h b/include/linux/slab.h
82138index b5b2df6..69f5734 100644
82139--- a/include/linux/slab.h
82140+++ b/include/linux/slab.h
82141@@ -14,15 +14,29 @@
82142 #include <linux/gfp.h>
82143 #include <linux/types.h>
82144 #include <linux/workqueue.h>
82145-
82146+#include <linux/err.h>
82147
82148 /*
82149 * Flags to pass to kmem_cache_create().
82150 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82151 */
82152 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82153+
82154+#ifdef CONFIG_PAX_USERCOPY_SLABS
82155+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82156+#else
82157+#define SLAB_USERCOPY 0x00000000UL
82158+#endif
82159+
82160 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82161 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82162+
82163+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82164+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82165+#else
82166+#define SLAB_NO_SANITIZE 0x00000000UL
82167+#endif
82168+
82169 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82170 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82171 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82172@@ -98,10 +112,13 @@
82173 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82174 * Both make kfree a no-op.
82175 */
82176-#define ZERO_SIZE_PTR ((void *)16)
82177+#define ZERO_SIZE_PTR \
82178+({ \
82179+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82180+ (void *)(-MAX_ERRNO-1L); \
82181+})
82182
82183-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82184- (unsigned long)ZERO_SIZE_PTR)
82185+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82186
82187 #include <linux/kmemleak.h>
82188
82189@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82190 void kfree(const void *);
82191 void kzfree(const void *);
82192 size_t ksize(const void *);
82193+const char *check_heap_object(const void *ptr, unsigned long n);
82194+bool is_usercopy_object(const void *ptr);
82195
82196 /*
82197 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82198@@ -174,7 +193,7 @@ struct kmem_cache {
82199 unsigned int align; /* Alignment as calculated */
82200 unsigned long flags; /* Active flags on the slab */
82201 const char *name; /* Slab name for sysfs */
82202- int refcount; /* Use counter */
82203+ atomic_t refcount; /* Use counter */
82204 void (*ctor)(void *); /* Called on object slot creation */
82205 struct list_head list; /* List of all slab caches on the system */
82206 };
82207@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82208 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82209 #endif
82210
82211+#ifdef CONFIG_PAX_USERCOPY_SLABS
82212+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82213+#endif
82214+
82215 /*
82216 * Figure out which kmalloc slab an allocation of a certain size
82217 * belongs to.
82218@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82219 * 2 = 120 .. 192 bytes
82220 * n = 2^(n-1) .. 2^n -1
82221 */
82222-static __always_inline int kmalloc_index(size_t size)
82223+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82224 {
82225 if (!size)
82226 return 0;
82227@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82228 }
82229 #endif /* !CONFIG_SLOB */
82230
82231-void *__kmalloc(size_t size, gfp_t flags);
82232+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82233 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82234
82235 #ifdef CONFIG_NUMA
82236-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82237+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82238 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82239 #else
82240 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82241diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82242index 8235dfb..47ce586 100644
82243--- a/include/linux/slab_def.h
82244+++ b/include/linux/slab_def.h
82245@@ -38,7 +38,7 @@ struct kmem_cache {
82246 /* 4) cache creation/removal */
82247 const char *name;
82248 struct list_head list;
82249- int refcount;
82250+ atomic_t refcount;
82251 int object_size;
82252 int align;
82253
82254@@ -54,10 +54,14 @@ struct kmem_cache {
82255 unsigned long node_allocs;
82256 unsigned long node_frees;
82257 unsigned long node_overflow;
82258- atomic_t allochit;
82259- atomic_t allocmiss;
82260- atomic_t freehit;
82261- atomic_t freemiss;
82262+ atomic_unchecked_t allochit;
82263+ atomic_unchecked_t allocmiss;
82264+ atomic_unchecked_t freehit;
82265+ atomic_unchecked_t freemiss;
82266+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82267+ atomic_unchecked_t sanitized;
82268+ atomic_unchecked_t not_sanitized;
82269+#endif
82270
82271 /*
82272 * If debugging is enabled, then the allocator can add additional
82273diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82274index f56bfa9..8378a26 100644
82275--- a/include/linux/slub_def.h
82276+++ b/include/linux/slub_def.h
82277@@ -74,7 +74,7 @@ struct kmem_cache {
82278 struct kmem_cache_order_objects max;
82279 struct kmem_cache_order_objects min;
82280 gfp_t allocflags; /* gfp flags to use on each alloc */
82281- int refcount; /* Refcount for slab cache destroy */
82282+ atomic_t refcount; /* Refcount for slab cache destroy */
82283 void (*ctor)(void *);
82284 int inuse; /* Offset to metadata */
82285 int align; /* Alignment */
82286diff --git a/include/linux/smp.h b/include/linux/smp.h
82287index 6ae004e..2743532 100644
82288--- a/include/linux/smp.h
82289+++ b/include/linux/smp.h
82290@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82291 #endif
82292
82293 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82294+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82295 #define put_cpu() preempt_enable()
82296+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82297
82298 /*
82299 * Callback to arch code if there's nosmp or maxcpus=0 on the
82300diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82301index 54f91d3..be2c379 100644
82302--- a/include/linux/sock_diag.h
82303+++ b/include/linux/sock_diag.h
82304@@ -11,7 +11,7 @@ struct sock;
82305 struct sock_diag_handler {
82306 __u8 family;
82307 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82308-};
82309+} __do_const;
82310
82311 int sock_diag_register(const struct sock_diag_handler *h);
82312 void sock_diag_unregister(const struct sock_diag_handler *h);
82313diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82314index 680f9a3..f13aeb0 100644
82315--- a/include/linux/sonet.h
82316+++ b/include/linux/sonet.h
82317@@ -7,7 +7,7 @@
82318 #include <uapi/linux/sonet.h>
82319
82320 struct k_sonet_stats {
82321-#define __HANDLE_ITEM(i) atomic_t i
82322+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82323 __SONET_ITEMS
82324 #undef __HANDLE_ITEM
82325 };
82326diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82327index 07d8e53..dc934c9 100644
82328--- a/include/linux/sunrpc/addr.h
82329+++ b/include/linux/sunrpc/addr.h
82330@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82331 {
82332 switch (sap->sa_family) {
82333 case AF_INET:
82334- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82335+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82336 case AF_INET6:
82337- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82338+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82339 }
82340 return 0;
82341 }
82342@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82343 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82344 const struct sockaddr *src)
82345 {
82346- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82347+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82348 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82349
82350 dsin->sin_family = ssin->sin_family;
82351@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82352 if (sa->sa_family != AF_INET6)
82353 return 0;
82354
82355- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82356+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82357 }
82358
82359 #endif /* _LINUX_SUNRPC_ADDR_H */
82360diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82361index 8af2804..c7414ef 100644
82362--- a/include/linux/sunrpc/clnt.h
82363+++ b/include/linux/sunrpc/clnt.h
82364@@ -97,7 +97,7 @@ struct rpc_procinfo {
82365 unsigned int p_timer; /* Which RTT timer to use */
82366 u32 p_statidx; /* Which procedure to account */
82367 const char * p_name; /* name of procedure */
82368-};
82369+} __do_const;
82370
82371 #ifdef __KERNEL__
82372
82373diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82374index 04e7632..2e2a8a3 100644
82375--- a/include/linux/sunrpc/svc.h
82376+++ b/include/linux/sunrpc/svc.h
82377@@ -412,7 +412,7 @@ struct svc_procedure {
82378 unsigned int pc_count; /* call count */
82379 unsigned int pc_cachetype; /* cache info (NFS) */
82380 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82381-};
82382+} __do_const;
82383
82384 /*
82385 * Function prototypes.
82386diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82387index 0b8e3e6..33e0a01 100644
82388--- a/include/linux/sunrpc/svc_rdma.h
82389+++ b/include/linux/sunrpc/svc_rdma.h
82390@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82391 extern unsigned int svcrdma_max_requests;
82392 extern unsigned int svcrdma_max_req_size;
82393
82394-extern atomic_t rdma_stat_recv;
82395-extern atomic_t rdma_stat_read;
82396-extern atomic_t rdma_stat_write;
82397-extern atomic_t rdma_stat_sq_starve;
82398-extern atomic_t rdma_stat_rq_starve;
82399-extern atomic_t rdma_stat_rq_poll;
82400-extern atomic_t rdma_stat_rq_prod;
82401-extern atomic_t rdma_stat_sq_poll;
82402-extern atomic_t rdma_stat_sq_prod;
82403+extern atomic_unchecked_t rdma_stat_recv;
82404+extern atomic_unchecked_t rdma_stat_read;
82405+extern atomic_unchecked_t rdma_stat_write;
82406+extern atomic_unchecked_t rdma_stat_sq_starve;
82407+extern atomic_unchecked_t rdma_stat_rq_starve;
82408+extern atomic_unchecked_t rdma_stat_rq_poll;
82409+extern atomic_unchecked_t rdma_stat_rq_prod;
82410+extern atomic_unchecked_t rdma_stat_sq_poll;
82411+extern atomic_unchecked_t rdma_stat_sq_prod;
82412
82413 #define RPCRDMA_VERSION 1
82414
82415diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82416index 8d71d65..f79586e 100644
82417--- a/include/linux/sunrpc/svcauth.h
82418+++ b/include/linux/sunrpc/svcauth.h
82419@@ -120,7 +120,7 @@ struct auth_ops {
82420 int (*release)(struct svc_rqst *rq);
82421 void (*domain_release)(struct auth_domain *);
82422 int (*set_client)(struct svc_rqst *rq);
82423-};
82424+} __do_const;
82425
82426 #define SVC_GARBAGE 1
82427 #define SVC_SYSERR 2
82428diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82429index a5ffd32..0935dea 100644
82430--- a/include/linux/swiotlb.h
82431+++ b/include/linux/swiotlb.h
82432@@ -60,7 +60,8 @@ extern void
82433
82434 extern void
82435 swiotlb_free_coherent(struct device *hwdev, size_t size,
82436- void *vaddr, dma_addr_t dma_handle);
82437+ void *vaddr, dma_addr_t dma_handle,
82438+ struct dma_attrs *attrs);
82439
82440 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82441 unsigned long offset, size_t size,
82442diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82443index a747a77..9e14df7 100644
82444--- a/include/linux/syscalls.h
82445+++ b/include/linux/syscalls.h
82446@@ -98,8 +98,14 @@ struct sigaltstack;
82447 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82448
82449 #define __SC_DECL(t, a) t a
82450+#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))
82451 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82452-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82453+#define __SC_LONG(t, a) __typeof( \
82454+ __builtin_choose_expr( \
82455+ sizeof(t) > sizeof(int), \
82456+ (t) 0, \
82457+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82458+ )) a
82459 #define __SC_CAST(t, a) (t) a
82460 #define __SC_ARGS(t, a) a
82461 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82462@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82463 asmlinkage long sys_fsync(unsigned int fd);
82464 asmlinkage long sys_fdatasync(unsigned int fd);
82465 asmlinkage long sys_bdflush(int func, long data);
82466-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82467- char __user *type, unsigned long flags,
82468+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82469+ const char __user *type, unsigned long flags,
82470 void __user *data);
82471-asmlinkage long sys_umount(char __user *name, int flags);
82472-asmlinkage long sys_oldumount(char __user *name);
82473+asmlinkage long sys_umount(const char __user *name, int flags);
82474+asmlinkage long sys_oldumount(const char __user *name);
82475 asmlinkage long sys_truncate(const char __user *path, long length);
82476 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82477 asmlinkage long sys_stat(const char __user *filename,
82478@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82479 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82480 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82481 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82482- struct sockaddr __user *, int);
82483+ struct sockaddr __user *, int) __intentional_overflow(0);
82484 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82485 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82486 unsigned int vlen, unsigned flags);
82487diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82488index 27b3b0b..e093dd9 100644
82489--- a/include/linux/syscore_ops.h
82490+++ b/include/linux/syscore_ops.h
82491@@ -16,7 +16,7 @@ struct syscore_ops {
82492 int (*suspend)(void);
82493 void (*resume)(void);
82494 void (*shutdown)(void);
82495-};
82496+} __do_const;
82497
82498 extern void register_syscore_ops(struct syscore_ops *ops);
82499 extern void unregister_syscore_ops(struct syscore_ops *ops);
82500diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82501index 14a8ff2..fa95f3a 100644
82502--- a/include/linux/sysctl.h
82503+++ b/include/linux/sysctl.h
82504@@ -34,13 +34,13 @@ struct ctl_table_root;
82505 struct ctl_table_header;
82506 struct ctl_dir;
82507
82508-typedef struct ctl_table ctl_table;
82509-
82510 typedef int proc_handler (struct ctl_table *ctl, int write,
82511 void __user *buffer, size_t *lenp, loff_t *ppos);
82512
82513 extern int proc_dostring(struct ctl_table *, int,
82514 void __user *, size_t *, loff_t *);
82515+extern int proc_dostring_modpriv(struct ctl_table *, int,
82516+ void __user *, size_t *, loff_t *);
82517 extern int proc_dointvec(struct ctl_table *, int,
82518 void __user *, size_t *, loff_t *);
82519 extern int proc_dointvec_minmax(struct ctl_table *, int,
82520@@ -115,7 +115,9 @@ struct ctl_table
82521 struct ctl_table_poll *poll;
82522 void *extra1;
82523 void *extra2;
82524-};
82525+} __do_const __randomize_layout;
82526+typedef struct ctl_table __no_const ctl_table_no_const;
82527+typedef struct ctl_table ctl_table;
82528
82529 struct ctl_node {
82530 struct rb_node node;
82531diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82532index 30b2ebe..37412ef 100644
82533--- a/include/linux/sysfs.h
82534+++ b/include/linux/sysfs.h
82535@@ -34,7 +34,8 @@ struct attribute {
82536 struct lock_class_key *key;
82537 struct lock_class_key skey;
82538 #endif
82539-};
82540+} __do_const;
82541+typedef struct attribute __no_const attribute_no_const;
82542
82543 /**
82544 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82545@@ -63,7 +64,8 @@ struct attribute_group {
82546 struct attribute *, int);
82547 struct attribute **attrs;
82548 struct bin_attribute **bin_attrs;
82549-};
82550+} __do_const;
82551+typedef struct attribute_group __no_const attribute_group_no_const;
82552
82553 /**
82554 * Use these macros to make defining attributes easier. See include/linux/device.h
82555@@ -127,7 +129,8 @@ struct bin_attribute {
82556 char *, loff_t, size_t);
82557 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82558 struct vm_area_struct *vma);
82559-};
82560+} __do_const;
82561+typedef struct bin_attribute __no_const bin_attribute_no_const;
82562
82563 /**
82564 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82565diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82566index 387fa7d..3fcde6b 100644
82567--- a/include/linux/sysrq.h
82568+++ b/include/linux/sysrq.h
82569@@ -16,6 +16,7 @@
82570
82571 #include <linux/errno.h>
82572 #include <linux/types.h>
82573+#include <linux/compiler.h>
82574
82575 /* Possible values of bitmask for enabling sysrq functions */
82576 /* 0x0001 is reserved for enable everything */
82577@@ -33,7 +34,7 @@ struct sysrq_key_op {
82578 char *help_msg;
82579 char *action_msg;
82580 int enable_mask;
82581-};
82582+} __do_const;
82583
82584 #ifdef CONFIG_MAGIC_SYSRQ
82585
82586diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82587index fddbe20..e4cce53 100644
82588--- a/include/linux/thread_info.h
82589+++ b/include/linux/thread_info.h
82590@@ -161,6 +161,25 @@ static inline bool test_and_clear_restore_sigmask(void)
82591 #error "no set_restore_sigmask() provided and default one won't work"
82592 #endif
82593
82594+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82595+
82596+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82597+extern void pax_check_alloca(unsigned long size);
82598+#endif
82599+
82600+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82601+{
82602+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82603+ /* always check if we've overflowed the stack in a copy*user */
82604+ pax_check_alloca(sizeof(unsigned long));
82605+#endif
82606+
82607+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82608+ if (!__builtin_constant_p(n))
82609+#endif
82610+ __check_object_size(ptr, n, to_user);
82611+}
82612+
82613 #endif /* __KERNEL__ */
82614
82615 #endif /* _LINUX_THREAD_INFO_H */
82616diff --git a/include/linux/tty.h b/include/linux/tty.h
82617index b90b5c2..e23a512 100644
82618--- a/include/linux/tty.h
82619+++ b/include/linux/tty.h
82620@@ -202,7 +202,7 @@ struct tty_port {
82621 const struct tty_port_operations *ops; /* Port operations */
82622 spinlock_t lock; /* Lock protecting tty field */
82623 int blocked_open; /* Waiting to open */
82624- int count; /* Usage count */
82625+ atomic_t count; /* Usage count */
82626 wait_queue_head_t open_wait; /* Open waiters */
82627 wait_queue_head_t close_wait; /* Close waiters */
82628 wait_queue_head_t delta_msr_wait; /* Modem status change */
82629@@ -284,7 +284,7 @@ struct tty_struct {
82630 /* If the tty has a pending do_SAK, queue it here - akpm */
82631 struct work_struct SAK_work;
82632 struct tty_port *port;
82633-};
82634+} __randomize_layout;
82635
82636 /* Each of a tty's open files has private_data pointing to tty_file_private */
82637 struct tty_file_private {
82638@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82639 struct tty_struct *tty, struct file *filp);
82640 static inline int tty_port_users(struct tty_port *port)
82641 {
82642- return port->count + port->blocked_open;
82643+ return atomic_read(&port->count) + port->blocked_open;
82644 }
82645
82646 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82647diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82648index 756a609..89db85e 100644
82649--- a/include/linux/tty_driver.h
82650+++ b/include/linux/tty_driver.h
82651@@ -285,7 +285,7 @@ struct tty_operations {
82652 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82653 #endif
82654 const struct file_operations *proc_fops;
82655-};
82656+} __do_const __randomize_layout;
82657
82658 struct tty_driver {
82659 int magic; /* magic number for this structure */
82660@@ -319,7 +319,7 @@ struct tty_driver {
82661
82662 const struct tty_operations *ops;
82663 struct list_head tty_drivers;
82664-};
82665+} __randomize_layout;
82666
82667 extern struct list_head tty_drivers;
82668
82669diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82670index b8347c2..85d8b0f 100644
82671--- a/include/linux/tty_ldisc.h
82672+++ b/include/linux/tty_ldisc.h
82673@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
82674
82675 struct module *owner;
82676
82677- int refcount;
82678+ atomic_t refcount;
82679 };
82680
82681 struct tty_ldisc {
82682diff --git a/include/linux/types.h b/include/linux/types.h
82683index 4d118ba..c3ee9bf 100644
82684--- a/include/linux/types.h
82685+++ b/include/linux/types.h
82686@@ -176,10 +176,26 @@ typedef struct {
82687 int counter;
82688 } atomic_t;
82689
82690+#ifdef CONFIG_PAX_REFCOUNT
82691+typedef struct {
82692+ int counter;
82693+} atomic_unchecked_t;
82694+#else
82695+typedef atomic_t atomic_unchecked_t;
82696+#endif
82697+
82698 #ifdef CONFIG_64BIT
82699 typedef struct {
82700 long counter;
82701 } atomic64_t;
82702+
82703+#ifdef CONFIG_PAX_REFCOUNT
82704+typedef struct {
82705+ long counter;
82706+} atomic64_unchecked_t;
82707+#else
82708+typedef atomic64_t atomic64_unchecked_t;
82709+#endif
82710 #endif
82711
82712 struct list_head {
82713diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82714index ecd3319..8a36ded 100644
82715--- a/include/linux/uaccess.h
82716+++ b/include/linux/uaccess.h
82717@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82718 long ret; \
82719 mm_segment_t old_fs = get_fs(); \
82720 \
82721- set_fs(KERNEL_DS); \
82722 pagefault_disable(); \
82723- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82724- pagefault_enable(); \
82725+ set_fs(KERNEL_DS); \
82726+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82727 set_fs(old_fs); \
82728+ pagefault_enable(); \
82729 ret; \
82730 })
82731
82732diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82733index 2d1f9b6..d7a9fce 100644
82734--- a/include/linux/uidgid.h
82735+++ b/include/linux/uidgid.h
82736@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82737
82738 #endif /* CONFIG_USER_NS */
82739
82740+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82741+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82742+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82743+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82744+
82745 #endif /* _LINUX_UIDGID_H */
82746diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82747index 99c1b4d..562e6f3 100644
82748--- a/include/linux/unaligned/access_ok.h
82749+++ b/include/linux/unaligned/access_ok.h
82750@@ -4,34 +4,34 @@
82751 #include <linux/kernel.h>
82752 #include <asm/byteorder.h>
82753
82754-static inline u16 get_unaligned_le16(const void *p)
82755+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82756 {
82757- return le16_to_cpup((__le16 *)p);
82758+ return le16_to_cpup((const __le16 *)p);
82759 }
82760
82761-static inline u32 get_unaligned_le32(const void *p)
82762+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82763 {
82764- return le32_to_cpup((__le32 *)p);
82765+ return le32_to_cpup((const __le32 *)p);
82766 }
82767
82768-static inline u64 get_unaligned_le64(const void *p)
82769+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82770 {
82771- return le64_to_cpup((__le64 *)p);
82772+ return le64_to_cpup((const __le64 *)p);
82773 }
82774
82775-static inline u16 get_unaligned_be16(const void *p)
82776+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82777 {
82778- return be16_to_cpup((__be16 *)p);
82779+ return be16_to_cpup((const __be16 *)p);
82780 }
82781
82782-static inline u32 get_unaligned_be32(const void *p)
82783+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82784 {
82785- return be32_to_cpup((__be32 *)p);
82786+ return be32_to_cpup((const __be32 *)p);
82787 }
82788
82789-static inline u64 get_unaligned_be64(const void *p)
82790+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82791 {
82792- return be64_to_cpup((__be64 *)p);
82793+ return be64_to_cpup((const __be64 *)p);
82794 }
82795
82796 static inline void put_unaligned_le16(u16 val, void *p)
82797diff --git a/include/linux/usb.h b/include/linux/usb.h
82798index 7f6eb85..656e806 100644
82799--- a/include/linux/usb.h
82800+++ b/include/linux/usb.h
82801@@ -563,7 +563,7 @@ struct usb_device {
82802 int maxchild;
82803
82804 u32 quirks;
82805- atomic_t urbnum;
82806+ atomic_unchecked_t urbnum;
82807
82808 unsigned long active_duration;
82809
82810@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82811
82812 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82813 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82814- void *data, __u16 size, int timeout);
82815+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82816 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82817 void *data, int len, int *actual_length, int timeout);
82818 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82819diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82820index e452ba6..78f8e80 100644
82821--- a/include/linux/usb/renesas_usbhs.h
82822+++ b/include/linux/usb/renesas_usbhs.h
82823@@ -39,7 +39,7 @@ enum {
82824 */
82825 struct renesas_usbhs_driver_callback {
82826 int (*notify_hotplug)(struct platform_device *pdev);
82827-};
82828+} __no_const;
82829
82830 /*
82831 * callback functions for platform
82832diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82833index 4836ba3..603f6ee 100644
82834--- a/include/linux/user_namespace.h
82835+++ b/include/linux/user_namespace.h
82836@@ -33,7 +33,7 @@ struct user_namespace {
82837 struct key *persistent_keyring_register;
82838 struct rw_semaphore persistent_keyring_register_sem;
82839 #endif
82840-};
82841+} __randomize_layout;
82842
82843 extern struct user_namespace init_user_ns;
82844
82845diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82846index 239e277..22a5cf5 100644
82847--- a/include/linux/utsname.h
82848+++ b/include/linux/utsname.h
82849@@ -24,7 +24,7 @@ struct uts_namespace {
82850 struct new_utsname name;
82851 struct user_namespace *user_ns;
82852 unsigned int proc_inum;
82853-};
82854+} __randomize_layout;
82855 extern struct uts_namespace init_uts_ns;
82856
82857 #ifdef CONFIG_UTS_NS
82858diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82859index 6f8fbcf..4efc177 100644
82860--- a/include/linux/vermagic.h
82861+++ b/include/linux/vermagic.h
82862@@ -25,9 +25,42 @@
82863 #define MODULE_ARCH_VERMAGIC ""
82864 #endif
82865
82866+#ifdef CONFIG_PAX_REFCOUNT
82867+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82868+#else
82869+#define MODULE_PAX_REFCOUNT ""
82870+#endif
82871+
82872+#ifdef CONSTIFY_PLUGIN
82873+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82874+#else
82875+#define MODULE_CONSTIFY_PLUGIN ""
82876+#endif
82877+
82878+#ifdef STACKLEAK_PLUGIN
82879+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82880+#else
82881+#define MODULE_STACKLEAK_PLUGIN ""
82882+#endif
82883+
82884+#ifdef RANDSTRUCT_PLUGIN
82885+#include <generated/randomize_layout_hash.h>
82886+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82887+#else
82888+#define MODULE_RANDSTRUCT_PLUGIN
82889+#endif
82890+
82891+#ifdef CONFIG_GRKERNSEC
82892+#define MODULE_GRSEC "GRSEC "
82893+#else
82894+#define MODULE_GRSEC ""
82895+#endif
82896+
82897 #define VERMAGIC_STRING \
82898 UTS_RELEASE " " \
82899 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82900 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82901- MODULE_ARCH_VERMAGIC
82902+ MODULE_ARCH_VERMAGIC \
82903+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82904+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82905
82906diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82907index 502073a..a7de024 100644
82908--- a/include/linux/vga_switcheroo.h
82909+++ b/include/linux/vga_switcheroo.h
82910@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82911
82912 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82913
82914-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82915-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82916+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82917+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82918 #else
82919
82920 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82921@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82922
82923 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82924
82925-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82926-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82927+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82928+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82929
82930 #endif
82931 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82932diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82933index 4b8a891..cb8df6e 100644
82934--- a/include/linux/vmalloc.h
82935+++ b/include/linux/vmalloc.h
82936@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82937 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82938 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82939 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82940+
82941+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82942+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82943+#endif
82944+
82945 /* bits [20..32] reserved for arch specific ioremap internals */
82946
82947 /*
82948@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82949
82950 /* for /dev/kmem */
82951 extern long vread(char *buf, char *addr, unsigned long count);
82952-extern long vwrite(char *buf, char *addr, unsigned long count);
82953+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82954
82955 /*
82956 * Internals. Dont't use..
82957diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82958index 67ce70c..d540954 100644
82959--- a/include/linux/vmstat.h
82960+++ b/include/linux/vmstat.h
82961@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
82962 /*
82963 * Zone based page accounting with per cpu differentials.
82964 */
82965-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82966+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82967
82968 static inline void zone_page_state_add(long x, struct zone *zone,
82969 enum zone_stat_item item)
82970 {
82971- atomic_long_add(x, &zone->vm_stat[item]);
82972- atomic_long_add(x, &vm_stat[item]);
82973+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82974+ atomic_long_add_unchecked(x, &vm_stat[item]);
82975 }
82976
82977-static inline unsigned long global_page_state(enum zone_stat_item item)
82978+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82979 {
82980- long x = atomic_long_read(&vm_stat[item]);
82981+ long x = atomic_long_read_unchecked(&vm_stat[item]);
82982 #ifdef CONFIG_SMP
82983 if (x < 0)
82984 x = 0;
82985@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82986 return x;
82987 }
82988
82989-static inline unsigned long zone_page_state(struct zone *zone,
82990+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82991 enum zone_stat_item item)
82992 {
82993- long x = atomic_long_read(&zone->vm_stat[item]);
82994+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82995 #ifdef CONFIG_SMP
82996 if (x < 0)
82997 x = 0;
82998@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82999 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83000 enum zone_stat_item item)
83001 {
83002- long x = atomic_long_read(&zone->vm_stat[item]);
83003+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83004
83005 #ifdef CONFIG_SMP
83006 int cpu;
83007@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
83008
83009 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83010 {
83011- atomic_long_inc(&zone->vm_stat[item]);
83012- atomic_long_inc(&vm_stat[item]);
83013+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83014+ atomic_long_inc_unchecked(&vm_stat[item]);
83015 }
83016
83017 static inline void __inc_zone_page_state(struct page *page,
83018@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
83019
83020 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83021 {
83022- atomic_long_dec(&zone->vm_stat[item]);
83023- atomic_long_dec(&vm_stat[item]);
83024+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83025+ atomic_long_dec_unchecked(&vm_stat[item]);
83026 }
83027
83028 static inline void __dec_zone_page_state(struct page *page,
83029diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83030index 91b0a68..0e9adf6 100644
83031--- a/include/linux/xattr.h
83032+++ b/include/linux/xattr.h
83033@@ -28,7 +28,7 @@ struct xattr_handler {
83034 size_t size, int handler_flags);
83035 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83036 size_t size, int flags, int handler_flags);
83037-};
83038+} __do_const;
83039
83040 struct xattr {
83041 const char *name;
83042@@ -37,6 +37,9 @@ struct xattr {
83043 };
83044
83045 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83046+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83047+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83048+#endif
83049 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83050 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83051 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83052diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83053index 9c5a6b4..09c9438 100644
83054--- a/include/linux/zlib.h
83055+++ b/include/linux/zlib.h
83056@@ -31,6 +31,7 @@
83057 #define _ZLIB_H
83058
83059 #include <linux/zconf.h>
83060+#include <linux/compiler.h>
83061
83062 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83063 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83064@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83065
83066 /* basic functions */
83067
83068-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83069+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83070 /*
83071 Returns the number of bytes that needs to be allocated for a per-
83072 stream workspace with the specified parameters. A pointer to this
83073diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83074index c768c9f..bdcaa5a 100644
83075--- a/include/media/v4l2-dev.h
83076+++ b/include/media/v4l2-dev.h
83077@@ -76,7 +76,7 @@ struct v4l2_file_operations {
83078 int (*mmap) (struct file *, struct vm_area_struct *);
83079 int (*open) (struct file *);
83080 int (*release) (struct file *);
83081-};
83082+} __do_const;
83083
83084 /*
83085 * Newer version of video_device, handled by videodev2.c
83086diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83087index c9b1593..a572459 100644
83088--- a/include/media/v4l2-device.h
83089+++ b/include/media/v4l2-device.h
83090@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83091 this function returns 0. If the name ends with a digit (e.g. cx18),
83092 then the name will be set to cx18-0 since cx180 looks really odd. */
83093 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83094- atomic_t *instance);
83095+ atomic_unchecked_t *instance);
83096
83097 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83098 Since the parent disappears this ensures that v4l2_dev doesn't have an
83099diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83100index 9a36d92..0aafe2a 100644
83101--- a/include/net/9p/transport.h
83102+++ b/include/net/9p/transport.h
83103@@ -60,7 +60,7 @@ struct p9_trans_module {
83104 int (*cancel) (struct p9_client *, struct p9_req_t *req);
83105 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83106 char *, char *, int , int, int, int);
83107-};
83108+} __do_const;
83109
83110 void v9fs_register_trans(struct p9_trans_module *m);
83111 void v9fs_unregister_trans(struct p9_trans_module *m);
83112diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83113index a175ba4..196eb82 100644
83114--- a/include/net/af_unix.h
83115+++ b/include/net/af_unix.h
83116@@ -36,7 +36,7 @@ struct unix_skb_parms {
83117 u32 secid; /* Security ID */
83118 #endif
83119 u32 consumed;
83120-};
83121+} __randomize_layout;
83122
83123 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83124 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83125diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83126index dbc4a89..4a59b5d 100644
83127--- a/include/net/bluetooth/l2cap.h
83128+++ b/include/net/bluetooth/l2cap.h
83129@@ -600,7 +600,7 @@ struct l2cap_ops {
83130 long (*get_sndtimeo) (struct l2cap_chan *chan);
83131 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83132 unsigned long len, int nb);
83133-};
83134+} __do_const;
83135
83136 struct l2cap_conn {
83137 struct hci_conn *hcon;
83138diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83139index f2ae33d..c457cf0 100644
83140--- a/include/net/caif/cfctrl.h
83141+++ b/include/net/caif/cfctrl.h
83142@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83143 void (*radioset_rsp)(void);
83144 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83145 struct cflayer *client_layer);
83146-};
83147+} __no_const;
83148
83149 /* Link Setup Parameters for CAIF-Links. */
83150 struct cfctrl_link_param {
83151@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83152 struct cfctrl {
83153 struct cfsrvl serv;
83154 struct cfctrl_rsp res;
83155- atomic_t req_seq_no;
83156- atomic_t rsp_seq_no;
83157+ atomic_unchecked_t req_seq_no;
83158+ atomic_unchecked_t rsp_seq_no;
83159 struct list_head list;
83160 /* Protects from simultaneous access to first_req list */
83161 spinlock_t info_list_lock;
83162diff --git a/include/net/flow.h b/include/net/flow.h
83163index d23e7fa..e188307 100644
83164--- a/include/net/flow.h
83165+++ b/include/net/flow.h
83166@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83167
83168 void flow_cache_flush(void);
83169 void flow_cache_flush_deferred(void);
83170-extern atomic_t flow_cache_genid;
83171+extern atomic_unchecked_t flow_cache_genid;
83172
83173 #endif
83174diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83175index 93695f0..766d71c 100644
83176--- a/include/net/genetlink.h
83177+++ b/include/net/genetlink.h
83178@@ -120,7 +120,7 @@ struct genl_ops {
83179 u8 cmd;
83180 u8 internal_flags;
83181 u8 flags;
83182-};
83183+} __do_const;
83184
83185 int __genl_register_family(struct genl_family *family);
83186
83187diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83188index 734d9b5..48a9a4b 100644
83189--- a/include/net/gro_cells.h
83190+++ b/include/net/gro_cells.h
83191@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83192 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83193
83194 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83195- atomic_long_inc(&dev->rx_dropped);
83196+ atomic_long_inc_unchecked(&dev->rx_dropped);
83197 kfree_skb(skb);
83198 return;
83199 }
83200diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83201index c55aeed..b3393f4 100644
83202--- a/include/net/inet_connection_sock.h
83203+++ b/include/net/inet_connection_sock.h
83204@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83205 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83206 int (*bind_conflict)(const struct sock *sk,
83207 const struct inet_bind_bucket *tb, bool relax);
83208-};
83209+} __do_const;
83210
83211 /** inet_connection_sock - INET connection oriented sock
83212 *
83213diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83214index 6efe73c..fa94270 100644
83215--- a/include/net/inetpeer.h
83216+++ b/include/net/inetpeer.h
83217@@ -47,8 +47,8 @@ struct inet_peer {
83218 */
83219 union {
83220 struct {
83221- atomic_t rid; /* Frag reception counter */
83222- atomic_t ip_id_count; /* IP ID for the next packet */
83223+ atomic_unchecked_t rid; /* Frag reception counter */
83224+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83225 };
83226 struct rcu_head rcu;
83227 struct inet_peer *gc_next;
83228@@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83229 /* can be called with or without local BH being disabled */
83230 static inline int inet_getid(struct inet_peer *p, int more)
83231 {
83232- int old, new;
83233+ int id;
83234 more++;
83235 inet_peer_refcheck(p);
83236- do {
83237- old = atomic_read(&p->ip_id_count);
83238- new = old + more;
83239- if (!new)
83240- new = 1;
83241- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83242- return new;
83243+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
83244+ if (!id)
83245+ id = atomic_inc_return_unchecked(&p->ip_id_count);
83246+ return id;
83247 }
83248
83249 #endif /* _NET_INETPEER_H */
83250diff --git a/include/net/ip.h b/include/net/ip.h
83251index 23be0fd..0cb3e2c 100644
83252--- a/include/net/ip.h
83253+++ b/include/net/ip.h
83254@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83255
83256 void inet_get_local_port_range(struct net *net, int *low, int *high);
83257
83258-extern unsigned long *sysctl_local_reserved_ports;
83259+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83260 static inline int inet_is_reserved_local_port(int port)
83261 {
83262 return test_bit(port, sysctl_local_reserved_ports);
83263diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83264index 9922093..a1755d6 100644
83265--- a/include/net/ip_fib.h
83266+++ b/include/net/ip_fib.h
83267@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83268
83269 #define FIB_RES_SADDR(net, res) \
83270 ((FIB_RES_NH(res).nh_saddr_genid == \
83271- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83272+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83273 FIB_RES_NH(res).nh_saddr : \
83274 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83275 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83276diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83277index 5679d92..2e7a690 100644
83278--- a/include/net/ip_vs.h
83279+++ b/include/net/ip_vs.h
83280@@ -558,7 +558,7 @@ struct ip_vs_conn {
83281 struct ip_vs_conn *control; /* Master control connection */
83282 atomic_t n_control; /* Number of controlled ones */
83283 struct ip_vs_dest *dest; /* real server */
83284- atomic_t in_pkts; /* incoming packet counter */
83285+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83286
83287 /* packet transmitter for different forwarding methods. If it
83288 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83289@@ -705,7 +705,7 @@ struct ip_vs_dest {
83290 __be16 port; /* port number of the server */
83291 union nf_inet_addr addr; /* IP address of the server */
83292 volatile unsigned int flags; /* dest status flags */
83293- atomic_t conn_flags; /* flags to copy to conn */
83294+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83295 atomic_t weight; /* server weight */
83296
83297 atomic_t refcnt; /* reference counter */
83298@@ -960,11 +960,11 @@ struct netns_ipvs {
83299 /* ip_vs_lblc */
83300 int sysctl_lblc_expiration;
83301 struct ctl_table_header *lblc_ctl_header;
83302- struct ctl_table *lblc_ctl_table;
83303+ ctl_table_no_const *lblc_ctl_table;
83304 /* ip_vs_lblcr */
83305 int sysctl_lblcr_expiration;
83306 struct ctl_table_header *lblcr_ctl_header;
83307- struct ctl_table *lblcr_ctl_table;
83308+ ctl_table_no_const *lblcr_ctl_table;
83309 /* ip_vs_est */
83310 struct list_head est_list; /* estimator list */
83311 spinlock_t est_lock;
83312diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83313index 8d4f588..2e37ad2 100644
83314--- a/include/net/irda/ircomm_tty.h
83315+++ b/include/net/irda/ircomm_tty.h
83316@@ -33,6 +33,7 @@
83317 #include <linux/termios.h>
83318 #include <linux/timer.h>
83319 #include <linux/tty.h> /* struct tty_struct */
83320+#include <asm/local.h>
83321
83322 #include <net/irda/irias_object.h>
83323 #include <net/irda/ircomm_core.h>
83324diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83325index 714cc9a..ea05f3e 100644
83326--- a/include/net/iucv/af_iucv.h
83327+++ b/include/net/iucv/af_iucv.h
83328@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83329 struct iucv_sock_list {
83330 struct hlist_head head;
83331 rwlock_t lock;
83332- atomic_t autobind_name;
83333+ atomic_unchecked_t autobind_name;
83334 };
83335
83336 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83337diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83338index f3be818..bf46196 100644
83339--- a/include/net/llc_c_ac.h
83340+++ b/include/net/llc_c_ac.h
83341@@ -87,7 +87,7 @@
83342 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83343 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83344
83345-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83346+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83347
83348 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83349 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83350diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83351index 3948cf1..83b28c4 100644
83352--- a/include/net/llc_c_ev.h
83353+++ b/include/net/llc_c_ev.h
83354@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83355 return (struct llc_conn_state_ev *)skb->cb;
83356 }
83357
83358-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83359-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83360+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83361+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83362
83363 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83364 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83365diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83366index 0e79cfb..f46db31 100644
83367--- a/include/net/llc_c_st.h
83368+++ b/include/net/llc_c_st.h
83369@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83370 u8 next_state;
83371 llc_conn_ev_qfyr_t *ev_qualifiers;
83372 llc_conn_action_t *ev_actions;
83373-};
83374+} __do_const;
83375
83376 struct llc_conn_state {
83377 u8 current_state;
83378diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83379index a61b98c..aade1eb 100644
83380--- a/include/net/llc_s_ac.h
83381+++ b/include/net/llc_s_ac.h
83382@@ -23,7 +23,7 @@
83383 #define SAP_ACT_TEST_IND 9
83384
83385 /* All action functions must look like this */
83386-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83387+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83388
83389 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83390 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83391diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83392index 567c681..cd73ac0 100644
83393--- a/include/net/llc_s_st.h
83394+++ b/include/net/llc_s_st.h
83395@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83396 llc_sap_ev_t ev;
83397 u8 next_state;
83398 llc_sap_action_t *ev_actions;
83399-};
83400+} __do_const;
83401
83402 struct llc_sap_state {
83403 u8 curr_state;
83404diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83405index f4ab2fb..71a85ba 100644
83406--- a/include/net/mac80211.h
83407+++ b/include/net/mac80211.h
83408@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83409 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83410 struct dentry *dir);
83411 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83412-};
83413+} __do_const;
83414
83415 static inline int rate_supported(struct ieee80211_sta *sta,
83416 enum ieee80211_band band,
83417diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83418index 7277caf..fd095bc 100644
83419--- a/include/net/neighbour.h
83420+++ b/include/net/neighbour.h
83421@@ -163,7 +163,7 @@ struct neigh_ops {
83422 void (*error_report)(struct neighbour *, struct sk_buff *);
83423 int (*output)(struct neighbour *, struct sk_buff *);
83424 int (*connected_output)(struct neighbour *, struct sk_buff *);
83425-};
83426+} __do_const;
83427
83428 struct pneigh_entry {
83429 struct pneigh_entry *next;
83430@@ -203,7 +203,6 @@ struct neigh_table {
83431 void (*proxy_redo)(struct sk_buff *skb);
83432 char *id;
83433 struct neigh_parms parms;
83434- /* HACK. gc_* should follow parms without a gap! */
83435 int gc_interval;
83436 int gc_thresh1;
83437 int gc_thresh2;
83438@@ -218,7 +217,7 @@ struct neigh_table {
83439 struct neigh_statistics __percpu *stats;
83440 struct neigh_hash_table __rcu *nht;
83441 struct pneigh_entry **phash_buckets;
83442-};
83443+} __randomize_layout;
83444
83445 static inline int neigh_parms_family(struct neigh_parms *p)
83446 {
83447diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83448index 991dcd9..ab58d00 100644
83449--- a/include/net/net_namespace.h
83450+++ b/include/net/net_namespace.h
83451@@ -124,8 +124,8 @@ struct net {
83452 struct netns_ipvs *ipvs;
83453 #endif
83454 struct sock *diag_nlsk;
83455- atomic_t fnhe_genid;
83456-};
83457+ atomic_unchecked_t fnhe_genid;
83458+} __randomize_layout;
83459
83460 /*
83461 * ifindex generation is per-net namespace, and loopback is
83462@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83463 #define __net_init __init
83464 #define __net_exit __exit_refok
83465 #define __net_initdata __initdata
83466+#ifdef CONSTIFY_PLUGIN
83467 #define __net_initconst __initconst
83468+#else
83469+#define __net_initconst __initdata
83470+#endif
83471 #endif
83472
83473 struct pernet_operations {
83474@@ -299,7 +303,7 @@ struct pernet_operations {
83475 void (*exit_batch)(struct list_head *net_exit_list);
83476 int *id;
83477 size_t size;
83478-};
83479+} __do_const;
83480
83481 /*
83482 * Use these carefully. If you implement a network device and it
83483@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83484
83485 static inline int rt_genid_ipv4(struct net *net)
83486 {
83487- return atomic_read(&net->ipv4.rt_genid);
83488+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83489 }
83490
83491 static inline void rt_genid_bump_ipv4(struct net *net)
83492 {
83493- atomic_inc(&net->ipv4.rt_genid);
83494+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83495 }
83496
83497 #if IS_ENABLED(CONFIG_IPV6)
83498 static inline int rt_genid_ipv6(struct net *net)
83499 {
83500- return atomic_read(&net->ipv6.rt_genid);
83501+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83502 }
83503
83504 static inline void rt_genid_bump_ipv6(struct net *net)
83505 {
83506- atomic_inc(&net->ipv6.rt_genid);
83507+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83508 }
83509 #else
83510 static inline int rt_genid_ipv6(struct net *net)
83511@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83512
83513 static inline int fnhe_genid(struct net *net)
83514 {
83515- return atomic_read(&net->fnhe_genid);
83516+ return atomic_read_unchecked(&net->fnhe_genid);
83517 }
83518
83519 static inline void fnhe_genid_bump(struct net *net)
83520 {
83521- atomic_inc(&net->fnhe_genid);
83522+ atomic_inc_unchecked(&net->fnhe_genid);
83523 }
83524
83525 #endif /* __NET_NET_NAMESPACE_H */
83526diff --git a/include/net/netdma.h b/include/net/netdma.h
83527index 8ba8ce2..99b7fff 100644
83528--- a/include/net/netdma.h
83529+++ b/include/net/netdma.h
83530@@ -24,7 +24,7 @@
83531 #include <linux/dmaengine.h>
83532 #include <linux/skbuff.h>
83533
83534-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83535+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83536 struct sk_buff *skb, int offset, struct iovec *to,
83537 size_t len, struct dma_pinned_list *pinned_list);
83538
83539diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83540index 956b175..55d1504 100644
83541--- a/include/net/netfilter/nf_conntrack_extend.h
83542+++ b/include/net/netfilter/nf_conntrack_extend.h
83543@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83544 /* Extensions: optional stuff which isn't permanently in struct. */
83545 struct nf_ct_ext {
83546 struct rcu_head rcu;
83547- u8 offset[NF_CT_EXT_NUM];
83548- u8 len;
83549+ u16 offset[NF_CT_EXT_NUM];
83550+ u16 len;
83551 char data[0];
83552 };
83553
83554diff --git a/include/net/netlink.h b/include/net/netlink.h
83555index 2b47eaa..6d5bcc2 100644
83556--- a/include/net/netlink.h
83557+++ b/include/net/netlink.h
83558@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83559 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83560 {
83561 if (mark)
83562- skb_trim(skb, (unsigned char *) mark - skb->data);
83563+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83564 }
83565
83566 /**
83567diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83568index fbcc7fa..03c7e51 100644
83569--- a/include/net/netns/conntrack.h
83570+++ b/include/net/netns/conntrack.h
83571@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83572 struct nf_proto_net {
83573 #ifdef CONFIG_SYSCTL
83574 struct ctl_table_header *ctl_table_header;
83575- struct ctl_table *ctl_table;
83576+ ctl_table_no_const *ctl_table;
83577 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83578 struct ctl_table_header *ctl_compat_header;
83579- struct ctl_table *ctl_compat_table;
83580+ ctl_table_no_const *ctl_compat_table;
83581 #endif
83582 #endif
83583 unsigned int users;
83584@@ -58,7 +58,7 @@ struct nf_ip_net {
83585 struct nf_icmp_net icmpv6;
83586 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83587 struct ctl_table_header *ctl_table_header;
83588- struct ctl_table *ctl_table;
83589+ ctl_table_no_const *ctl_table;
83590 #endif
83591 };
83592
83593diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83594index 80f500a..f0c23c2 100644
83595--- a/include/net/netns/ipv4.h
83596+++ b/include/net/netns/ipv4.h
83597@@ -74,7 +74,7 @@ struct netns_ipv4 {
83598
83599 kgid_t sysctl_ping_group_range[2];
83600
83601- atomic_t dev_addr_genid;
83602+ atomic_unchecked_t dev_addr_genid;
83603
83604 #ifdef CONFIG_IP_MROUTE
83605 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83606@@ -84,6 +84,6 @@ struct netns_ipv4 {
83607 struct fib_rules_ops *mr_rules_ops;
83608 #endif
83609 #endif
83610- atomic_t rt_genid;
83611+ atomic_unchecked_t rt_genid;
83612 };
83613 #endif
83614diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83615index 21edaf1..4c5faae 100644
83616--- a/include/net/netns/ipv6.h
83617+++ b/include/net/netns/ipv6.h
83618@@ -73,8 +73,8 @@ struct netns_ipv6 {
83619 struct fib_rules_ops *mr6_rules_ops;
83620 #endif
83621 #endif
83622- atomic_t dev_addr_genid;
83623- atomic_t rt_genid;
83624+ atomic_unchecked_t dev_addr_genid;
83625+ atomic_unchecked_t rt_genid;
83626 };
83627
83628 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83629diff --git a/include/net/ping.h b/include/net/ping.h
83630index 026479b..d9b2829 100644
83631--- a/include/net/ping.h
83632+++ b/include/net/ping.h
83633@@ -54,7 +54,7 @@ struct ping_iter_state {
83634
83635 extern struct proto ping_prot;
83636 #if IS_ENABLED(CONFIG_IPV6)
83637-extern struct pingv6_ops pingv6_ops;
83638+extern struct pingv6_ops *pingv6_ops;
83639 #endif
83640
83641 struct pingfakehdr {
83642diff --git a/include/net/protocol.h b/include/net/protocol.h
83643index a7e986b..dc67bce 100644
83644--- a/include/net/protocol.h
83645+++ b/include/net/protocol.h
83646@@ -49,7 +49,7 @@ struct net_protocol {
83647 * socket lookup?
83648 */
83649 icmp_strict_tag_validation:1;
83650-};
83651+} __do_const;
83652
83653 #if IS_ENABLED(CONFIG_IPV6)
83654 struct inet6_protocol {
83655@@ -62,7 +62,7 @@ struct inet6_protocol {
83656 u8 type, u8 code, int offset,
83657 __be32 info);
83658 unsigned int flags; /* INET6_PROTO_xxx */
83659-};
83660+} __do_const;
83661
83662 #define INET6_PROTO_NOPOLICY 0x1
83663 #define INET6_PROTO_FINAL 0x2
83664diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83665index 661e45d..54c39df 100644
83666--- a/include/net/rtnetlink.h
83667+++ b/include/net/rtnetlink.h
83668@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83669 int (*fill_slave_info)(struct sk_buff *skb,
83670 const struct net_device *dev,
83671 const struct net_device *slave_dev);
83672-};
83673+} __do_const;
83674
83675 int __rtnl_link_register(struct rtnl_link_ops *ops);
83676 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83677diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83678index 4a5b9a3..ca27d73 100644
83679--- a/include/net/sctp/checksum.h
83680+++ b/include/net/sctp/checksum.h
83681@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83682 unsigned int offset)
83683 {
83684 struct sctphdr *sh = sctp_hdr(skb);
83685- __le32 ret, old = sh->checksum;
83686- const struct skb_checksum_ops ops = {
83687+ __le32 ret, old = sh->checksum;
83688+ static const struct skb_checksum_ops ops = {
83689 .update = sctp_csum_update,
83690 .combine = sctp_csum_combine,
83691 };
83692diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83693index 7f4eeb3..37e8fe1 100644
83694--- a/include/net/sctp/sm.h
83695+++ b/include/net/sctp/sm.h
83696@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83697 typedef struct {
83698 sctp_state_fn_t *fn;
83699 const char *name;
83700-} sctp_sm_table_entry_t;
83701+} __do_const sctp_sm_table_entry_t;
83702
83703 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83704 * currently in use.
83705@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83706 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83707
83708 /* Extern declarations for major data structures. */
83709-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83710+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83711
83712
83713 /* Get the size of a DATA chunk payload. */
83714diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83715index 6ee76c8..45f2609 100644
83716--- a/include/net/sctp/structs.h
83717+++ b/include/net/sctp/structs.h
83718@@ -507,7 +507,7 @@ struct sctp_pf {
83719 struct sctp_association *asoc);
83720 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83721 struct sctp_af *af;
83722-};
83723+} __do_const;
83724
83725
83726 /* Structure to track chunk fragments that have been acked, but peer
83727diff --git a/include/net/sock.h b/include/net/sock.h
83728index b9586a1..b2948c0 100644
83729--- a/include/net/sock.h
83730+++ b/include/net/sock.h
83731@@ -348,7 +348,7 @@ struct sock {
83732 unsigned int sk_napi_id;
83733 unsigned int sk_ll_usec;
83734 #endif
83735- atomic_t sk_drops;
83736+ atomic_unchecked_t sk_drops;
83737 int sk_rcvbuf;
83738
83739 struct sk_filter __rcu *sk_filter;
83740@@ -1036,7 +1036,7 @@ struct proto {
83741 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83742 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83743 #endif
83744-};
83745+} __randomize_layout;
83746
83747 /*
83748 * Bits in struct cg_proto.flags
83749@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83750 return ret >> PAGE_SHIFT;
83751 }
83752
83753-static inline long
83754+static inline long __intentional_overflow(-1)
83755 sk_memory_allocated(const struct sock *sk)
83756 {
83757 struct proto *prot = sk->sk_prot;
83758@@ -1368,7 +1368,7 @@ struct sock_iocb {
83759 struct scm_cookie *scm;
83760 struct msghdr *msg, async_msg;
83761 struct kiocb *kiocb;
83762-};
83763+} __randomize_layout;
83764
83765 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83766 {
83767@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83768 }
83769
83770 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83771- char __user *from, char *to,
83772+ char __user *from, unsigned char *to,
83773 int copy, int offset)
83774 {
83775 if (skb->ip_summed == CHECKSUM_NONE) {
83776@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83777 }
83778 }
83779
83780-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83781+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83782
83783 /**
83784 * sk_page_frag - return an appropriate page_frag
83785diff --git a/include/net/tcp.h b/include/net/tcp.h
83786index 743acce..44a58b0 100644
83787--- a/include/net/tcp.h
83788+++ b/include/net/tcp.h
83789@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83790 void tcp_xmit_retransmit_queue(struct sock *);
83791 void tcp_simple_retransmit(struct sock *);
83792 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83793-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83794+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83795
83796 void tcp_send_probe0(struct sock *);
83797 void tcp_send_partial(struct sock *);
83798@@ -710,8 +710,8 @@ struct tcp_skb_cb {
83799 struct inet6_skb_parm h6;
83800 #endif
83801 } header; /* For incoming frames */
83802- __u32 seq; /* Starting sequence number */
83803- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83804+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83805+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83806 __u32 when; /* used to compute rtt's */
83807 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83808
83809@@ -725,7 +725,7 @@ struct tcp_skb_cb {
83810
83811 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83812 /* 1 byte hole */
83813- __u32 ack_seq; /* Sequence number ACK'd */
83814+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83815 };
83816
83817 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83818diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83819index fb5654a..4457522 100644
83820--- a/include/net/xfrm.h
83821+++ b/include/net/xfrm.h
83822@@ -286,7 +286,6 @@ struct xfrm_dst;
83823 struct xfrm_policy_afinfo {
83824 unsigned short family;
83825 struct dst_ops *dst_ops;
83826- void (*garbage_collect)(struct net *net);
83827 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83828 const xfrm_address_t *saddr,
83829 const xfrm_address_t *daddr);
83830@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
83831 struct net_device *dev,
83832 const struct flowi *fl);
83833 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83834-};
83835+} __do_const;
83836
83837 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83838 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83839@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
83840 int (*transport_finish)(struct sk_buff *skb,
83841 int async);
83842 void (*local_error)(struct sk_buff *skb, u32 mtu);
83843-};
83844+} __do_const;
83845
83846 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83847 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83848@@ -428,7 +427,7 @@ struct xfrm_mode {
83849 struct module *owner;
83850 unsigned int encap;
83851 int flags;
83852-};
83853+} __do_const;
83854
83855 /* Flags for xfrm_mode. */
83856 enum {
83857@@ -525,7 +524,7 @@ struct xfrm_policy {
83858 struct timer_list timer;
83859
83860 struct flow_cache_object flo;
83861- atomic_t genid;
83862+ atomic_unchecked_t genid;
83863 u32 priority;
83864 u32 index;
83865 struct xfrm_mark mark;
83866@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83867 }
83868
83869 void xfrm_garbage_collect(struct net *net);
83870+void xfrm_garbage_collect_deferred(struct net *net);
83871
83872 #else
83873
83874@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83875 static inline void xfrm_garbage_collect(struct net *net)
83876 {
83877 }
83878+static inline void xfrm_garbage_collect_deferred(struct net *net)
83879+{
83880+}
83881 #endif
83882
83883 static __inline__
83884diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83885index 1017e0b..227aa4d 100644
83886--- a/include/rdma/iw_cm.h
83887+++ b/include/rdma/iw_cm.h
83888@@ -122,7 +122,7 @@ struct iw_cm_verbs {
83889 int backlog);
83890
83891 int (*destroy_listen)(struct iw_cm_id *cm_id);
83892-};
83893+} __no_const;
83894
83895 /**
83896 * iw_create_cm_id - Create an IW CM identifier.
83897diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83898index 52beadf..598734c 100644
83899--- a/include/scsi/libfc.h
83900+++ b/include/scsi/libfc.h
83901@@ -771,6 +771,7 @@ struct libfc_function_template {
83902 */
83903 void (*disc_stop_final) (struct fc_lport *);
83904 };
83905+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83906
83907 /**
83908 * struct fc_disc - Discovery context
83909@@ -875,7 +876,7 @@ struct fc_lport {
83910 struct fc_vport *vport;
83911
83912 /* Operational Information */
83913- struct libfc_function_template tt;
83914+ libfc_function_template_no_const tt;
83915 u8 link_up;
83916 u8 qfull;
83917 enum fc_lport_state state;
83918diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83919index d65fbec..f80fef2 100644
83920--- a/include/scsi/scsi_device.h
83921+++ b/include/scsi/scsi_device.h
83922@@ -180,9 +180,9 @@ struct scsi_device {
83923 unsigned int max_device_blocked; /* what device_blocked counts down from */
83924 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83925
83926- atomic_t iorequest_cnt;
83927- atomic_t iodone_cnt;
83928- atomic_t ioerr_cnt;
83929+ atomic_unchecked_t iorequest_cnt;
83930+ atomic_unchecked_t iodone_cnt;
83931+ atomic_unchecked_t ioerr_cnt;
83932
83933 struct device sdev_gendev,
83934 sdev_dev;
83935diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83936index b797e8f..8e2c3aa 100644
83937--- a/include/scsi/scsi_transport_fc.h
83938+++ b/include/scsi/scsi_transport_fc.h
83939@@ -751,7 +751,8 @@ struct fc_function_template {
83940 unsigned long show_host_system_hostname:1;
83941
83942 unsigned long disable_target_scan:1;
83943-};
83944+} __do_const;
83945+typedef struct fc_function_template __no_const fc_function_template_no_const;
83946
83947
83948 /**
83949diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83950index ae6c3b8..fd748ac 100644
83951--- a/include/sound/compress_driver.h
83952+++ b/include/sound/compress_driver.h
83953@@ -128,7 +128,7 @@ struct snd_compr_ops {
83954 struct snd_compr_caps *caps);
83955 int (*get_codec_caps) (struct snd_compr_stream *stream,
83956 struct snd_compr_codec_caps *codec);
83957-};
83958+} __no_const;
83959
83960 /**
83961 * struct snd_compr: Compressed device
83962diff --git a/include/sound/soc.h b/include/sound/soc.h
83963index 9a00147..d814573 100644
83964--- a/include/sound/soc.h
83965+++ b/include/sound/soc.h
83966@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
83967 /* probe ordering - for components with runtime dependencies */
83968 int probe_order;
83969 int remove_order;
83970-};
83971+} __do_const;
83972
83973 /* SoC platform interface */
83974 struct snd_soc_platform_driver {
83975@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
83976 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83977 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83978 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83979-};
83980+} __do_const;
83981
83982 struct snd_soc_platform {
83983 const char *name;
83984diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83985index 1772fad..282e3e2 100644
83986--- a/include/target/target_core_base.h
83987+++ b/include/target/target_core_base.h
83988@@ -754,7 +754,7 @@ struct se_device {
83989 atomic_long_t write_bytes;
83990 /* Active commands on this virtual SE device */
83991 atomic_t simple_cmds;
83992- atomic_t dev_ordered_id;
83993+ atomic_unchecked_t dev_ordered_id;
83994 atomic_t dev_ordered_sync;
83995 atomic_t dev_qf_count;
83996 int export_count;
83997diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83998new file mode 100644
83999index 0000000..fb634b7
84000--- /dev/null
84001+++ b/include/trace/events/fs.h
84002@@ -0,0 +1,53 @@
84003+#undef TRACE_SYSTEM
84004+#define TRACE_SYSTEM fs
84005+
84006+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84007+#define _TRACE_FS_H
84008+
84009+#include <linux/fs.h>
84010+#include <linux/tracepoint.h>
84011+
84012+TRACE_EVENT(do_sys_open,
84013+
84014+ TP_PROTO(const char *filename, int flags, int mode),
84015+
84016+ TP_ARGS(filename, flags, mode),
84017+
84018+ TP_STRUCT__entry(
84019+ __string( filename, filename )
84020+ __field( int, flags )
84021+ __field( int, mode )
84022+ ),
84023+
84024+ TP_fast_assign(
84025+ __assign_str(filename, filename);
84026+ __entry->flags = flags;
84027+ __entry->mode = mode;
84028+ ),
84029+
84030+ TP_printk("\"%s\" %x %o",
84031+ __get_str(filename), __entry->flags, __entry->mode)
84032+);
84033+
84034+TRACE_EVENT(open_exec,
84035+
84036+ TP_PROTO(const char *filename),
84037+
84038+ TP_ARGS(filename),
84039+
84040+ TP_STRUCT__entry(
84041+ __string( filename, filename )
84042+ ),
84043+
84044+ TP_fast_assign(
84045+ __assign_str(filename, filename);
84046+ ),
84047+
84048+ TP_printk("\"%s\"",
84049+ __get_str(filename))
84050+);
84051+
84052+#endif /* _TRACE_FS_H */
84053+
84054+/* This part must be outside protection */
84055+#include <trace/define_trace.h>
84056diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84057index 1c09820..7f5ec79 100644
84058--- a/include/trace/events/irq.h
84059+++ b/include/trace/events/irq.h
84060@@ -36,7 +36,7 @@ struct softirq_action;
84061 */
84062 TRACE_EVENT(irq_handler_entry,
84063
84064- TP_PROTO(int irq, struct irqaction *action),
84065+ TP_PROTO(int irq, const struct irqaction *action),
84066
84067 TP_ARGS(irq, action),
84068
84069@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84070 */
84071 TRACE_EVENT(irq_handler_exit,
84072
84073- TP_PROTO(int irq, struct irqaction *action, int ret),
84074+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84075
84076 TP_ARGS(irq, action, ret),
84077
84078diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84079index 7caf44c..23c6f27 100644
84080--- a/include/uapi/linux/a.out.h
84081+++ b/include/uapi/linux/a.out.h
84082@@ -39,6 +39,14 @@ enum machine_type {
84083 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84084 };
84085
84086+/* Constants for the N_FLAGS field */
84087+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84088+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84089+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84090+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84091+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84092+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84093+
84094 #if !defined (N_MAGIC)
84095 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84096 #endif
84097diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84098index 22b6ad3..aeba37e 100644
84099--- a/include/uapi/linux/bcache.h
84100+++ b/include/uapi/linux/bcache.h
84101@@ -5,6 +5,7 @@
84102 * Bcache on disk data structures
84103 */
84104
84105+#include <linux/compiler.h>
84106 #include <asm/types.h>
84107
84108 #define BITMASK(name, type, field, offset, size) \
84109@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84110 /* Btree keys - all units are in sectors */
84111
84112 struct bkey {
84113- __u64 high;
84114- __u64 low;
84115+ __u64 high __intentional_overflow(-1);
84116+ __u64 low __intentional_overflow(-1);
84117 __u64 ptr[];
84118 };
84119
84120diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84121index d876736..ccce5c0 100644
84122--- a/include/uapi/linux/byteorder/little_endian.h
84123+++ b/include/uapi/linux/byteorder/little_endian.h
84124@@ -42,51 +42,51 @@
84125
84126 static inline __le64 __cpu_to_le64p(const __u64 *p)
84127 {
84128- return (__force __le64)*p;
84129+ return (__force const __le64)*p;
84130 }
84131-static inline __u64 __le64_to_cpup(const __le64 *p)
84132+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84133 {
84134- return (__force __u64)*p;
84135+ return (__force const __u64)*p;
84136 }
84137 static inline __le32 __cpu_to_le32p(const __u32 *p)
84138 {
84139- return (__force __le32)*p;
84140+ return (__force const __le32)*p;
84141 }
84142 static inline __u32 __le32_to_cpup(const __le32 *p)
84143 {
84144- return (__force __u32)*p;
84145+ return (__force const __u32)*p;
84146 }
84147 static inline __le16 __cpu_to_le16p(const __u16 *p)
84148 {
84149- return (__force __le16)*p;
84150+ return (__force const __le16)*p;
84151 }
84152 static inline __u16 __le16_to_cpup(const __le16 *p)
84153 {
84154- return (__force __u16)*p;
84155+ return (__force const __u16)*p;
84156 }
84157 static inline __be64 __cpu_to_be64p(const __u64 *p)
84158 {
84159- return (__force __be64)__swab64p(p);
84160+ return (__force const __be64)__swab64p(p);
84161 }
84162 static inline __u64 __be64_to_cpup(const __be64 *p)
84163 {
84164- return __swab64p((__u64 *)p);
84165+ return __swab64p((const __u64 *)p);
84166 }
84167 static inline __be32 __cpu_to_be32p(const __u32 *p)
84168 {
84169- return (__force __be32)__swab32p(p);
84170+ return (__force const __be32)__swab32p(p);
84171 }
84172-static inline __u32 __be32_to_cpup(const __be32 *p)
84173+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84174 {
84175- return __swab32p((__u32 *)p);
84176+ return __swab32p((const __u32 *)p);
84177 }
84178 static inline __be16 __cpu_to_be16p(const __u16 *p)
84179 {
84180- return (__force __be16)__swab16p(p);
84181+ return (__force const __be16)__swab16p(p);
84182 }
84183 static inline __u16 __be16_to_cpup(const __be16 *p)
84184 {
84185- return __swab16p((__u16 *)p);
84186+ return __swab16p((const __u16 *)p);
84187 }
84188 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84189 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84190diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84191index ef6103b..d4e65dd 100644
84192--- a/include/uapi/linux/elf.h
84193+++ b/include/uapi/linux/elf.h
84194@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84195 #define PT_GNU_EH_FRAME 0x6474e550
84196
84197 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84198+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84199+
84200+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84201+
84202+/* Constants for the e_flags field */
84203+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84204+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84205+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84206+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84207+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84208+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84209
84210 /*
84211 * Extended Numbering
84212@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84213 #define DT_DEBUG 21
84214 #define DT_TEXTREL 22
84215 #define DT_JMPREL 23
84216+#define DT_FLAGS 30
84217+ #define DF_TEXTREL 0x00000004
84218 #define DT_ENCODING 32
84219 #define OLD_DT_LOOS 0x60000000
84220 #define DT_LOOS 0x6000000d
84221@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84222 #define PF_W 0x2
84223 #define PF_X 0x1
84224
84225+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84226+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84227+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84228+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84229+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84230+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84231+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84232+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84233+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84234+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84235+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84236+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84237+
84238 typedef struct elf32_phdr{
84239 Elf32_Word p_type;
84240 Elf32_Off p_offset;
84241@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84242 #define EI_OSABI 7
84243 #define EI_PAD 8
84244
84245+#define EI_PAX 14
84246+
84247 #define ELFMAG0 0x7f /* EI_MAG */
84248 #define ELFMAG1 'E'
84249 #define ELFMAG2 'L'
84250diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84251index aa169c4..6a2771d 100644
84252--- a/include/uapi/linux/personality.h
84253+++ b/include/uapi/linux/personality.h
84254@@ -30,6 +30,7 @@ enum {
84255 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84256 ADDR_NO_RANDOMIZE | \
84257 ADDR_COMPAT_LAYOUT | \
84258+ ADDR_LIMIT_3GB | \
84259 MMAP_PAGE_ZERO)
84260
84261 /*
84262diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84263index 7530e74..e714828 100644
84264--- a/include/uapi/linux/screen_info.h
84265+++ b/include/uapi/linux/screen_info.h
84266@@ -43,7 +43,8 @@ struct screen_info {
84267 __u16 pages; /* 0x32 */
84268 __u16 vesa_attributes; /* 0x34 */
84269 __u32 capabilities; /* 0x36 */
84270- __u8 _reserved[6]; /* 0x3a */
84271+ __u16 vesapm_size; /* 0x3a */
84272+ __u8 _reserved[4]; /* 0x3c */
84273 } __attribute__((packed));
84274
84275 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84276diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84277index 0e011eb..82681b1 100644
84278--- a/include/uapi/linux/swab.h
84279+++ b/include/uapi/linux/swab.h
84280@@ -43,7 +43,7 @@
84281 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84282 */
84283
84284-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84285+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84286 {
84287 #ifdef __HAVE_BUILTIN_BSWAP16__
84288 return __builtin_bswap16(val);
84289@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84290 #endif
84291 }
84292
84293-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84294+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84295 {
84296 #ifdef __HAVE_BUILTIN_BSWAP32__
84297 return __builtin_bswap32(val);
84298@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84299 #endif
84300 }
84301
84302-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84303+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84304 {
84305 #ifdef __HAVE_BUILTIN_BSWAP64__
84306 return __builtin_bswap64(val);
84307diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84308index 6d67213..552fdd9 100644
84309--- a/include/uapi/linux/sysctl.h
84310+++ b/include/uapi/linux/sysctl.h
84311@@ -155,8 +155,6 @@ enum
84312 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84313 };
84314
84315-
84316-
84317 /* CTL_VM names: */
84318 enum
84319 {
84320diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84321index fe94bb9..c9e51c2 100644
84322--- a/include/uapi/linux/videodev2.h
84323+++ b/include/uapi/linux/videodev2.h
84324@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84325 union {
84326 __s32 value;
84327 __s64 value64;
84328- char *string;
84329+ char __user *string;
84330 };
84331 } __attribute__ ((packed));
84332
84333diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84334index c38355c..17a57bc 100644
84335--- a/include/uapi/linux/xattr.h
84336+++ b/include/uapi/linux/xattr.h
84337@@ -73,5 +73,9 @@
84338 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84339 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84340
84341+/* User namespace */
84342+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84343+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84344+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84345
84346 #endif /* _UAPI_LINUX_XATTR_H */
84347diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84348index f9466fa..f4e2b81 100644
84349--- a/include/video/udlfb.h
84350+++ b/include/video/udlfb.h
84351@@ -53,10 +53,10 @@ struct dlfb_data {
84352 u32 pseudo_palette[256];
84353 int blank_mode; /*one of FB_BLANK_ */
84354 /* blit-only rendering path metrics, exposed through sysfs */
84355- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84356- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84357- atomic_t bytes_sent; /* to usb, after compression including overhead */
84358- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84359+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84360+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84361+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84362+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84363 };
84364
84365 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84366diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84367index 30f5362..8ed8ac9 100644
84368--- a/include/video/uvesafb.h
84369+++ b/include/video/uvesafb.h
84370@@ -122,6 +122,7 @@ struct uvesafb_par {
84371 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84372 u8 pmi_setpal; /* PMI for palette changes */
84373 u16 *pmi_base; /* protected mode interface location */
84374+ u8 *pmi_code; /* protected mode code location */
84375 void *pmi_start;
84376 void *pmi_pal;
84377 u8 *vbe_state_orig; /*
84378diff --git a/init/Kconfig b/init/Kconfig
84379index d56cb03..7e6d5dc 100644
84380--- a/init/Kconfig
84381+++ b/init/Kconfig
84382@@ -1079,6 +1079,7 @@ endif # CGROUPS
84383
84384 config CHECKPOINT_RESTORE
84385 bool "Checkpoint/restore support" if EXPERT
84386+ depends on !GRKERNSEC
84387 default n
84388 help
84389 Enables additional kernel features in a sake of checkpoint/restore.
84390@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84391
84392 config COMPAT_BRK
84393 bool "Disable heap randomization"
84394- default y
84395+ default n
84396 help
84397 Randomizing heap placement makes heap exploits harder, but it
84398 also breaks ancient binaries (including anything libc5 based).
84399@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84400 config STOP_MACHINE
84401 bool
84402 default y
84403- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84404+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84405 help
84406 Need stop_machine() primitive.
84407
84408diff --git a/init/Makefile b/init/Makefile
84409index 7bc47ee..6da2dc7 100644
84410--- a/init/Makefile
84411+++ b/init/Makefile
84412@@ -2,6 +2,9 @@
84413 # Makefile for the linux kernel.
84414 #
84415
84416+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84417+asflags-y := $(GCC_PLUGINS_AFLAGS)
84418+
84419 obj-y := main.o version.o mounts.o
84420 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84421 obj-y += noinitramfs.o
84422diff --git a/init/do_mounts.c b/init/do_mounts.c
84423index 8e5addc..c96ea61 100644
84424--- a/init/do_mounts.c
84425+++ b/init/do_mounts.c
84426@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84427 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84428 {
84429 struct super_block *s;
84430- int err = sys_mount(name, "/root", fs, flags, data);
84431+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84432 if (err)
84433 return err;
84434
84435- sys_chdir("/root");
84436+ sys_chdir((const char __force_user *)"/root");
84437 s = current->fs->pwd.dentry->d_sb;
84438 ROOT_DEV = s->s_dev;
84439 printk(KERN_INFO
84440@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84441 va_start(args, fmt);
84442 vsprintf(buf, fmt, args);
84443 va_end(args);
84444- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84445+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84446 if (fd >= 0) {
84447 sys_ioctl(fd, FDEJECT, 0);
84448 sys_close(fd);
84449 }
84450 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84451- fd = sys_open("/dev/console", O_RDWR, 0);
84452+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84453 if (fd >= 0) {
84454 sys_ioctl(fd, TCGETS, (long)&termios);
84455 termios.c_lflag &= ~ICANON;
84456 sys_ioctl(fd, TCSETSF, (long)&termios);
84457- sys_read(fd, &c, 1);
84458+ sys_read(fd, (char __user *)&c, 1);
84459 termios.c_lflag |= ICANON;
84460 sys_ioctl(fd, TCSETSF, (long)&termios);
84461 sys_close(fd);
84462@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84463 mount_root();
84464 out:
84465 devtmpfs_mount("dev");
84466- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84467- sys_chroot(".");
84468+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84469+ sys_chroot((const char __force_user *)".");
84470 }
84471
84472 static bool is_tmpfs;
84473diff --git a/init/do_mounts.h b/init/do_mounts.h
84474index f5b978a..69dbfe8 100644
84475--- a/init/do_mounts.h
84476+++ b/init/do_mounts.h
84477@@ -15,15 +15,15 @@ extern int root_mountflags;
84478
84479 static inline int create_dev(char *name, dev_t dev)
84480 {
84481- sys_unlink(name);
84482- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84483+ sys_unlink((char __force_user *)name);
84484+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84485 }
84486
84487 #if BITS_PER_LONG == 32
84488 static inline u32 bstat(char *name)
84489 {
84490 struct stat64 stat;
84491- if (sys_stat64(name, &stat) != 0)
84492+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84493 return 0;
84494 if (!S_ISBLK(stat.st_mode))
84495 return 0;
84496@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84497 static inline u32 bstat(char *name)
84498 {
84499 struct stat stat;
84500- if (sys_newstat(name, &stat) != 0)
84501+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84502 return 0;
84503 if (!S_ISBLK(stat.st_mode))
84504 return 0;
84505diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84506index 3e0878e..8a9d7a0 100644
84507--- a/init/do_mounts_initrd.c
84508+++ b/init/do_mounts_initrd.c
84509@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84510 {
84511 sys_unshare(CLONE_FS | CLONE_FILES);
84512 /* stdin/stdout/stderr for /linuxrc */
84513- sys_open("/dev/console", O_RDWR, 0);
84514+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84515 sys_dup(0);
84516 sys_dup(0);
84517 /* move initrd over / and chdir/chroot in initrd root */
84518- sys_chdir("/root");
84519- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84520- sys_chroot(".");
84521+ sys_chdir((const char __force_user *)"/root");
84522+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84523+ sys_chroot((const char __force_user *)".");
84524 sys_setsid();
84525 return 0;
84526 }
84527@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84528 create_dev("/dev/root.old", Root_RAM0);
84529 /* mount initrd on rootfs' /root */
84530 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84531- sys_mkdir("/old", 0700);
84532- sys_chdir("/old");
84533+ sys_mkdir((const char __force_user *)"/old", 0700);
84534+ sys_chdir((const char __force_user *)"/old");
84535
84536 /* try loading default modules from initrd */
84537 load_default_modules();
84538@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84539 current->flags &= ~PF_FREEZER_SKIP;
84540
84541 /* move initrd to rootfs' /old */
84542- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84543+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84544 /* switch root and cwd back to / of rootfs */
84545- sys_chroot("..");
84546+ sys_chroot((const char __force_user *)"..");
84547
84548 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84549- sys_chdir("/old");
84550+ sys_chdir((const char __force_user *)"/old");
84551 return;
84552 }
84553
84554- sys_chdir("/");
84555+ sys_chdir((const char __force_user *)"/");
84556 ROOT_DEV = new_decode_dev(real_root_dev);
84557 mount_root();
84558
84559 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84560- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84561+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84562 if (!error)
84563 printk("okay\n");
84564 else {
84565- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84566+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84567 if (error == -ENOENT)
84568 printk("/initrd does not exist. Ignored.\n");
84569 else
84570 printk("failed\n");
84571 printk(KERN_NOTICE "Unmounting old root\n");
84572- sys_umount("/old", MNT_DETACH);
84573+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84574 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84575 if (fd < 0) {
84576 error = fd;
84577@@ -127,11 +127,11 @@ int __init initrd_load(void)
84578 * mounted in the normal path.
84579 */
84580 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84581- sys_unlink("/initrd.image");
84582+ sys_unlink((const char __force_user *)"/initrd.image");
84583 handle_initrd();
84584 return 1;
84585 }
84586 }
84587- sys_unlink("/initrd.image");
84588+ sys_unlink((const char __force_user *)"/initrd.image");
84589 return 0;
84590 }
84591diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84592index 8cb6db5..d729f50 100644
84593--- a/init/do_mounts_md.c
84594+++ b/init/do_mounts_md.c
84595@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84596 partitioned ? "_d" : "", minor,
84597 md_setup_args[ent].device_names);
84598
84599- fd = sys_open(name, 0, 0);
84600+ fd = sys_open((char __force_user *)name, 0, 0);
84601 if (fd < 0) {
84602 printk(KERN_ERR "md: open failed - cannot start "
84603 "array %s\n", name);
84604@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84605 * array without it
84606 */
84607 sys_close(fd);
84608- fd = sys_open(name, 0, 0);
84609+ fd = sys_open((char __force_user *)name, 0, 0);
84610 sys_ioctl(fd, BLKRRPART, 0);
84611 }
84612 sys_close(fd);
84613@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84614
84615 wait_for_device_probe();
84616
84617- fd = sys_open("/dev/md0", 0, 0);
84618+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84619 if (fd >= 0) {
84620 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84621 sys_close(fd);
84622diff --git a/init/init_task.c b/init/init_task.c
84623index ba0a7f36..2bcf1d5 100644
84624--- a/init/init_task.c
84625+++ b/init/init_task.c
84626@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84627 * Initial thread structure. Alignment of this is handled by a special
84628 * linker map entry.
84629 */
84630+#ifdef CONFIG_X86
84631+union thread_union init_thread_union __init_task_data;
84632+#else
84633 union thread_union init_thread_union __init_task_data =
84634 { INIT_THREAD_INFO(init_task) };
84635+#endif
84636diff --git a/init/initramfs.c b/init/initramfs.c
84637index 93b6139..8d628b7 100644
84638--- a/init/initramfs.c
84639+++ b/init/initramfs.c
84640@@ -84,7 +84,7 @@ static void __init free_hash(void)
84641 }
84642 }
84643
84644-static long __init do_utime(char *filename, time_t mtime)
84645+static long __init do_utime(char __force_user *filename, time_t mtime)
84646 {
84647 struct timespec t[2];
84648
84649@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84650 struct dir_entry *de, *tmp;
84651 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84652 list_del(&de->list);
84653- do_utime(de->name, de->mtime);
84654+ do_utime((char __force_user *)de->name, de->mtime);
84655 kfree(de->name);
84656 kfree(de);
84657 }
84658@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84659 if (nlink >= 2) {
84660 char *old = find_link(major, minor, ino, mode, collected);
84661 if (old)
84662- return (sys_link(old, collected) < 0) ? -1 : 1;
84663+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84664 }
84665 return 0;
84666 }
84667@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84668 {
84669 struct stat st;
84670
84671- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84672+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84673 if (S_ISDIR(st.st_mode))
84674- sys_rmdir(path);
84675+ sys_rmdir((char __force_user *)path);
84676 else
84677- sys_unlink(path);
84678+ sys_unlink((char __force_user *)path);
84679 }
84680 }
84681
84682@@ -315,7 +315,7 @@ static int __init do_name(void)
84683 int openflags = O_WRONLY|O_CREAT;
84684 if (ml != 1)
84685 openflags |= O_TRUNC;
84686- wfd = sys_open(collected, openflags, mode);
84687+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84688
84689 if (wfd >= 0) {
84690 sys_fchown(wfd, uid, gid);
84691@@ -327,17 +327,17 @@ static int __init do_name(void)
84692 }
84693 }
84694 } else if (S_ISDIR(mode)) {
84695- sys_mkdir(collected, mode);
84696- sys_chown(collected, uid, gid);
84697- sys_chmod(collected, mode);
84698+ sys_mkdir((char __force_user *)collected, mode);
84699+ sys_chown((char __force_user *)collected, uid, gid);
84700+ sys_chmod((char __force_user *)collected, mode);
84701 dir_add(collected, mtime);
84702 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84703 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84704 if (maybe_link() == 0) {
84705- sys_mknod(collected, mode, rdev);
84706- sys_chown(collected, uid, gid);
84707- sys_chmod(collected, mode);
84708- do_utime(collected, mtime);
84709+ sys_mknod((char __force_user *)collected, mode, rdev);
84710+ sys_chown((char __force_user *)collected, uid, gid);
84711+ sys_chmod((char __force_user *)collected, mode);
84712+ do_utime((char __force_user *)collected, mtime);
84713 }
84714 }
84715 return 0;
84716@@ -346,15 +346,15 @@ static int __init do_name(void)
84717 static int __init do_copy(void)
84718 {
84719 if (count >= body_len) {
84720- sys_write(wfd, victim, body_len);
84721+ sys_write(wfd, (char __force_user *)victim, body_len);
84722 sys_close(wfd);
84723- do_utime(vcollected, mtime);
84724+ do_utime((char __force_user *)vcollected, mtime);
84725 kfree(vcollected);
84726 eat(body_len);
84727 state = SkipIt;
84728 return 0;
84729 } else {
84730- sys_write(wfd, victim, count);
84731+ sys_write(wfd, (char __force_user *)victim, count);
84732 body_len -= count;
84733 eat(count);
84734 return 1;
84735@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84736 {
84737 collected[N_ALIGN(name_len) + body_len] = '\0';
84738 clean_path(collected, 0);
84739- sys_symlink(collected + N_ALIGN(name_len), collected);
84740- sys_lchown(collected, uid, gid);
84741- do_utime(collected, mtime);
84742+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84743+ sys_lchown((char __force_user *)collected, uid, gid);
84744+ do_utime((char __force_user *)collected, mtime);
84745 state = SkipIt;
84746 next_state = Reset;
84747 return 0;
84748diff --git a/init/main.c b/init/main.c
84749index 9c7fd4c..650b4f1 100644
84750--- a/init/main.c
84751+++ b/init/main.c
84752@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84753 static inline void mark_rodata_ro(void) { }
84754 #endif
84755
84756+extern void grsecurity_init(void);
84757+
84758 /*
84759 * Debug helper: via this flag we know that we are in 'early bootup code'
84760 * where only the boot processor is running with IRQ disabled. This means
84761@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84762
84763 __setup("reset_devices", set_reset_devices);
84764
84765+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84766+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84767+static int __init setup_grsec_proc_gid(char *str)
84768+{
84769+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84770+ return 1;
84771+}
84772+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84773+#endif
84774+
84775+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84776+unsigned long pax_user_shadow_base __read_only;
84777+EXPORT_SYMBOL(pax_user_shadow_base);
84778+extern char pax_enter_kernel_user[];
84779+extern char pax_exit_kernel_user[];
84780+#endif
84781+
84782+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84783+static int __init setup_pax_nouderef(char *str)
84784+{
84785+#ifdef CONFIG_X86_32
84786+ unsigned int cpu;
84787+ struct desc_struct *gdt;
84788+
84789+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84790+ gdt = get_cpu_gdt_table(cpu);
84791+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84792+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84793+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84794+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84795+ }
84796+ loadsegment(ds, __KERNEL_DS);
84797+ loadsegment(es, __KERNEL_DS);
84798+ loadsegment(ss, __KERNEL_DS);
84799+#else
84800+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84801+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84802+ clone_pgd_mask = ~(pgdval_t)0UL;
84803+ pax_user_shadow_base = 0UL;
84804+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84805+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84806+#endif
84807+
84808+ return 0;
84809+}
84810+early_param("pax_nouderef", setup_pax_nouderef);
84811+
84812+#ifdef CONFIG_X86_64
84813+static int __init setup_pax_weakuderef(char *str)
84814+{
84815+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84816+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84817+ return 1;
84818+}
84819+__setup("pax_weakuderef", setup_pax_weakuderef);
84820+#endif
84821+#endif
84822+
84823+#ifdef CONFIG_PAX_SOFTMODE
84824+int pax_softmode;
84825+
84826+static int __init setup_pax_softmode(char *str)
84827+{
84828+ get_option(&str, &pax_softmode);
84829+ return 1;
84830+}
84831+__setup("pax_softmode=", setup_pax_softmode);
84832+#endif
84833+
84834 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84835 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84836 static const char *panic_later, *panic_param;
84837@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84838 {
84839 int count = preempt_count();
84840 int ret;
84841- char msgbuf[64];
84842+ const char *msg1 = "", *msg2 = "";
84843
84844 if (initcall_debug)
84845 ret = do_one_initcall_debug(fn);
84846 else
84847 ret = fn();
84848
84849- msgbuf[0] = 0;
84850-
84851 if (preempt_count() != count) {
84852- sprintf(msgbuf, "preemption imbalance ");
84853+ msg1 = " preemption imbalance";
84854 preempt_count_set(count);
84855 }
84856 if (irqs_disabled()) {
84857- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84858+ msg2 = " disabled interrupts";
84859 local_irq_enable();
84860 }
84861- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84862+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84863
84864+ add_latent_entropy();
84865 return ret;
84866 }
84867
84868@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84869 {
84870 argv_init[0] = init_filename;
84871 return do_execve(getname_kernel(init_filename),
84872- (const char __user *const __user *)argv_init,
84873- (const char __user *const __user *)envp_init);
84874+ (const char __user *const __force_user *)argv_init,
84875+ (const char __user *const __force_user *)envp_init);
84876 }
84877
84878 static int try_to_run_init_process(const char *init_filename)
84879@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84880 return ret;
84881 }
84882
84883+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84884+extern int gr_init_ran;
84885+#endif
84886+
84887 static noinline void __init kernel_init_freeable(void);
84888
84889 static int __ref kernel_init(void *unused)
84890@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
84891 ramdisk_execute_command, ret);
84892 }
84893
84894+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84895+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
84896+ gr_init_ran = 1;
84897+#endif
84898+
84899 /*
84900 * We try each of these until one succeeds.
84901 *
84902@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
84903 do_basic_setup();
84904
84905 /* Open the /dev/console on the rootfs, this should never fail */
84906- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84907+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84908 pr_err("Warning: unable to open an initial console.\n");
84909
84910 (void) sys_dup(0);
84911@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
84912 if (!ramdisk_execute_command)
84913 ramdisk_execute_command = "/init";
84914
84915- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84916+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84917 ramdisk_execute_command = NULL;
84918 prepare_namespace();
84919 }
84920
84921+ grsecurity_init();
84922+
84923 /*
84924 * Ok, we have completed the initial bootup, and
84925 * we're essentially up and running. Get rid of the
84926diff --git a/ipc/compat.c b/ipc/compat.c
84927index f486b00..442867f 100644
84928--- a/ipc/compat.c
84929+++ b/ipc/compat.c
84930@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84931 COMPAT_SHMLBA);
84932 if (err < 0)
84933 return err;
84934- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84935+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84936 }
84937 case SHMDT:
84938 return sys_shmdt(compat_ptr(ptr));
84939diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84940index 1702864..797fa84 100644
84941--- a/ipc/ipc_sysctl.c
84942+++ b/ipc/ipc_sysctl.c
84943@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84944 static int proc_ipc_dointvec(ctl_table *table, int write,
84945 void __user *buffer, size_t *lenp, loff_t *ppos)
84946 {
84947- struct ctl_table ipc_table;
84948+ ctl_table_no_const ipc_table;
84949
84950 memcpy(&ipc_table, table, sizeof(ipc_table));
84951 ipc_table.data = get_ipc(table);
84952@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84953 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84954 void __user *buffer, size_t *lenp, loff_t *ppos)
84955 {
84956- struct ctl_table ipc_table;
84957+ ctl_table_no_const ipc_table;
84958
84959 memcpy(&ipc_table, table, sizeof(ipc_table));
84960 ipc_table.data = get_ipc(table);
84961@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84962 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84963 void __user *buffer, size_t *lenp, loff_t *ppos)
84964 {
84965- struct ctl_table ipc_table;
84966+ ctl_table_no_const ipc_table;
84967 size_t lenp_bef = *lenp;
84968 int rc;
84969
84970@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84971 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84972 void __user *buffer, size_t *lenp, loff_t *ppos)
84973 {
84974- struct ctl_table ipc_table;
84975+ ctl_table_no_const ipc_table;
84976 memcpy(&ipc_table, table, sizeof(ipc_table));
84977 ipc_table.data = get_ipc(table);
84978
84979@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84980 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84981 void __user *buffer, size_t *lenp, loff_t *ppos)
84982 {
84983- struct ctl_table ipc_table;
84984+ ctl_table_no_const ipc_table;
84985 size_t lenp_bef = *lenp;
84986 int oldval;
84987 int rc;
84988diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84989index 5bb8bfe..a38ec05 100644
84990--- a/ipc/mq_sysctl.c
84991+++ b/ipc/mq_sysctl.c
84992@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84993 static int proc_mq_dointvec(ctl_table *table, int write,
84994 void __user *buffer, size_t *lenp, loff_t *ppos)
84995 {
84996- struct ctl_table mq_table;
84997+ ctl_table_no_const mq_table;
84998 memcpy(&mq_table, table, sizeof(mq_table));
84999 mq_table.data = get_mq(table);
85000
85001@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85002 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85003 void __user *buffer, size_t *lenp, loff_t *ppos)
85004 {
85005- struct ctl_table mq_table;
85006+ ctl_table_no_const mq_table;
85007 memcpy(&mq_table, table, sizeof(mq_table));
85008 mq_table.data = get_mq(table);
85009
85010diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85011index c3b3117..1efa933 100644
85012--- a/ipc/mqueue.c
85013+++ b/ipc/mqueue.c
85014@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85015 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85016 info->attr.mq_msgsize);
85017
85018+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85019 spin_lock(&mq_lock);
85020 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85021 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85022diff --git a/ipc/msg.c b/ipc/msg.c
85023index 6498531..b0ff3c8 100644
85024--- a/ipc/msg.c
85025+++ b/ipc/msg.c
85026@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85027 return security_msg_queue_associate(msq, msgflg);
85028 }
85029
85030+static struct ipc_ops msg_ops = {
85031+ .getnew = newque,
85032+ .associate = msg_security,
85033+ .more_checks = NULL
85034+};
85035+
85036 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85037 {
85038 struct ipc_namespace *ns;
85039- struct ipc_ops msg_ops;
85040 struct ipc_params msg_params;
85041
85042 ns = current->nsproxy->ipc_ns;
85043
85044- msg_ops.getnew = newque;
85045- msg_ops.associate = msg_security;
85046- msg_ops.more_checks = NULL;
85047-
85048 msg_params.key = key;
85049 msg_params.flg = msgflg;
85050
85051diff --git a/ipc/sem.c b/ipc/sem.c
85052index bee5554..e9af81dd 100644
85053--- a/ipc/sem.c
85054+++ b/ipc/sem.c
85055@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85056 return 0;
85057 }
85058
85059+static struct ipc_ops sem_ops = {
85060+ .getnew = newary,
85061+ .associate = sem_security,
85062+ .more_checks = sem_more_checks
85063+};
85064+
85065 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85066 {
85067 struct ipc_namespace *ns;
85068- struct ipc_ops sem_ops;
85069 struct ipc_params sem_params;
85070
85071 ns = current->nsproxy->ipc_ns;
85072@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85073 if (nsems < 0 || nsems > ns->sc_semmsl)
85074 return -EINVAL;
85075
85076- sem_ops.getnew = newary;
85077- sem_ops.associate = sem_security;
85078- sem_ops.more_checks = sem_more_checks;
85079-
85080 sem_params.key = key;
85081 sem_params.flg = semflg;
85082 sem_params.u.nsems = nsems;
85083diff --git a/ipc/shm.c b/ipc/shm.c
85084index 7645961..afc7f02 100644
85085--- a/ipc/shm.c
85086+++ b/ipc/shm.c
85087@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85088 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85089 #endif
85090
85091+#ifdef CONFIG_GRKERNSEC
85092+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85093+ const time_t shm_createtime, const kuid_t cuid,
85094+ const int shmid);
85095+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85096+ const time_t shm_createtime);
85097+#endif
85098+
85099 void shm_init_ns(struct ipc_namespace *ns)
85100 {
85101 ns->shm_ctlmax = SHMMAX;
85102@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85103 shp->shm_lprid = 0;
85104 shp->shm_atim = shp->shm_dtim = 0;
85105 shp->shm_ctim = get_seconds();
85106+#ifdef CONFIG_GRKERNSEC
85107+ {
85108+ struct timespec timeval;
85109+ do_posix_clock_monotonic_gettime(&timeval);
85110+
85111+ shp->shm_createtime = timeval.tv_sec;
85112+ }
85113+#endif
85114 shp->shm_segsz = size;
85115 shp->shm_nattch = 0;
85116 shp->shm_file = file;
85117@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85118 return 0;
85119 }
85120
85121+static struct ipc_ops shm_ops = {
85122+ .getnew = newseg,
85123+ .associate = shm_security,
85124+ .more_checks = shm_more_checks
85125+};
85126+
85127 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85128 {
85129 struct ipc_namespace *ns;
85130- struct ipc_ops shm_ops;
85131 struct ipc_params shm_params;
85132
85133 ns = current->nsproxy->ipc_ns;
85134
85135- shm_ops.getnew = newseg;
85136- shm_ops.associate = shm_security;
85137- shm_ops.more_checks = shm_more_checks;
85138-
85139 shm_params.key = key;
85140 shm_params.flg = shmflg;
85141 shm_params.u.size = size;
85142@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85143 f_mode = FMODE_READ | FMODE_WRITE;
85144 }
85145 if (shmflg & SHM_EXEC) {
85146+
85147+#ifdef CONFIG_PAX_MPROTECT
85148+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85149+ goto out;
85150+#endif
85151+
85152 prot |= PROT_EXEC;
85153 acc_mode |= S_IXUGO;
85154 }
85155@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85156 if (err)
85157 goto out_unlock;
85158
85159+#ifdef CONFIG_GRKERNSEC
85160+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85161+ shp->shm_perm.cuid, shmid) ||
85162+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85163+ err = -EACCES;
85164+ goto out_unlock;
85165+ }
85166+#endif
85167+
85168 ipc_lock_object(&shp->shm_perm);
85169
85170 /* check if shm_destroy() is tearing down shp */
85171@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85172 path = shp->shm_file->f_path;
85173 path_get(&path);
85174 shp->shm_nattch++;
85175+#ifdef CONFIG_GRKERNSEC
85176+ shp->shm_lapid = current->pid;
85177+#endif
85178 size = i_size_read(path.dentry->d_inode);
85179 ipc_unlock_object(&shp->shm_perm);
85180 rcu_read_unlock();
85181diff --git a/ipc/util.c b/ipc/util.c
85182index e1b4c6d..8174204 100644
85183--- a/ipc/util.c
85184+++ b/ipc/util.c
85185@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85186 int (*show)(struct seq_file *, void *);
85187 };
85188
85189+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85190+
85191 static void ipc_memory_notifier(struct work_struct *work)
85192 {
85193 ipcns_notify(IPCNS_MEMCHANGED);
85194@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85195 granted_mode >>= 6;
85196 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85197 granted_mode >>= 3;
85198+
85199+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85200+ return -1;
85201+
85202 /* is there some bit set in requested_mode but not in granted_mode? */
85203 if ((requested_mode & ~granted_mode & 0007) &&
85204 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85205diff --git a/kernel/acct.c b/kernel/acct.c
85206index 8d6e145..33e0b1e 100644
85207--- a/kernel/acct.c
85208+++ b/kernel/acct.c
85209@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85210 */
85211 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85212 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85213- file->f_op->write(file, (char *)&ac,
85214+ file->f_op->write(file, (char __force_user *)&ac,
85215 sizeof(acct_t), &file->f_pos);
85216 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85217 set_fs(fs);
85218diff --git a/kernel/audit.c b/kernel/audit.c
85219index 95a20f3..e1cb300 100644
85220--- a/kernel/audit.c
85221+++ b/kernel/audit.c
85222@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85223 3) suppressed due to audit_rate_limit
85224 4) suppressed due to audit_backlog_limit
85225 */
85226-static atomic_t audit_lost = ATOMIC_INIT(0);
85227+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85228
85229 /* The netlink socket. */
85230 static struct sock *audit_sock;
85231@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85232 unsigned long now;
85233 int print;
85234
85235- atomic_inc(&audit_lost);
85236+ atomic_inc_unchecked(&audit_lost);
85237
85238 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85239
85240@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85241 if (print) {
85242 if (printk_ratelimit())
85243 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85244- atomic_read(&audit_lost),
85245+ atomic_read_unchecked(&audit_lost),
85246 audit_rate_limit,
85247 audit_backlog_limit);
85248 audit_panic(message);
85249@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85250 s.pid = audit_pid;
85251 s.rate_limit = audit_rate_limit;
85252 s.backlog_limit = audit_backlog_limit;
85253- s.lost = atomic_read(&audit_lost);
85254+ s.lost = atomic_read_unchecked(&audit_lost);
85255 s.backlog = skb_queue_len(&audit_skb_queue);
85256 s.version = AUDIT_VERSION_LATEST;
85257 s.backlog_wait_time = audit_backlog_wait_time;
85258diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85259index 7aef2f4..db6ced2 100644
85260--- a/kernel/auditsc.c
85261+++ b/kernel/auditsc.c
85262@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85263 }
85264
85265 /* global counter which is incremented every time something logs in */
85266-static atomic_t session_id = ATOMIC_INIT(0);
85267+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85268
85269 static int audit_set_loginuid_perm(kuid_t loginuid)
85270 {
85271@@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85272
85273 /* are we setting or clearing? */
85274 if (uid_valid(loginuid))
85275- sessionid = (unsigned int)atomic_inc_return(&session_id);
85276+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85277
85278 task->sessionid = sessionid;
85279 task->loginuid = loginuid;
85280diff --git a/kernel/capability.c b/kernel/capability.c
85281index 34019c5..363f279 100644
85282--- a/kernel/capability.c
85283+++ b/kernel/capability.c
85284@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85285 * before modification is attempted and the application
85286 * fails.
85287 */
85288+ if (tocopy > ARRAY_SIZE(kdata))
85289+ return -EFAULT;
85290+
85291 if (copy_to_user(dataptr, kdata, tocopy
85292 * sizeof(struct __user_cap_data_struct))) {
85293 return -EFAULT;
85294@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85295 int ret;
85296
85297 rcu_read_lock();
85298- ret = security_capable(__task_cred(t), ns, cap);
85299+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85300+ gr_task_is_capable(t, __task_cred(t), cap);
85301 rcu_read_unlock();
85302
85303- return (ret == 0);
85304+ return ret;
85305 }
85306
85307 /**
85308@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85309 int ret;
85310
85311 rcu_read_lock();
85312- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85313+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85314 rcu_read_unlock();
85315
85316- return (ret == 0);
85317+ return ret;
85318 }
85319
85320 /**
85321@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85322 BUG();
85323 }
85324
85325- if (security_capable(current_cred(), ns, cap) == 0) {
85326+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85327 current->flags |= PF_SUPERPRIV;
85328 return true;
85329 }
85330@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85331 }
85332 EXPORT_SYMBOL(ns_capable);
85333
85334+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85335+{
85336+ if (unlikely(!cap_valid(cap))) {
85337+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85338+ BUG();
85339+ }
85340+
85341+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85342+ current->flags |= PF_SUPERPRIV;
85343+ return true;
85344+ }
85345+ return false;
85346+}
85347+EXPORT_SYMBOL(ns_capable_nolog);
85348+
85349 /**
85350 * file_ns_capable - Determine if the file's opener had a capability in effect
85351 * @file: The file we want to check
85352@@ -432,6 +451,12 @@ bool capable(int cap)
85353 }
85354 EXPORT_SYMBOL(capable);
85355
85356+bool capable_nolog(int cap)
85357+{
85358+ return ns_capable_nolog(&init_user_ns, cap);
85359+}
85360+EXPORT_SYMBOL(capable_nolog);
85361+
85362 /**
85363 * inode_capable - Check superior capability over inode
85364 * @inode: The inode in question
85365@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85366 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85367 }
85368 EXPORT_SYMBOL(inode_capable);
85369+
85370+bool inode_capable_nolog(const struct inode *inode, int cap)
85371+{
85372+ struct user_namespace *ns = current_user_ns();
85373+
85374+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85375+}
85376+EXPORT_SYMBOL(inode_capable_nolog);
85377diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85378index 0c753dd..dd7d3d6 100644
85379--- a/kernel/cgroup.c
85380+++ b/kernel/cgroup.c
85381@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85382 struct css_set *cset = link->cset;
85383 struct task_struct *task;
85384 int count = 0;
85385- seq_printf(seq, "css_set %p\n", cset);
85386+ seq_printf(seq, "css_set %pK\n", cset);
85387 list_for_each_entry(task, &cset->tasks, cg_list) {
85388 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85389 seq_puts(seq, " ...\n");
85390diff --git a/kernel/compat.c b/kernel/compat.c
85391index 0a09e48..b46b3d78 100644
85392--- a/kernel/compat.c
85393+++ b/kernel/compat.c
85394@@ -13,6 +13,7 @@
85395
85396 #include <linux/linkage.h>
85397 #include <linux/compat.h>
85398+#include <linux/module.h>
85399 #include <linux/errno.h>
85400 #include <linux/time.h>
85401 #include <linux/signal.h>
85402@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85403 mm_segment_t oldfs;
85404 long ret;
85405
85406- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85407+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85408 oldfs = get_fs();
85409 set_fs(KERNEL_DS);
85410 ret = hrtimer_nanosleep_restart(restart);
85411@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85412 oldfs = get_fs();
85413 set_fs(KERNEL_DS);
85414 ret = hrtimer_nanosleep(&tu,
85415- rmtp ? (struct timespec __user *)&rmt : NULL,
85416+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85417 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85418 set_fs(oldfs);
85419
85420@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85421 mm_segment_t old_fs = get_fs();
85422
85423 set_fs(KERNEL_DS);
85424- ret = sys_sigpending((old_sigset_t __user *) &s);
85425+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85426 set_fs(old_fs);
85427 if (ret == 0)
85428 ret = put_user(s, set);
85429@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85430 mm_segment_t old_fs = get_fs();
85431
85432 set_fs(KERNEL_DS);
85433- ret = sys_old_getrlimit(resource, &r);
85434+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85435 set_fs(old_fs);
85436
85437 if (!ret) {
85438@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85439 set_fs (KERNEL_DS);
85440 ret = sys_wait4(pid,
85441 (stat_addr ?
85442- (unsigned int __user *) &status : NULL),
85443- options, (struct rusage __user *) &r);
85444+ (unsigned int __force_user *) &status : NULL),
85445+ options, (struct rusage __force_user *) &r);
85446 set_fs (old_fs);
85447
85448 if (ret > 0) {
85449@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85450 memset(&info, 0, sizeof(info));
85451
85452 set_fs(KERNEL_DS);
85453- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85454- uru ? (struct rusage __user *)&ru : NULL);
85455+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85456+ uru ? (struct rusage __force_user *)&ru : NULL);
85457 set_fs(old_fs);
85458
85459 if ((ret < 0) || (info.si_signo == 0))
85460@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85461 oldfs = get_fs();
85462 set_fs(KERNEL_DS);
85463 err = sys_timer_settime(timer_id, flags,
85464- (struct itimerspec __user *) &newts,
85465- (struct itimerspec __user *) &oldts);
85466+ (struct itimerspec __force_user *) &newts,
85467+ (struct itimerspec __force_user *) &oldts);
85468 set_fs(oldfs);
85469 if (!err && old && put_compat_itimerspec(old, &oldts))
85470 return -EFAULT;
85471@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85472 oldfs = get_fs();
85473 set_fs(KERNEL_DS);
85474 err = sys_timer_gettime(timer_id,
85475- (struct itimerspec __user *) &ts);
85476+ (struct itimerspec __force_user *) &ts);
85477 set_fs(oldfs);
85478 if (!err && put_compat_itimerspec(setting, &ts))
85479 return -EFAULT;
85480@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85481 oldfs = get_fs();
85482 set_fs(KERNEL_DS);
85483 err = sys_clock_settime(which_clock,
85484- (struct timespec __user *) &ts);
85485+ (struct timespec __force_user *) &ts);
85486 set_fs(oldfs);
85487 return err;
85488 }
85489@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85490 oldfs = get_fs();
85491 set_fs(KERNEL_DS);
85492 err = sys_clock_gettime(which_clock,
85493- (struct timespec __user *) &ts);
85494+ (struct timespec __force_user *) &ts);
85495 set_fs(oldfs);
85496 if (!err && put_compat_timespec(&ts, tp))
85497 return -EFAULT;
85498@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85499
85500 oldfs = get_fs();
85501 set_fs(KERNEL_DS);
85502- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85503+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85504 set_fs(oldfs);
85505
85506 err = compat_put_timex(utp, &txc);
85507@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85508 oldfs = get_fs();
85509 set_fs(KERNEL_DS);
85510 err = sys_clock_getres(which_clock,
85511- (struct timespec __user *) &ts);
85512+ (struct timespec __force_user *) &ts);
85513 set_fs(oldfs);
85514 if (!err && tp && put_compat_timespec(&ts, tp))
85515 return -EFAULT;
85516@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85517 long err;
85518 mm_segment_t oldfs;
85519 struct timespec tu;
85520- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85521+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85522
85523- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85524+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85525 oldfs = get_fs();
85526 set_fs(KERNEL_DS);
85527 err = clock_nanosleep_restart(restart);
85528@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85529 oldfs = get_fs();
85530 set_fs(KERNEL_DS);
85531 err = sys_clock_nanosleep(which_clock, flags,
85532- (struct timespec __user *) &in,
85533- (struct timespec __user *) &out);
85534+ (struct timespec __force_user *) &in,
85535+ (struct timespec __force_user *) &out);
85536 set_fs(oldfs);
85537
85538 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85539@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85540 mm_segment_t old_fs = get_fs();
85541
85542 set_fs(KERNEL_DS);
85543- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85544+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85545 set_fs(old_fs);
85546 if (put_compat_timespec(&t, interval))
85547 return -EFAULT;
85548diff --git a/kernel/configs.c b/kernel/configs.c
85549index c18b1f1..b9a0132 100644
85550--- a/kernel/configs.c
85551+++ b/kernel/configs.c
85552@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85553 struct proc_dir_entry *entry;
85554
85555 /* create the current config file */
85556+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85557+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85558+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85559+ &ikconfig_file_ops);
85560+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85561+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85562+ &ikconfig_file_ops);
85563+#endif
85564+#else
85565 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85566 &ikconfig_file_ops);
85567+#endif
85568+
85569 if (!entry)
85570 return -ENOMEM;
85571
85572diff --git a/kernel/cred.c b/kernel/cred.c
85573index e0573a4..3874e41 100644
85574--- a/kernel/cred.c
85575+++ b/kernel/cred.c
85576@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85577 validate_creds(cred);
85578 alter_cred_subscribers(cred, -1);
85579 put_cred(cred);
85580+
85581+#ifdef CONFIG_GRKERNSEC_SETXID
85582+ cred = (struct cred *) tsk->delayed_cred;
85583+ if (cred != NULL) {
85584+ tsk->delayed_cred = NULL;
85585+ validate_creds(cred);
85586+ alter_cred_subscribers(cred, -1);
85587+ put_cred(cred);
85588+ }
85589+#endif
85590 }
85591
85592 /**
85593@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85594 * Always returns 0 thus allowing this function to be tail-called at the end
85595 * of, say, sys_setgid().
85596 */
85597-int commit_creds(struct cred *new)
85598+static int __commit_creds(struct cred *new)
85599 {
85600 struct task_struct *task = current;
85601 const struct cred *old = task->real_cred;
85602@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85603
85604 get_cred(new); /* we will require a ref for the subj creds too */
85605
85606+ gr_set_role_label(task, new->uid, new->gid);
85607+
85608 /* dumpability changes */
85609 if (!uid_eq(old->euid, new->euid) ||
85610 !gid_eq(old->egid, new->egid) ||
85611@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85612 put_cred(old);
85613 return 0;
85614 }
85615+#ifdef CONFIG_GRKERNSEC_SETXID
85616+extern int set_user(struct cred *new);
85617+
85618+void gr_delayed_cred_worker(void)
85619+{
85620+ const struct cred *new = current->delayed_cred;
85621+ struct cred *ncred;
85622+
85623+ current->delayed_cred = NULL;
85624+
85625+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85626+ // from doing get_cred on it when queueing this
85627+ put_cred(new);
85628+ return;
85629+ } else if (new == NULL)
85630+ return;
85631+
85632+ ncred = prepare_creds();
85633+ if (!ncred)
85634+ goto die;
85635+ // uids
85636+ ncred->uid = new->uid;
85637+ ncred->euid = new->euid;
85638+ ncred->suid = new->suid;
85639+ ncred->fsuid = new->fsuid;
85640+ // gids
85641+ ncred->gid = new->gid;
85642+ ncred->egid = new->egid;
85643+ ncred->sgid = new->sgid;
85644+ ncred->fsgid = new->fsgid;
85645+ // groups
85646+ if (set_groups(ncred, new->group_info) < 0) {
85647+ abort_creds(ncred);
85648+ goto die;
85649+ }
85650+ // caps
85651+ ncred->securebits = new->securebits;
85652+ ncred->cap_inheritable = new->cap_inheritable;
85653+ ncred->cap_permitted = new->cap_permitted;
85654+ ncred->cap_effective = new->cap_effective;
85655+ ncred->cap_bset = new->cap_bset;
85656+
85657+ if (set_user(ncred)) {
85658+ abort_creds(ncred);
85659+ goto die;
85660+ }
85661+
85662+ // from doing get_cred on it when queueing this
85663+ put_cred(new);
85664+
85665+ __commit_creds(ncred);
85666+ return;
85667+die:
85668+ // from doing get_cred on it when queueing this
85669+ put_cred(new);
85670+ do_group_exit(SIGKILL);
85671+}
85672+#endif
85673+
85674+int commit_creds(struct cred *new)
85675+{
85676+#ifdef CONFIG_GRKERNSEC_SETXID
85677+ int ret;
85678+ int schedule_it = 0;
85679+ struct task_struct *t;
85680+
85681+ /* we won't get called with tasklist_lock held for writing
85682+ and interrupts disabled as the cred struct in that case is
85683+ init_cred
85684+ */
85685+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85686+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85687+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85688+ schedule_it = 1;
85689+ }
85690+ ret = __commit_creds(new);
85691+ if (schedule_it) {
85692+ rcu_read_lock();
85693+ read_lock(&tasklist_lock);
85694+ for (t = next_thread(current); t != current;
85695+ t = next_thread(t)) {
85696+ if (t->delayed_cred == NULL) {
85697+ t->delayed_cred = get_cred(new);
85698+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85699+ set_tsk_need_resched(t);
85700+ }
85701+ }
85702+ read_unlock(&tasklist_lock);
85703+ rcu_read_unlock();
85704+ }
85705+ return ret;
85706+#else
85707+ return __commit_creds(new);
85708+#endif
85709+}
85710+
85711 EXPORT_SYMBOL(commit_creds);
85712
85713 /**
85714diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85715index 334b398..9145fb1 100644
85716--- a/kernel/debug/debug_core.c
85717+++ b/kernel/debug/debug_core.c
85718@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85719 */
85720 static atomic_t masters_in_kgdb;
85721 static atomic_t slaves_in_kgdb;
85722-static atomic_t kgdb_break_tasklet_var;
85723+static atomic_unchecked_t kgdb_break_tasklet_var;
85724 atomic_t kgdb_setting_breakpoint;
85725
85726 struct task_struct *kgdb_usethread;
85727@@ -133,7 +133,7 @@ int kgdb_single_step;
85728 static pid_t kgdb_sstep_pid;
85729
85730 /* to keep track of the CPU which is doing the single stepping*/
85731-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85732+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85733
85734 /*
85735 * If you are debugging a problem where roundup (the collection of
85736@@ -541,7 +541,7 @@ return_normal:
85737 * kernel will only try for the value of sstep_tries before
85738 * giving up and continuing on.
85739 */
85740- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85741+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85742 (kgdb_info[cpu].task &&
85743 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85744 atomic_set(&kgdb_active, -1);
85745@@ -639,8 +639,8 @@ cpu_master_loop:
85746 }
85747
85748 kgdb_restore:
85749- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85750- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85751+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85752+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85753 if (kgdb_info[sstep_cpu].task)
85754 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85755 else
85756@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
85757 static void kgdb_tasklet_bpt(unsigned long ing)
85758 {
85759 kgdb_breakpoint();
85760- atomic_set(&kgdb_break_tasklet_var, 0);
85761+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85762 }
85763
85764 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85765
85766 void kgdb_schedule_breakpoint(void)
85767 {
85768- if (atomic_read(&kgdb_break_tasklet_var) ||
85769+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85770 atomic_read(&kgdb_active) != -1 ||
85771 atomic_read(&kgdb_setting_breakpoint))
85772 return;
85773- atomic_inc(&kgdb_break_tasklet_var);
85774+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85775 tasklet_schedule(&kgdb_tasklet_breakpoint);
85776 }
85777 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85778diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85779index 0b097c8..11dd5c5 100644
85780--- a/kernel/debug/kdb/kdb_main.c
85781+++ b/kernel/debug/kdb/kdb_main.c
85782@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85783 continue;
85784
85785 kdb_printf("%-20s%8u 0x%p ", mod->name,
85786- mod->core_size, (void *)mod);
85787+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85788 #ifdef CONFIG_MODULE_UNLOAD
85789 kdb_printf("%4ld ", module_refcount(mod));
85790 #endif
85791@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85792 kdb_printf(" (Loading)");
85793 else
85794 kdb_printf(" (Live)");
85795- kdb_printf(" 0x%p", mod->module_core);
85796+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85797
85798 #ifdef CONFIG_MODULE_UNLOAD
85799 {
85800diff --git a/kernel/events/core.c b/kernel/events/core.c
85801index fa0b2d4..67a1c7a 100644
85802--- a/kernel/events/core.c
85803+++ b/kernel/events/core.c
85804@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85805 * 0 - disallow raw tracepoint access for unpriv
85806 * 1 - disallow cpu events for unpriv
85807 * 2 - disallow kernel profiling for unpriv
85808+ * 3 - disallow all unpriv perf event use
85809 */
85810-int sysctl_perf_event_paranoid __read_mostly = 1;
85811+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85812+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85813+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85814+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85815+#else
85816+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85817+#endif
85818
85819 /* Minimum for 512 kiB + 1 user control page */
85820 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85821@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85822
85823 tmp *= sysctl_perf_cpu_time_max_percent;
85824 do_div(tmp, 100);
85825- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85826+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85827 }
85828
85829 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85830@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85831 update_perf_cpu_limits();
85832 }
85833
85834-static atomic64_t perf_event_id;
85835+static atomic64_unchecked_t perf_event_id;
85836
85837 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85838 enum event_type_t event_type);
85839@@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
85840
85841 static inline u64 perf_event_count(struct perf_event *event)
85842 {
85843- return local64_read(&event->count) + atomic64_read(&event->child_count);
85844+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85845 }
85846
85847 static u64 perf_event_read(struct perf_event *event)
85848@@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85849 mutex_lock(&event->child_mutex);
85850 total += perf_event_read(event);
85851 *enabled += event->total_time_enabled +
85852- atomic64_read(&event->child_total_time_enabled);
85853+ atomic64_read_unchecked(&event->child_total_time_enabled);
85854 *running += event->total_time_running +
85855- atomic64_read(&event->child_total_time_running);
85856+ atomic64_read_unchecked(&event->child_total_time_running);
85857
85858 list_for_each_entry(child, &event->child_list, child_list) {
85859 total += perf_event_read(child);
85860@@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
85861 userpg->offset -= local64_read(&event->hw.prev_count);
85862
85863 userpg->time_enabled = enabled +
85864- atomic64_read(&event->child_total_time_enabled);
85865+ atomic64_read_unchecked(&event->child_total_time_enabled);
85866
85867 userpg->time_running = running +
85868- atomic64_read(&event->child_total_time_running);
85869+ atomic64_read_unchecked(&event->child_total_time_running);
85870
85871 arch_perf_update_userpage(userpg, now);
85872
85873@@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85874
85875 /* Data. */
85876 sp = perf_user_stack_pointer(regs);
85877- rem = __output_copy_user(handle, (void *) sp, dump_size);
85878+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85879 dyn_size = dump_size - rem;
85880
85881 perf_output_skip(handle, rem);
85882@@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85883 values[n++] = perf_event_count(event);
85884 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85885 values[n++] = enabled +
85886- atomic64_read(&event->child_total_time_enabled);
85887+ atomic64_read_unchecked(&event->child_total_time_enabled);
85888 }
85889 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85890 values[n++] = running +
85891- atomic64_read(&event->child_total_time_running);
85892+ atomic64_read_unchecked(&event->child_total_time_running);
85893 }
85894 if (read_format & PERF_FORMAT_ID)
85895 values[n++] = primary_event_id(event);
85896@@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85897 event->parent = parent_event;
85898
85899 event->ns = get_pid_ns(task_active_pid_ns(current));
85900- event->id = atomic64_inc_return(&perf_event_id);
85901+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
85902
85903 event->state = PERF_EVENT_STATE_INACTIVE;
85904
85905@@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
85906 if (flags & ~PERF_FLAG_ALL)
85907 return -EINVAL;
85908
85909+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85910+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85911+ return -EACCES;
85912+#endif
85913+
85914 err = perf_copy_attr(attr_uptr, &attr);
85915 if (err)
85916 return err;
85917@@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
85918 /*
85919 * Add back the child's count to the parent's count:
85920 */
85921- atomic64_add(child_val, &parent_event->child_count);
85922- atomic64_add(child_event->total_time_enabled,
85923+ atomic64_add_unchecked(child_val, &parent_event->child_count);
85924+ atomic64_add_unchecked(child_event->total_time_enabled,
85925 &parent_event->child_total_time_enabled);
85926- atomic64_add(child_event->total_time_running,
85927+ atomic64_add_unchecked(child_event->total_time_running,
85928 &parent_event->child_total_time_running);
85929
85930 /*
85931diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85932index 569b2187..19940d9 100644
85933--- a/kernel/events/internal.h
85934+++ b/kernel/events/internal.h
85935@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85936 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85937 }
85938
85939-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85940+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85941 static inline unsigned long \
85942 func_name(struct perf_output_handle *handle, \
85943- const void *buf, unsigned long len) \
85944+ const void user *buf, unsigned long len) \
85945 { \
85946 unsigned long size, written; \
85947 \
85948@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85949 return 0;
85950 }
85951
85952-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85953+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85954
85955 static inline unsigned long
85956 memcpy_skip(void *dst, const void *src, unsigned long n)
85957@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85958 return 0;
85959 }
85960
85961-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85962+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85963
85964 #ifndef arch_perf_out_copy_user
85965 #define arch_perf_out_copy_user arch_perf_out_copy_user
85966@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85967 }
85968 #endif
85969
85970-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85971+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85972
85973 /* Callchain handling */
85974 extern struct perf_callchain_entry *
85975diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85976index 307d87c..6466cbe 100644
85977--- a/kernel/events/uprobes.c
85978+++ b/kernel/events/uprobes.c
85979@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85980 {
85981 struct page *page;
85982 uprobe_opcode_t opcode;
85983- int result;
85984+ long result;
85985
85986 pagefault_disable();
85987 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85988diff --git a/kernel/exit.c b/kernel/exit.c
85989index 81b3d67..ef189a4 100644
85990--- a/kernel/exit.c
85991+++ b/kernel/exit.c
85992@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
85993 struct task_struct *leader;
85994 int zap_leader;
85995 repeat:
85996+#ifdef CONFIG_NET
85997+ gr_del_task_from_ip_table(p);
85998+#endif
85999+
86000 /* don't need to get the RCU readlock here - the process is dead and
86001 * can't be modifying its own credentials. But shut RCU-lockdep up */
86002 rcu_read_lock();
86003@@ -330,7 +334,7 @@ int allow_signal(int sig)
86004 * know it'll be handled, so that they don't get converted to
86005 * SIGKILL or just silently dropped.
86006 */
86007- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86008+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86009 recalc_sigpending();
86010 spin_unlock_irq(&current->sighand->siglock);
86011 return 0;
86012@@ -706,6 +710,8 @@ void do_exit(long code)
86013 struct task_struct *tsk = current;
86014 int group_dead;
86015
86016+ set_fs(USER_DS);
86017+
86018 profile_task_exit(tsk);
86019
86020 WARN_ON(blk_needs_flush_plug(tsk));
86021@@ -722,7 +728,6 @@ void do_exit(long code)
86022 * mm_release()->clear_child_tid() from writing to a user-controlled
86023 * kernel address.
86024 */
86025- set_fs(USER_DS);
86026
86027 ptrace_event(PTRACE_EVENT_EXIT, code);
86028
86029@@ -781,6 +786,9 @@ void do_exit(long code)
86030 tsk->exit_code = code;
86031 taskstats_exit(tsk, group_dead);
86032
86033+ gr_acl_handle_psacct(tsk, code);
86034+ gr_acl_handle_exit();
86035+
86036 exit_mm(tsk);
86037
86038 if (group_dead)
86039@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86040 * Take down every thread in the group. This is called by fatal signals
86041 * as well as by sys_exit_group (below).
86042 */
86043-void
86044+__noreturn void
86045 do_group_exit(int exit_code)
86046 {
86047 struct signal_struct *sig = current->signal;
86048diff --git a/kernel/fork.c b/kernel/fork.c
86049index a17621c..b77fef8 100644
86050--- a/kernel/fork.c
86051+++ b/kernel/fork.c
86052@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86053 *stackend = STACK_END_MAGIC; /* for overflow detection */
86054
86055 #ifdef CONFIG_CC_STACKPROTECTOR
86056- tsk->stack_canary = get_random_int();
86057+ tsk->stack_canary = pax_get_random_long();
86058 #endif
86059
86060 /*
86061@@ -345,12 +345,80 @@ free_tsk:
86062 }
86063
86064 #ifdef CONFIG_MMU
86065-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86066+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86067+{
86068+ struct vm_area_struct *tmp;
86069+ unsigned long charge;
86070+ struct file *file;
86071+ int retval;
86072+
86073+ charge = 0;
86074+ if (mpnt->vm_flags & VM_ACCOUNT) {
86075+ unsigned long len = vma_pages(mpnt);
86076+
86077+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86078+ goto fail_nomem;
86079+ charge = len;
86080+ }
86081+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86082+ if (!tmp)
86083+ goto fail_nomem;
86084+ *tmp = *mpnt;
86085+ tmp->vm_mm = mm;
86086+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86087+ retval = vma_dup_policy(mpnt, tmp);
86088+ if (retval)
86089+ goto fail_nomem_policy;
86090+ if (anon_vma_fork(tmp, mpnt))
86091+ goto fail_nomem_anon_vma_fork;
86092+ tmp->vm_flags &= ~VM_LOCKED;
86093+ tmp->vm_next = tmp->vm_prev = NULL;
86094+ tmp->vm_mirror = NULL;
86095+ file = tmp->vm_file;
86096+ if (file) {
86097+ struct inode *inode = file_inode(file);
86098+ struct address_space *mapping = file->f_mapping;
86099+
86100+ get_file(file);
86101+ if (tmp->vm_flags & VM_DENYWRITE)
86102+ atomic_dec(&inode->i_writecount);
86103+ mutex_lock(&mapping->i_mmap_mutex);
86104+ if (tmp->vm_flags & VM_SHARED)
86105+ mapping->i_mmap_writable++;
86106+ flush_dcache_mmap_lock(mapping);
86107+ /* insert tmp into the share list, just after mpnt */
86108+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86109+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86110+ else
86111+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86112+ flush_dcache_mmap_unlock(mapping);
86113+ mutex_unlock(&mapping->i_mmap_mutex);
86114+ }
86115+
86116+ /*
86117+ * Clear hugetlb-related page reserves for children. This only
86118+ * affects MAP_PRIVATE mappings. Faults generated by the child
86119+ * are not guaranteed to succeed, even if read-only
86120+ */
86121+ if (is_vm_hugetlb_page(tmp))
86122+ reset_vma_resv_huge_pages(tmp);
86123+
86124+ return tmp;
86125+
86126+fail_nomem_anon_vma_fork:
86127+ mpol_put(vma_policy(tmp));
86128+fail_nomem_policy:
86129+ kmem_cache_free(vm_area_cachep, tmp);
86130+fail_nomem:
86131+ vm_unacct_memory(charge);
86132+ return NULL;
86133+}
86134+
86135+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86136 {
86137 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86138 struct rb_node **rb_link, *rb_parent;
86139 int retval;
86140- unsigned long charge;
86141
86142 uprobe_start_dup_mmap();
86143 down_write(&oldmm->mmap_sem);
86144@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86145
86146 prev = NULL;
86147 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86148- struct file *file;
86149-
86150 if (mpnt->vm_flags & VM_DONTCOPY) {
86151 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86152 -vma_pages(mpnt));
86153 continue;
86154 }
86155- charge = 0;
86156- if (mpnt->vm_flags & VM_ACCOUNT) {
86157- unsigned long len = vma_pages(mpnt);
86158-
86159- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86160- goto fail_nomem;
86161- charge = len;
86162- }
86163- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86164- if (!tmp)
86165- goto fail_nomem;
86166- *tmp = *mpnt;
86167- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86168- retval = vma_dup_policy(mpnt, tmp);
86169- if (retval)
86170- goto fail_nomem_policy;
86171- tmp->vm_mm = mm;
86172- if (anon_vma_fork(tmp, mpnt))
86173- goto fail_nomem_anon_vma_fork;
86174- tmp->vm_flags &= ~VM_LOCKED;
86175- tmp->vm_next = tmp->vm_prev = NULL;
86176- file = tmp->vm_file;
86177- if (file) {
86178- struct inode *inode = file_inode(file);
86179- struct address_space *mapping = file->f_mapping;
86180-
86181- get_file(file);
86182- if (tmp->vm_flags & VM_DENYWRITE)
86183- atomic_dec(&inode->i_writecount);
86184- mutex_lock(&mapping->i_mmap_mutex);
86185- if (tmp->vm_flags & VM_SHARED)
86186- mapping->i_mmap_writable++;
86187- flush_dcache_mmap_lock(mapping);
86188- /* insert tmp into the share list, just after mpnt */
86189- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86190- vma_nonlinear_insert(tmp,
86191- &mapping->i_mmap_nonlinear);
86192- else
86193- vma_interval_tree_insert_after(tmp, mpnt,
86194- &mapping->i_mmap);
86195- flush_dcache_mmap_unlock(mapping);
86196- mutex_unlock(&mapping->i_mmap_mutex);
86197+ tmp = dup_vma(mm, oldmm, mpnt);
86198+ if (!tmp) {
86199+ retval = -ENOMEM;
86200+ goto out;
86201 }
86202
86203 /*
86204@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86205 if (retval)
86206 goto out;
86207 }
86208+
86209+#ifdef CONFIG_PAX_SEGMEXEC
86210+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86211+ struct vm_area_struct *mpnt_m;
86212+
86213+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86214+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86215+
86216+ if (!mpnt->vm_mirror)
86217+ continue;
86218+
86219+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86220+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86221+ mpnt->vm_mirror = mpnt_m;
86222+ } else {
86223+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86224+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86225+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86226+ mpnt->vm_mirror->vm_mirror = mpnt;
86227+ }
86228+ }
86229+ BUG_ON(mpnt_m);
86230+ }
86231+#endif
86232+
86233 /* a new mm has just been created */
86234 arch_dup_mmap(oldmm, mm);
86235 retval = 0;
86236@@ -468,14 +521,6 @@ out:
86237 up_write(&oldmm->mmap_sem);
86238 uprobe_end_dup_mmap();
86239 return retval;
86240-fail_nomem_anon_vma_fork:
86241- mpol_put(vma_policy(tmp));
86242-fail_nomem_policy:
86243- kmem_cache_free(vm_area_cachep, tmp);
86244-fail_nomem:
86245- retval = -ENOMEM;
86246- vm_unacct_memory(charge);
86247- goto out;
86248 }
86249
86250 static inline int mm_alloc_pgd(struct mm_struct *mm)
86251@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86252 return ERR_PTR(err);
86253
86254 mm = get_task_mm(task);
86255- if (mm && mm != current->mm &&
86256- !ptrace_may_access(task, mode)) {
86257+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86258+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86259 mmput(mm);
86260 mm = ERR_PTR(-EACCES);
86261 }
86262@@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86263 spin_unlock(&fs->lock);
86264 return -EAGAIN;
86265 }
86266- fs->users++;
86267+ atomic_inc(&fs->users);
86268 spin_unlock(&fs->lock);
86269 return 0;
86270 }
86271 tsk->fs = copy_fs_struct(fs);
86272 if (!tsk->fs)
86273 return -ENOMEM;
86274+ /* Carry through gr_chroot_dentry and is_chrooted instead
86275+ of recomputing it here. Already copied when the task struct
86276+ is duplicated. This allows pivot_root to not be treated as
86277+ a chroot
86278+ */
86279+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86280+
86281 return 0;
86282 }
86283
86284@@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86285 * parts of the process environment (as per the clone
86286 * flags). The actual kick-off is left to the caller.
86287 */
86288-static struct task_struct *copy_process(unsigned long clone_flags,
86289+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86290 unsigned long stack_start,
86291 unsigned long stack_size,
86292 int __user *child_tidptr,
86293@@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86294 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86295 #endif
86296 retval = -EAGAIN;
86297+
86298+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86299+
86300 if (atomic_read(&p->real_cred->user->processes) >=
86301 task_rlimit(p, RLIMIT_NPROC)) {
86302 if (p->real_cred->user != INIT_USER &&
86303@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86304 goto bad_fork_free_pid;
86305 }
86306
86307+ /* synchronizes with gr_set_acls()
86308+ we need to call this past the point of no return for fork()
86309+ */
86310+ gr_copy_label(p);
86311+
86312 if (likely(p->pid)) {
86313 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86314
86315@@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
86316 bad_fork_free:
86317 free_task(p);
86318 fork_out:
86319+ gr_log_forkfail(retval);
86320+
86321 return ERR_PTR(retval);
86322 }
86323
86324@@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
86325
86326 p = copy_process(clone_flags, stack_start, stack_size,
86327 child_tidptr, NULL, trace);
86328+ add_latent_entropy();
86329 /*
86330 * Do this prior waking up the new thread - the thread pointer
86331 * might get invalid after that point, if the thread exits quickly.
86332@@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
86333 if (clone_flags & CLONE_PARENT_SETTID)
86334 put_user(nr, parent_tidptr);
86335
86336+ gr_handle_brute_check();
86337+
86338 if (clone_flags & CLONE_VFORK) {
86339 p->vfork_done = &vfork;
86340 init_completion(&vfork);
86341@@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
86342 mm_cachep = kmem_cache_create("mm_struct",
86343 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86344 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86345- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86346+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86347 mmap_init();
86348 nsproxy_cache_init();
86349 }
86350@@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86351 return 0;
86352
86353 /* don't need lock here; in the worst case we'll do useless copy */
86354- if (fs->users == 1)
86355+ if (atomic_read(&fs->users) == 1)
86356 return 0;
86357
86358 *new_fsp = copy_fs_struct(fs);
86359@@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86360 fs = current->fs;
86361 spin_lock(&fs->lock);
86362 current->fs = new_fs;
86363- if (--fs->users)
86364+ gr_set_chroot_entries(current, &current->fs->root);
86365+ if (atomic_dec_return(&fs->users))
86366 new_fs = NULL;
86367 else
86368 new_fs = fs;
86369diff --git a/kernel/futex.c b/kernel/futex.c
86370index 6801b37..bb6becca 100644
86371--- a/kernel/futex.c
86372+++ b/kernel/futex.c
86373@@ -54,6 +54,7 @@
86374 #include <linux/mount.h>
86375 #include <linux/pagemap.h>
86376 #include <linux/syscalls.h>
86377+#include <linux/ptrace.h>
86378 #include <linux/signal.h>
86379 #include <linux/export.h>
86380 #include <linux/magic.h>
86381@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86382 struct page *page, *page_head;
86383 int err, ro = 0;
86384
86385+#ifdef CONFIG_PAX_SEGMEXEC
86386+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86387+ return -EFAULT;
86388+#endif
86389+
86390 /*
86391 * The futex address must be "naturally" aligned.
86392 */
86393@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86394
86395 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86396 {
86397- int ret;
86398+ unsigned long ret;
86399
86400 pagefault_disable();
86401 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86402@@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86403 {
86404 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86405 u32 curval;
86406+ mm_segment_t oldfs;
86407
86408 /*
86409 * This will fail and we want it. Some arch implementations do
86410@@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86411 * implementation, the non-functional ones will return
86412 * -ENOSYS.
86413 */
86414+ oldfs = get_fs();
86415+ set_fs(USER_DS);
86416 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86417 futex_cmpxchg_enabled = 1;
86418+ set_fs(oldfs);
86419 #endif
86420 }
86421
86422diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86423index f9f44fd..29885e4 100644
86424--- a/kernel/futex_compat.c
86425+++ b/kernel/futex_compat.c
86426@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86427 return 0;
86428 }
86429
86430-static void __user *futex_uaddr(struct robust_list __user *entry,
86431+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86432 compat_long_t futex_offset)
86433 {
86434 compat_uptr_t base = ptr_to_compat(entry);
86435diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86436index f45b75b..bfac6d5 100644
86437--- a/kernel/gcov/base.c
86438+++ b/kernel/gcov/base.c
86439@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86440 }
86441
86442 #ifdef CONFIG_MODULES
86443-static inline int within(void *addr, void *start, unsigned long size)
86444-{
86445- return ((addr >= start) && (addr < start + size));
86446-}
86447-
86448 /* Update list and generate events when modules are unloaded. */
86449 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86450 void *data)
86451@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86452
86453 /* Remove entries located in module from linked list. */
86454 while ((info = gcov_info_next(info))) {
86455- if (within(info, mod->module_core, mod->core_size)) {
86456+ if (within_module_core_rw((unsigned long)info, mod)) {
86457 gcov_info_unlink(prev, info);
86458 if (gcov_events_enabled)
86459 gcov_event(GCOV_REMOVE, info);
86460diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86461index 0909436..6037d22 100644
86462--- a/kernel/hrtimer.c
86463+++ b/kernel/hrtimer.c
86464@@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86465 local_irq_restore(flags);
86466 }
86467
86468-static void run_hrtimer_softirq(struct softirq_action *h)
86469+static __latent_entropy void run_hrtimer_softirq(void)
86470 {
86471 hrtimer_peek_ahead_timers();
86472 }
86473diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86474index 55fcce6..0e4cf34 100644
86475--- a/kernel/irq_work.c
86476+++ b/kernel/irq_work.c
86477@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86478 return NOTIFY_OK;
86479 }
86480
86481-static struct notifier_block cpu_notify;
86482+static struct notifier_block cpu_notify = {
86483+ .notifier_call = irq_work_cpu_notify,
86484+ .priority = 0,
86485+};
86486
86487 static __init int irq_work_init_cpu_notifier(void)
86488 {
86489- cpu_notify.notifier_call = irq_work_cpu_notify;
86490- cpu_notify.priority = 0;
86491 register_cpu_notifier(&cpu_notify);
86492 return 0;
86493 }
86494diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86495index 9019f15..9a3c42e 100644
86496--- a/kernel/jump_label.c
86497+++ b/kernel/jump_label.c
86498@@ -14,6 +14,7 @@
86499 #include <linux/err.h>
86500 #include <linux/static_key.h>
86501 #include <linux/jump_label_ratelimit.h>
86502+#include <linux/mm.h>
86503
86504 #ifdef HAVE_JUMP_LABEL
86505
86506@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86507
86508 size = (((unsigned long)stop - (unsigned long)start)
86509 / sizeof(struct jump_entry));
86510+ pax_open_kernel();
86511 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86512+ pax_close_kernel();
86513 }
86514
86515 static void jump_label_update(struct static_key *key, int enable);
86516@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86517 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86518 struct jump_entry *iter;
86519
86520+ pax_open_kernel();
86521 for (iter = iter_start; iter < iter_stop; iter++) {
86522 if (within_module_init(iter->code, mod))
86523 iter->code = 0;
86524 }
86525+ pax_close_kernel();
86526 }
86527
86528 static int
86529diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86530index 3127ad5..159d880 100644
86531--- a/kernel/kallsyms.c
86532+++ b/kernel/kallsyms.c
86533@@ -11,6 +11,9 @@
86534 * Changed the compression method from stem compression to "table lookup"
86535 * compression (see scripts/kallsyms.c for a more complete description)
86536 */
86537+#ifdef CONFIG_GRKERNSEC_HIDESYM
86538+#define __INCLUDED_BY_HIDESYM 1
86539+#endif
86540 #include <linux/kallsyms.h>
86541 #include <linux/module.h>
86542 #include <linux/init.h>
86543@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86544
86545 static inline int is_kernel_inittext(unsigned long addr)
86546 {
86547+ if (system_state != SYSTEM_BOOTING)
86548+ return 0;
86549+
86550 if (addr >= (unsigned long)_sinittext
86551 && addr <= (unsigned long)_einittext)
86552 return 1;
86553 return 0;
86554 }
86555
86556+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86557+#ifdef CONFIG_MODULES
86558+static inline int is_module_text(unsigned long addr)
86559+{
86560+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86561+ return 1;
86562+
86563+ addr = ktla_ktva(addr);
86564+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86565+}
86566+#else
86567+static inline int is_module_text(unsigned long addr)
86568+{
86569+ return 0;
86570+}
86571+#endif
86572+#endif
86573+
86574 static inline int is_kernel_text(unsigned long addr)
86575 {
86576 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86577@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86578
86579 static inline int is_kernel(unsigned long addr)
86580 {
86581+
86582+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86583+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86584+ return 1;
86585+
86586+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86587+#else
86588 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86589+#endif
86590+
86591 return 1;
86592 return in_gate_area_no_mm(addr);
86593 }
86594
86595 static int is_ksym_addr(unsigned long addr)
86596 {
86597+
86598+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86599+ if (is_module_text(addr))
86600+ return 0;
86601+#endif
86602+
86603 if (all_var)
86604 return is_kernel(addr);
86605
86606@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86607
86608 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86609 {
86610- iter->name[0] = '\0';
86611 iter->nameoff = get_symbol_offset(new_pos);
86612 iter->pos = new_pos;
86613 }
86614@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86615 {
86616 struct kallsym_iter *iter = m->private;
86617
86618+#ifdef CONFIG_GRKERNSEC_HIDESYM
86619+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86620+ return 0;
86621+#endif
86622+
86623 /* Some debugging symbols have no name. Ignore them. */
86624 if (!iter->name[0])
86625 return 0;
86626@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86627 */
86628 type = iter->exported ? toupper(iter->type) :
86629 tolower(iter->type);
86630+
86631 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86632 type, iter->name, iter->module_name);
86633 } else
86634@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86635 struct kallsym_iter *iter;
86636 int ret;
86637
86638- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86639+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86640 if (!iter)
86641 return -ENOMEM;
86642 reset_iter(iter, 0);
86643diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86644index e30ac0f..3528cac 100644
86645--- a/kernel/kcmp.c
86646+++ b/kernel/kcmp.c
86647@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86648 struct task_struct *task1, *task2;
86649 int ret;
86650
86651+#ifdef CONFIG_GRKERNSEC
86652+ return -ENOSYS;
86653+#endif
86654+
86655 rcu_read_lock();
86656
86657 /*
86658diff --git a/kernel/kexec.c b/kernel/kexec.c
86659index 60bafbe..a120f4f 100644
86660--- a/kernel/kexec.c
86661+++ b/kernel/kexec.c
86662@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86663 unsigned long flags)
86664 {
86665 struct compat_kexec_segment in;
86666- struct kexec_segment out, __user *ksegments;
86667+ struct kexec_segment out;
86668+ struct kexec_segment __user *ksegments;
86669 unsigned long i, result;
86670
86671 /* Don't allow clients that don't understand the native
86672diff --git a/kernel/kmod.c b/kernel/kmod.c
86673index 6b375af..eaff670 100644
86674--- a/kernel/kmod.c
86675+++ b/kernel/kmod.c
86676@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86677 kfree(info->argv);
86678 }
86679
86680-static int call_modprobe(char *module_name, int wait)
86681+static int call_modprobe(char *module_name, char *module_param, int wait)
86682 {
86683 struct subprocess_info *info;
86684 static char *envp[] = {
86685@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86686 NULL
86687 };
86688
86689- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86690+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86691 if (!argv)
86692 goto out;
86693
86694@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86695 argv[1] = "-q";
86696 argv[2] = "--";
86697 argv[3] = module_name; /* check free_modprobe_argv() */
86698- argv[4] = NULL;
86699+ argv[4] = module_param;
86700+ argv[5] = NULL;
86701
86702 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86703 NULL, free_modprobe_argv, NULL);
86704@@ -129,9 +130,8 @@ out:
86705 * If module auto-loading support is disabled then this function
86706 * becomes a no-operation.
86707 */
86708-int __request_module(bool wait, const char *fmt, ...)
86709+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86710 {
86711- va_list args;
86712 char module_name[MODULE_NAME_LEN];
86713 unsigned int max_modprobes;
86714 int ret;
86715@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86716 if (!modprobe_path[0])
86717 return 0;
86718
86719- va_start(args, fmt);
86720- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86721- va_end(args);
86722+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86723 if (ret >= MODULE_NAME_LEN)
86724 return -ENAMETOOLONG;
86725
86726@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86727 if (ret)
86728 return ret;
86729
86730+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86731+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86732+ /* hack to workaround consolekit/udisks stupidity */
86733+ read_lock(&tasklist_lock);
86734+ if (!strcmp(current->comm, "mount") &&
86735+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86736+ read_unlock(&tasklist_lock);
86737+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86738+ return -EPERM;
86739+ }
86740+ read_unlock(&tasklist_lock);
86741+ }
86742+#endif
86743+
86744 /* If modprobe needs a service that is in a module, we get a recursive
86745 * loop. Limit the number of running kmod threads to max_threads/2 or
86746 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86747@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86748
86749 trace_module_request(module_name, wait, _RET_IP_);
86750
86751- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86752+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86753
86754 atomic_dec(&kmod_concurrent);
86755 return ret;
86756 }
86757+
86758+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86759+{
86760+ va_list args;
86761+ int ret;
86762+
86763+ va_start(args, fmt);
86764+ ret = ____request_module(wait, module_param, fmt, args);
86765+ va_end(args);
86766+
86767+ return ret;
86768+}
86769+
86770+int __request_module(bool wait, const char *fmt, ...)
86771+{
86772+ va_list args;
86773+ int ret;
86774+
86775+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86776+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86777+ char module_param[MODULE_NAME_LEN];
86778+
86779+ memset(module_param, 0, sizeof(module_param));
86780+
86781+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86782+
86783+ va_start(args, fmt);
86784+ ret = ____request_module(wait, module_param, fmt, args);
86785+ va_end(args);
86786+
86787+ return ret;
86788+ }
86789+#endif
86790+
86791+ va_start(args, fmt);
86792+ ret = ____request_module(wait, NULL, fmt, args);
86793+ va_end(args);
86794+
86795+ return ret;
86796+}
86797+
86798 EXPORT_SYMBOL(__request_module);
86799 #endif /* CONFIG_MODULES */
86800
86801@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86802 */
86803 set_user_nice(current, 0);
86804
86805+#ifdef CONFIG_GRKERNSEC
86806+ /* this is race-free as far as userland is concerned as we copied
86807+ out the path to be used prior to this point and are now operating
86808+ on that copy
86809+ */
86810+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86811+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86812+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86813+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86814+ retval = -EPERM;
86815+ goto fail;
86816+ }
86817+#endif
86818+
86819 retval = -ENOMEM;
86820 new = prepare_kernel_cred(current);
86821 if (!new)
86822@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86823 commit_creds(new);
86824
86825 retval = do_execve(getname_kernel(sub_info->path),
86826- (const char __user *const __user *)sub_info->argv,
86827- (const char __user *const __user *)sub_info->envp);
86828+ (const char __user *const __force_user *)sub_info->argv,
86829+ (const char __user *const __force_user *)sub_info->envp);
86830 if (!retval)
86831 return 0;
86832
86833@@ -260,6 +327,10 @@ static int call_helper(void *data)
86834
86835 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86836 {
86837+#ifdef CONFIG_GRKERNSEC
86838+ kfree(info->path);
86839+ info->path = info->origpath;
86840+#endif
86841 if (info->cleanup)
86842 (*info->cleanup)(info);
86843 kfree(info);
86844@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86845 *
86846 * Thus the __user pointer cast is valid here.
86847 */
86848- sys_wait4(pid, (int __user *)&ret, 0, NULL);
86849+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86850
86851 /*
86852 * If ret is 0, either ____call_usermodehelper failed and the
86853@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86854 goto out;
86855
86856 INIT_WORK(&sub_info->work, __call_usermodehelper);
86857+#ifdef CONFIG_GRKERNSEC
86858+ sub_info->origpath = path;
86859+ sub_info->path = kstrdup(path, gfp_mask);
86860+#else
86861 sub_info->path = path;
86862+#endif
86863 sub_info->argv = argv;
86864 sub_info->envp = envp;
86865
86866@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86867 static int proc_cap_handler(struct ctl_table *table, int write,
86868 void __user *buffer, size_t *lenp, loff_t *ppos)
86869 {
86870- struct ctl_table t;
86871+ ctl_table_no_const t;
86872 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86873 kernel_cap_t new_cap;
86874 int err, i;
86875diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86876index ceeadfc..11c18b6 100644
86877--- a/kernel/kprobes.c
86878+++ b/kernel/kprobes.c
86879@@ -31,6 +31,9 @@
86880 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86881 * <prasanna@in.ibm.com> added function-return probes.
86882 */
86883+#ifdef CONFIG_GRKERNSEC_HIDESYM
86884+#define __INCLUDED_BY_HIDESYM 1
86885+#endif
86886 #include <linux/kprobes.h>
86887 #include <linux/hash.h>
86888 #include <linux/init.h>
86889@@ -135,12 +138,12 @@ enum kprobe_slot_state {
86890
86891 static void *alloc_insn_page(void)
86892 {
86893- return module_alloc(PAGE_SIZE);
86894+ return module_alloc_exec(PAGE_SIZE);
86895 }
86896
86897 static void free_insn_page(void *page)
86898 {
86899- module_free(NULL, page);
86900+ module_free_exec(NULL, page);
86901 }
86902
86903 struct kprobe_insn_cache kprobe_insn_slots = {
86904@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86905 kprobe_type = "k";
86906
86907 if (sym)
86908- seq_printf(pi, "%p %s %s+0x%x %s ",
86909+ seq_printf(pi, "%pK %s %s+0x%x %s ",
86910 p->addr, kprobe_type, sym, offset,
86911 (modname ? modname : " "));
86912 else
86913- seq_printf(pi, "%p %s %p ",
86914+ seq_printf(pi, "%pK %s %pK ",
86915 p->addr, kprobe_type, p->addr);
86916
86917 if (!pp)
86918diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86919index d945a94..0b7f45f 100644
86920--- a/kernel/ksysfs.c
86921+++ b/kernel/ksysfs.c
86922@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86923 {
86924 if (count+1 > UEVENT_HELPER_PATH_LEN)
86925 return -ENOENT;
86926+ if (!capable(CAP_SYS_ADMIN))
86927+ return -EPERM;
86928 memcpy(uevent_helper, buf, count);
86929 uevent_helper[count] = '\0';
86930 if (count && uevent_helper[count-1] == '\n')
86931@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86932 return count;
86933 }
86934
86935-static struct bin_attribute notes_attr = {
86936+static bin_attribute_no_const notes_attr __read_only = {
86937 .attr = {
86938 .name = "notes",
86939 .mode = S_IRUGO,
86940diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86941index eb8a547..321d8e1 100644
86942--- a/kernel/locking/lockdep.c
86943+++ b/kernel/locking/lockdep.c
86944@@ -597,6 +597,10 @@ static int static_obj(void *obj)
86945 end = (unsigned long) &_end,
86946 addr = (unsigned long) obj;
86947
86948+#ifdef CONFIG_PAX_KERNEXEC
86949+ start = ktla_ktva(start);
86950+#endif
86951+
86952 /*
86953 * static variable?
86954 */
86955@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86956 if (!static_obj(lock->key)) {
86957 debug_locks_off();
86958 printk("INFO: trying to register non-static key.\n");
86959+ printk("lock:%pS key:%pS.\n", lock, lock->key);
86960 printk("the code is fine but needs lockdep annotation.\n");
86961 printk("turning off the locking correctness validator.\n");
86962 dump_stack();
86963@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86964 if (!class)
86965 return 0;
86966 }
86967- atomic_inc((atomic_t *)&class->ops);
86968+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86969 if (very_verbose(class)) {
86970 printk("\nacquire class [%p] %s", class->key, class->name);
86971 if (class->name_version > 1)
86972diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86973index ef43ac4..2720dfa 100644
86974--- a/kernel/locking/lockdep_proc.c
86975+++ b/kernel/locking/lockdep_proc.c
86976@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86977 return 0;
86978 }
86979
86980- seq_printf(m, "%p", class->key);
86981+ seq_printf(m, "%pK", class->key);
86982 #ifdef CONFIG_DEBUG_LOCKDEP
86983 seq_printf(m, " OPS:%8ld", class->ops);
86984 #endif
86985@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86986
86987 list_for_each_entry(entry, &class->locks_after, entry) {
86988 if (entry->distance == 1) {
86989- seq_printf(m, " -> [%p] ", entry->class->key);
86990+ seq_printf(m, " -> [%pK] ", entry->class->key);
86991 print_name(m, entry->class);
86992 seq_puts(m, "\n");
86993 }
86994@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86995 if (!class->key)
86996 continue;
86997
86998- seq_printf(m, "[%p] ", class->key);
86999+ seq_printf(m, "[%pK] ", class->key);
87000 print_name(m, class);
87001 seq_puts(m, "\n");
87002 }
87003@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87004 if (!i)
87005 seq_line(m, '-', 40-namelen, namelen);
87006
87007- snprintf(ip, sizeof(ip), "[<%p>]",
87008+ snprintf(ip, sizeof(ip), "[<%pK>]",
87009 (void *)class->contention_point[i]);
87010 seq_printf(m, "%40s %14lu %29s %pS\n",
87011 name, stats->contention_point[i],
87012@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87013 if (!i)
87014 seq_line(m, '-', 40-namelen, namelen);
87015
87016- snprintf(ip, sizeof(ip), "[<%p>]",
87017+ snprintf(ip, sizeof(ip), "[<%pK>]",
87018 (void *)class->contending_point[i]);
87019 seq_printf(m, "%40s %14lu %29s %pS\n",
87020 name, stats->contending_point[i],
87021diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87022index faf6f5b..dc9070a 100644
87023--- a/kernel/locking/mutex-debug.c
87024+++ b/kernel/locking/mutex-debug.c
87025@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87026 }
87027
87028 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87029- struct thread_info *ti)
87030+ struct task_struct *task)
87031 {
87032 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87033
87034 /* Mark the current thread as blocked on the lock: */
87035- ti->task->blocked_on = waiter;
87036+ task->blocked_on = waiter;
87037 }
87038
87039 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87040- struct thread_info *ti)
87041+ struct task_struct *task)
87042 {
87043 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87044- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87045- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87046- ti->task->blocked_on = NULL;
87047+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87048+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87049+ task->blocked_on = NULL;
87050
87051 list_del_init(&waiter->list);
87052 waiter->task = NULL;
87053diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87054index 0799fd3..d06ae3b 100644
87055--- a/kernel/locking/mutex-debug.h
87056+++ b/kernel/locking/mutex-debug.h
87057@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87058 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87059 extern void debug_mutex_add_waiter(struct mutex *lock,
87060 struct mutex_waiter *waiter,
87061- struct thread_info *ti);
87062+ struct task_struct *task);
87063 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87064- struct thread_info *ti);
87065+ struct task_struct *task);
87066 extern void debug_mutex_unlock(struct mutex *lock);
87067 extern void debug_mutex_init(struct mutex *lock, const char *name,
87068 struct lock_class_key *key);
87069diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87070index 4dd6e4c..df52693 100644
87071--- a/kernel/locking/mutex.c
87072+++ b/kernel/locking/mutex.c
87073@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
87074 node->locked = 1;
87075 return;
87076 }
87077- ACCESS_ONCE(prev->next) = node;
87078+ ACCESS_ONCE_RW(prev->next) = node;
87079 smp_wmb();
87080 /* Wait until the lock holder passes the lock down */
87081 while (!ACCESS_ONCE(node->locked))
87082@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
87083 while (!(next = ACCESS_ONCE(node->next)))
87084 arch_mutex_cpu_relax();
87085 }
87086- ACCESS_ONCE(next->locked) = 1;
87087+ ACCESS_ONCE_RW(next->locked) = 1;
87088 smp_wmb();
87089 }
87090
87091@@ -520,7 +520,7 @@ slowpath:
87092 goto skip_wait;
87093
87094 debug_mutex_lock_common(lock, &waiter);
87095- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87096+ debug_mutex_add_waiter(lock, &waiter, task);
87097
87098 /* add waiting tasks to the end of the waitqueue (FIFO): */
87099 list_add_tail(&waiter.list, &lock->wait_list);
87100@@ -564,7 +564,7 @@ slowpath:
87101 schedule_preempt_disabled();
87102 spin_lock_mutex(&lock->wait_lock, flags);
87103 }
87104- mutex_remove_waiter(lock, &waiter, current_thread_info());
87105+ mutex_remove_waiter(lock, &waiter, task);
87106 /* set it to 0 if there are no waiters left: */
87107 if (likely(list_empty(&lock->wait_list)))
87108 atomic_set(&lock->count, 0);
87109@@ -601,7 +601,7 @@ skip_wait:
87110 return 0;
87111
87112 err:
87113- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87114+ mutex_remove_waiter(lock, &waiter, task);
87115 spin_unlock_mutex(&lock->wait_lock, flags);
87116 debug_mutex_free_waiter(&waiter);
87117 mutex_release(&lock->dep_map, 1, ip);
87118diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87119index 1d96dd0..994ff19 100644
87120--- a/kernel/locking/rtmutex-tester.c
87121+++ b/kernel/locking/rtmutex-tester.c
87122@@ -22,7 +22,7 @@
87123 #define MAX_RT_TEST_MUTEXES 8
87124
87125 static spinlock_t rttest_lock;
87126-static atomic_t rttest_event;
87127+static atomic_unchecked_t rttest_event;
87128
87129 struct test_thread_data {
87130 int opcode;
87131@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87132
87133 case RTTEST_LOCKCONT:
87134 td->mutexes[td->opdata] = 1;
87135- td->event = atomic_add_return(1, &rttest_event);
87136+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87137 return 0;
87138
87139 case RTTEST_RESET:
87140@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87141 return 0;
87142
87143 case RTTEST_RESETEVENT:
87144- atomic_set(&rttest_event, 0);
87145+ atomic_set_unchecked(&rttest_event, 0);
87146 return 0;
87147
87148 default:
87149@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87150 return ret;
87151
87152 td->mutexes[id] = 1;
87153- td->event = atomic_add_return(1, &rttest_event);
87154+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87155 rt_mutex_lock(&mutexes[id]);
87156- td->event = atomic_add_return(1, &rttest_event);
87157+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87158 td->mutexes[id] = 4;
87159 return 0;
87160
87161@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87162 return ret;
87163
87164 td->mutexes[id] = 1;
87165- td->event = atomic_add_return(1, &rttest_event);
87166+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87167 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87168- td->event = atomic_add_return(1, &rttest_event);
87169+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87170 td->mutexes[id] = ret ? 0 : 4;
87171 return ret ? -EINTR : 0;
87172
87173@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87174 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87175 return ret;
87176
87177- td->event = atomic_add_return(1, &rttest_event);
87178+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87179 rt_mutex_unlock(&mutexes[id]);
87180- td->event = atomic_add_return(1, &rttest_event);
87181+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87182 td->mutexes[id] = 0;
87183 return 0;
87184
87185@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87186 break;
87187
87188 td->mutexes[dat] = 2;
87189- td->event = atomic_add_return(1, &rttest_event);
87190+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87191 break;
87192
87193 default:
87194@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87195 return;
87196
87197 td->mutexes[dat] = 3;
87198- td->event = atomic_add_return(1, &rttest_event);
87199+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87200 break;
87201
87202 case RTTEST_LOCKNOWAIT:
87203@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87204 return;
87205
87206 td->mutexes[dat] = 1;
87207- td->event = atomic_add_return(1, &rttest_event);
87208+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87209 return;
87210
87211 default:
87212diff --git a/kernel/module.c b/kernel/module.c
87213index d24fcf2..2af3fd9 100644
87214--- a/kernel/module.c
87215+++ b/kernel/module.c
87216@@ -61,6 +61,7 @@
87217 #include <linux/pfn.h>
87218 #include <linux/bsearch.h>
87219 #include <linux/fips.h>
87220+#include <linux/grsecurity.h>
87221 #include <uapi/linux/module.h>
87222 #include "module-internal.h"
87223
87224@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87225
87226 /* Bounds of module allocation, for speeding __module_address.
87227 * Protected by module_mutex. */
87228-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87229+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87230+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87231
87232 int register_module_notifier(struct notifier_block * nb)
87233 {
87234@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87235 return true;
87236
87237 list_for_each_entry_rcu(mod, &modules, list) {
87238- struct symsearch arr[] = {
87239+ struct symsearch modarr[] = {
87240 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87241 NOT_GPL_ONLY, false },
87242 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87243@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87244 if (mod->state == MODULE_STATE_UNFORMED)
87245 continue;
87246
87247- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87248+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87249 return true;
87250 }
87251 return false;
87252@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87253 if (!pcpusec->sh_size)
87254 return 0;
87255
87256- if (align > PAGE_SIZE) {
87257+ if (align-1 >= PAGE_SIZE) {
87258 pr_warn("%s: per-cpu alignment %li > %li\n",
87259 mod->name, align, PAGE_SIZE);
87260 align = PAGE_SIZE;
87261@@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87262 static ssize_t show_coresize(struct module_attribute *mattr,
87263 struct module_kobject *mk, char *buffer)
87264 {
87265- return sprintf(buffer, "%u\n", mk->mod->core_size);
87266+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87267 }
87268
87269 static struct module_attribute modinfo_coresize =
87270@@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87271 static ssize_t show_initsize(struct module_attribute *mattr,
87272 struct module_kobject *mk, char *buffer)
87273 {
87274- return sprintf(buffer, "%u\n", mk->mod->init_size);
87275+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87276 }
87277
87278 static struct module_attribute modinfo_initsize =
87279@@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87280 goto bad_version;
87281 }
87282
87283+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87284+ /*
87285+ * avoid potentially printing jibberish on attempted load
87286+ * of a module randomized with a different seed
87287+ */
87288+ pr_warn("no symbol version for %s\n", symname);
87289+#else
87290 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87291+#endif
87292 return 0;
87293
87294 bad_version:
87295+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87296+ /*
87297+ * avoid potentially printing jibberish on attempted load
87298+ * of a module randomized with a different seed
87299+ */
87300+ printk("attempted module disagrees about version of symbol %s\n",
87301+ symname);
87302+#else
87303 printk("%s: disagrees about version of symbol %s\n",
87304 mod->name, symname);
87305+#endif
87306 return 0;
87307 }
87308
87309@@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87310 */
87311 #ifdef CONFIG_SYSFS
87312
87313-#ifdef CONFIG_KALLSYMS
87314+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87315 static inline bool sect_empty(const Elf_Shdr *sect)
87316 {
87317 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87318@@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87319 {
87320 unsigned int notes, loaded, i;
87321 struct module_notes_attrs *notes_attrs;
87322- struct bin_attribute *nattr;
87323+ bin_attribute_no_const *nattr;
87324
87325 /* failed to create section attributes, so can't create notes */
87326 if (!mod->sect_attrs)
87327@@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87328 static int module_add_modinfo_attrs(struct module *mod)
87329 {
87330 struct module_attribute *attr;
87331- struct module_attribute *temp_attr;
87332+ module_attribute_no_const *temp_attr;
87333 int error = 0;
87334 int i;
87335
87336@@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87337
87338 static void unset_module_core_ro_nx(struct module *mod)
87339 {
87340- set_page_attributes(mod->module_core + mod->core_text_size,
87341- mod->module_core + mod->core_size,
87342+ set_page_attributes(mod->module_core_rw,
87343+ mod->module_core_rw + mod->core_size_rw,
87344 set_memory_x);
87345- set_page_attributes(mod->module_core,
87346- mod->module_core + mod->core_ro_size,
87347+ set_page_attributes(mod->module_core_rx,
87348+ mod->module_core_rx + mod->core_size_rx,
87349 set_memory_rw);
87350 }
87351
87352 static void unset_module_init_ro_nx(struct module *mod)
87353 {
87354- set_page_attributes(mod->module_init + mod->init_text_size,
87355- mod->module_init + mod->init_size,
87356+ set_page_attributes(mod->module_init_rw,
87357+ mod->module_init_rw + mod->init_size_rw,
87358 set_memory_x);
87359- set_page_attributes(mod->module_init,
87360- mod->module_init + mod->init_ro_size,
87361+ set_page_attributes(mod->module_init_rx,
87362+ mod->module_init_rx + mod->init_size_rx,
87363 set_memory_rw);
87364 }
87365
87366@@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87367 list_for_each_entry_rcu(mod, &modules, list) {
87368 if (mod->state == MODULE_STATE_UNFORMED)
87369 continue;
87370- if ((mod->module_core) && (mod->core_text_size)) {
87371- set_page_attributes(mod->module_core,
87372- mod->module_core + mod->core_text_size,
87373+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87374+ set_page_attributes(mod->module_core_rx,
87375+ mod->module_core_rx + mod->core_size_rx,
87376 set_memory_rw);
87377 }
87378- if ((mod->module_init) && (mod->init_text_size)) {
87379- set_page_attributes(mod->module_init,
87380- mod->module_init + mod->init_text_size,
87381+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87382+ set_page_attributes(mod->module_init_rx,
87383+ mod->module_init_rx + mod->init_size_rx,
87384 set_memory_rw);
87385 }
87386 }
87387@@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87388 list_for_each_entry_rcu(mod, &modules, list) {
87389 if (mod->state == MODULE_STATE_UNFORMED)
87390 continue;
87391- if ((mod->module_core) && (mod->core_text_size)) {
87392- set_page_attributes(mod->module_core,
87393- mod->module_core + mod->core_text_size,
87394+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87395+ set_page_attributes(mod->module_core_rx,
87396+ mod->module_core_rx + mod->core_size_rx,
87397 set_memory_ro);
87398 }
87399- if ((mod->module_init) && (mod->init_text_size)) {
87400- set_page_attributes(mod->module_init,
87401- mod->module_init + mod->init_text_size,
87402+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87403+ set_page_attributes(mod->module_init_rx,
87404+ mod->module_init_rx + mod->init_size_rx,
87405 set_memory_ro);
87406 }
87407 }
87408@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87409
87410 /* This may be NULL, but that's OK */
87411 unset_module_init_ro_nx(mod);
87412- module_free(mod, mod->module_init);
87413+ module_free(mod, mod->module_init_rw);
87414+ module_free_exec(mod, mod->module_init_rx);
87415 kfree(mod->args);
87416 percpu_modfree(mod);
87417
87418 /* Free lock-classes: */
87419- lockdep_free_key_range(mod->module_core, mod->core_size);
87420+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87421+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87422
87423 /* Finally, free the core (containing the module structure) */
87424 unset_module_core_ro_nx(mod);
87425- module_free(mod, mod->module_core);
87426+ module_free_exec(mod, mod->module_core_rx);
87427+ module_free(mod, mod->module_core_rw);
87428
87429 #ifdef CONFIG_MPU
87430 update_protections(current->mm);
87431@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87432 int ret = 0;
87433 const struct kernel_symbol *ksym;
87434
87435+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87436+ int is_fs_load = 0;
87437+ int register_filesystem_found = 0;
87438+ char *p;
87439+
87440+ p = strstr(mod->args, "grsec_modharden_fs");
87441+ if (p) {
87442+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87443+ /* copy \0 as well */
87444+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87445+ is_fs_load = 1;
87446+ }
87447+#endif
87448+
87449 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87450 const char *name = info->strtab + sym[i].st_name;
87451
87452+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87453+ /* it's a real shame this will never get ripped and copied
87454+ upstream! ;(
87455+ */
87456+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87457+ register_filesystem_found = 1;
87458+#endif
87459+
87460 switch (sym[i].st_shndx) {
87461 case SHN_COMMON:
87462 /* We compiled with -fno-common. These are not
87463@@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87464 ksym = resolve_symbol_wait(mod, info, name);
87465 /* Ok if resolved. */
87466 if (ksym && !IS_ERR(ksym)) {
87467+ pax_open_kernel();
87468 sym[i].st_value = ksym->value;
87469+ pax_close_kernel();
87470 break;
87471 }
87472
87473@@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87474 secbase = (unsigned long)mod_percpu(mod);
87475 else
87476 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87477+ pax_open_kernel();
87478 sym[i].st_value += secbase;
87479+ pax_close_kernel();
87480 break;
87481 }
87482 }
87483
87484+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87485+ if (is_fs_load && !register_filesystem_found) {
87486+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87487+ ret = -EPERM;
87488+ }
87489+#endif
87490+
87491 return ret;
87492 }
87493
87494@@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87495 || s->sh_entsize != ~0UL
87496 || strstarts(sname, ".init"))
87497 continue;
87498- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87499+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87500+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87501+ else
87502+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87503 pr_debug("\t%s\n", sname);
87504 }
87505- switch (m) {
87506- case 0: /* executable */
87507- mod->core_size = debug_align(mod->core_size);
87508- mod->core_text_size = mod->core_size;
87509- break;
87510- case 1: /* RO: text and ro-data */
87511- mod->core_size = debug_align(mod->core_size);
87512- mod->core_ro_size = mod->core_size;
87513- break;
87514- case 3: /* whole core */
87515- mod->core_size = debug_align(mod->core_size);
87516- break;
87517- }
87518 }
87519
87520 pr_debug("Init section allocation order:\n");
87521@@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87522 || s->sh_entsize != ~0UL
87523 || !strstarts(sname, ".init"))
87524 continue;
87525- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87526- | INIT_OFFSET_MASK);
87527+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87528+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87529+ else
87530+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87531+ s->sh_entsize |= INIT_OFFSET_MASK;
87532 pr_debug("\t%s\n", sname);
87533 }
87534- switch (m) {
87535- case 0: /* executable */
87536- mod->init_size = debug_align(mod->init_size);
87537- mod->init_text_size = mod->init_size;
87538- break;
87539- case 1: /* RO: text and ro-data */
87540- mod->init_size = debug_align(mod->init_size);
87541- mod->init_ro_size = mod->init_size;
87542- break;
87543- case 3: /* whole init */
87544- mod->init_size = debug_align(mod->init_size);
87545- break;
87546- }
87547 }
87548 }
87549
87550@@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87551
87552 /* Put symbol section at end of init part of module. */
87553 symsect->sh_flags |= SHF_ALLOC;
87554- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87555+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87556 info->index.sym) | INIT_OFFSET_MASK;
87557 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87558
87559@@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87560 }
87561
87562 /* Append room for core symbols at end of core part. */
87563- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87564- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87565- mod->core_size += strtab_size;
87566+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87567+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87568+ mod->core_size_rx += strtab_size;
87569
87570 /* Put string table section at end of init part of module. */
87571 strsect->sh_flags |= SHF_ALLOC;
87572- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87573+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87574 info->index.str) | INIT_OFFSET_MASK;
87575 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87576 }
87577@@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87578 /* Make sure we get permanent strtab: don't use info->strtab. */
87579 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87580
87581+ pax_open_kernel();
87582+
87583 /* Set types up while we still have access to sections. */
87584 for (i = 0; i < mod->num_symtab; i++)
87585 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87586
87587- mod->core_symtab = dst = mod->module_core + info->symoffs;
87588- mod->core_strtab = s = mod->module_core + info->stroffs;
87589+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87590+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87591 src = mod->symtab;
87592 for (ndst = i = 0; i < mod->num_symtab; i++) {
87593 if (i == 0 ||
87594@@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87595 }
87596 }
87597 mod->core_num_syms = ndst;
87598+
87599+ pax_close_kernel();
87600 }
87601 #else
87602 static inline void layout_symtab(struct module *mod, struct load_info *info)
87603@@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87604 return vmalloc_exec(size);
87605 }
87606
87607-static void *module_alloc_update_bounds(unsigned long size)
87608+static void *module_alloc_update_bounds_rw(unsigned long size)
87609 {
87610 void *ret = module_alloc(size);
87611
87612 if (ret) {
87613 mutex_lock(&module_mutex);
87614 /* Update module bounds. */
87615- if ((unsigned long)ret < module_addr_min)
87616- module_addr_min = (unsigned long)ret;
87617- if ((unsigned long)ret + size > module_addr_max)
87618- module_addr_max = (unsigned long)ret + size;
87619+ if ((unsigned long)ret < module_addr_min_rw)
87620+ module_addr_min_rw = (unsigned long)ret;
87621+ if ((unsigned long)ret + size > module_addr_max_rw)
87622+ module_addr_max_rw = (unsigned long)ret + size;
87623+ mutex_unlock(&module_mutex);
87624+ }
87625+ return ret;
87626+}
87627+
87628+static void *module_alloc_update_bounds_rx(unsigned long size)
87629+{
87630+ void *ret = module_alloc_exec(size);
87631+
87632+ if (ret) {
87633+ mutex_lock(&module_mutex);
87634+ /* Update module bounds. */
87635+ if ((unsigned long)ret < module_addr_min_rx)
87636+ module_addr_min_rx = (unsigned long)ret;
87637+ if ((unsigned long)ret + size > module_addr_max_rx)
87638+ module_addr_max_rx = (unsigned long)ret + size;
87639 mutex_unlock(&module_mutex);
87640 }
87641 return ret;
87642@@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87643 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87644
87645 if (info->index.sym == 0) {
87646+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87647+ /*
87648+ * avoid potentially printing jibberish on attempted load
87649+ * of a module randomized with a different seed
87650+ */
87651+ pr_warn("module has no symbols (stripped?)\n");
87652+#else
87653 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87654+#endif
87655 return ERR_PTR(-ENOEXEC);
87656 }
87657
87658@@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87659 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87660 {
87661 const char *modmagic = get_modinfo(info, "vermagic");
87662+ const char *license = get_modinfo(info, "license");
87663 int err;
87664
87665+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87666+ if (!license || !license_is_gpl_compatible(license))
87667+ return -ENOEXEC;
87668+#endif
87669+
87670 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87671 modmagic = NULL;
87672
87673@@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87674 }
87675
87676 /* Set up license info based on the info section */
87677- set_license(mod, get_modinfo(info, "license"));
87678+ set_license(mod, license);
87679
87680 return 0;
87681 }
87682@@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87683 void *ptr;
87684
87685 /* Do the allocs. */
87686- ptr = module_alloc_update_bounds(mod->core_size);
87687+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87688 /*
87689 * The pointer to this block is stored in the module structure
87690 * which is inside the block. Just mark it as not being a
87691@@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87692 if (!ptr)
87693 return -ENOMEM;
87694
87695- memset(ptr, 0, mod->core_size);
87696- mod->module_core = ptr;
87697+ memset(ptr, 0, mod->core_size_rw);
87698+ mod->module_core_rw = ptr;
87699
87700- if (mod->init_size) {
87701- ptr = module_alloc_update_bounds(mod->init_size);
87702+ if (mod->init_size_rw) {
87703+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87704 /*
87705 * The pointer to this block is stored in the module structure
87706 * which is inside the block. This block doesn't need to be
87707@@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
87708 */
87709 kmemleak_ignore(ptr);
87710 if (!ptr) {
87711- module_free(mod, mod->module_core);
87712+ module_free(mod, mod->module_core_rw);
87713 return -ENOMEM;
87714 }
87715- memset(ptr, 0, mod->init_size);
87716- mod->module_init = ptr;
87717+ memset(ptr, 0, mod->init_size_rw);
87718+ mod->module_init_rw = ptr;
87719 } else
87720- mod->module_init = NULL;
87721+ mod->module_init_rw = NULL;
87722+
87723+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87724+ kmemleak_not_leak(ptr);
87725+ if (!ptr) {
87726+ if (mod->module_init_rw)
87727+ module_free(mod, mod->module_init_rw);
87728+ module_free(mod, mod->module_core_rw);
87729+ return -ENOMEM;
87730+ }
87731+
87732+ pax_open_kernel();
87733+ memset(ptr, 0, mod->core_size_rx);
87734+ pax_close_kernel();
87735+ mod->module_core_rx = ptr;
87736+
87737+ if (mod->init_size_rx) {
87738+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87739+ kmemleak_ignore(ptr);
87740+ if (!ptr && mod->init_size_rx) {
87741+ module_free_exec(mod, mod->module_core_rx);
87742+ if (mod->module_init_rw)
87743+ module_free(mod, mod->module_init_rw);
87744+ module_free(mod, mod->module_core_rw);
87745+ return -ENOMEM;
87746+ }
87747+
87748+ pax_open_kernel();
87749+ memset(ptr, 0, mod->init_size_rx);
87750+ pax_close_kernel();
87751+ mod->module_init_rx = ptr;
87752+ } else
87753+ mod->module_init_rx = NULL;
87754
87755 /* Transfer each section which specifies SHF_ALLOC */
87756 pr_debug("final section addresses:\n");
87757@@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
87758 if (!(shdr->sh_flags & SHF_ALLOC))
87759 continue;
87760
87761- if (shdr->sh_entsize & INIT_OFFSET_MASK)
87762- dest = mod->module_init
87763- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87764- else
87765- dest = mod->module_core + shdr->sh_entsize;
87766+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87767+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87768+ dest = mod->module_init_rw
87769+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87770+ else
87771+ dest = mod->module_init_rx
87772+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87773+ } else {
87774+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87775+ dest = mod->module_core_rw + shdr->sh_entsize;
87776+ else
87777+ dest = mod->module_core_rx + shdr->sh_entsize;
87778+ }
87779+
87780+ if (shdr->sh_type != SHT_NOBITS) {
87781+
87782+#ifdef CONFIG_PAX_KERNEXEC
87783+#ifdef CONFIG_X86_64
87784+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87785+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87786+#endif
87787+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87788+ pax_open_kernel();
87789+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87790+ pax_close_kernel();
87791+ } else
87792+#endif
87793
87794- if (shdr->sh_type != SHT_NOBITS)
87795 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87796+ }
87797 /* Update sh_addr to point to copy in image. */
87798- shdr->sh_addr = (unsigned long)dest;
87799+
87800+#ifdef CONFIG_PAX_KERNEXEC
87801+ if (shdr->sh_flags & SHF_EXECINSTR)
87802+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
87803+ else
87804+#endif
87805+
87806+ shdr->sh_addr = (unsigned long)dest;
87807 pr_debug("\t0x%lx %s\n",
87808 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87809 }
87810@@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
87811 * Do it before processing of module parameters, so the module
87812 * can provide parameter accessor functions of its own.
87813 */
87814- if (mod->module_init)
87815- flush_icache_range((unsigned long)mod->module_init,
87816- (unsigned long)mod->module_init
87817- + mod->init_size);
87818- flush_icache_range((unsigned long)mod->module_core,
87819- (unsigned long)mod->module_core + mod->core_size);
87820+ if (mod->module_init_rx)
87821+ flush_icache_range((unsigned long)mod->module_init_rx,
87822+ (unsigned long)mod->module_init_rx
87823+ + mod->init_size_rx);
87824+ flush_icache_range((unsigned long)mod->module_core_rx,
87825+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
87826
87827 set_fs(old_fs);
87828 }
87829@@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87830 static void module_deallocate(struct module *mod, struct load_info *info)
87831 {
87832 percpu_modfree(mod);
87833- module_free(mod, mod->module_init);
87834- module_free(mod, mod->module_core);
87835+ module_free_exec(mod, mod->module_init_rx);
87836+ module_free_exec(mod, mod->module_core_rx);
87837+ module_free(mod, mod->module_init_rw);
87838+ module_free(mod, mod->module_core_rw);
87839 }
87840
87841 int __weak module_finalize(const Elf_Ehdr *hdr,
87842@@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87843 static int post_relocation(struct module *mod, const struct load_info *info)
87844 {
87845 /* Sort exception table now relocations are done. */
87846+ pax_open_kernel();
87847 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87848+ pax_close_kernel();
87849
87850 /* Copy relocated percpu area over. */
87851 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87852@@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
87853 MODULE_STATE_COMING, mod);
87854
87855 /* Set RO and NX regions for core */
87856- set_section_ro_nx(mod->module_core,
87857- mod->core_text_size,
87858- mod->core_ro_size,
87859- mod->core_size);
87860+ set_section_ro_nx(mod->module_core_rx,
87861+ mod->core_size_rx,
87862+ mod->core_size_rx,
87863+ mod->core_size_rx);
87864
87865 /* Set RO and NX regions for init */
87866- set_section_ro_nx(mod->module_init,
87867- mod->init_text_size,
87868- mod->init_ro_size,
87869- mod->init_size);
87870+ set_section_ro_nx(mod->module_init_rx,
87871+ mod->init_size_rx,
87872+ mod->init_size_rx,
87873+ mod->init_size_rx);
87874
87875 do_mod_ctors(mod);
87876 /* Start the module */
87877@@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
87878 mod->strtab = mod->core_strtab;
87879 #endif
87880 unset_module_init_ro_nx(mod);
87881- module_free(mod, mod->module_init);
87882- mod->module_init = NULL;
87883- mod->init_size = 0;
87884- mod->init_ro_size = 0;
87885- mod->init_text_size = 0;
87886+ module_free(mod, mod->module_init_rw);
87887+ module_free_exec(mod, mod->module_init_rx);
87888+ mod->module_init_rw = NULL;
87889+ mod->module_init_rx = NULL;
87890+ mod->init_size_rw = 0;
87891+ mod->init_size_rx = 0;
87892 mutex_unlock(&module_mutex);
87893 wake_up_all(&module_wq);
87894
87895@@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87896 if (err)
87897 goto free_unload;
87898
87899+ /* Now copy in args */
87900+ mod->args = strndup_user(uargs, ~0UL >> 1);
87901+ if (IS_ERR(mod->args)) {
87902+ err = PTR_ERR(mod->args);
87903+ goto free_unload;
87904+ }
87905+
87906 /* Set up MODINFO_ATTR fields */
87907 setup_modinfo(mod, info);
87908
87909+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87910+ {
87911+ char *p, *p2;
87912+
87913+ if (strstr(mod->args, "grsec_modharden_netdev")) {
87914+ 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);
87915+ err = -EPERM;
87916+ goto free_modinfo;
87917+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87918+ p += sizeof("grsec_modharden_normal") - 1;
87919+ p2 = strstr(p, "_");
87920+ if (p2) {
87921+ *p2 = '\0';
87922+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87923+ *p2 = '_';
87924+ }
87925+ err = -EPERM;
87926+ goto free_modinfo;
87927+ }
87928+ }
87929+#endif
87930+
87931 /* Fix up syms, so that st_value is a pointer to location. */
87932 err = simplify_symbols(mod, info);
87933 if (err < 0)
87934@@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87935
87936 flush_module_icache(mod);
87937
87938- /* Now copy in args */
87939- mod->args = strndup_user(uargs, ~0UL >> 1);
87940- if (IS_ERR(mod->args)) {
87941- err = PTR_ERR(mod->args);
87942- goto free_arch_cleanup;
87943- }
87944-
87945 dynamic_debug_setup(info->debug, info->num_debug);
87946
87947 /* Finally it's fully formed, ready to start executing. */
87948@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87949 ddebug_cleanup:
87950 dynamic_debug_remove(info->debug);
87951 synchronize_sched();
87952- kfree(mod->args);
87953- free_arch_cleanup:
87954 module_arch_cleanup(mod);
87955 free_modinfo:
87956 free_modinfo(mod);
87957+ kfree(mod->args);
87958 free_unload:
87959 module_unload_free(mod);
87960 unlink_mod:
87961@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
87962 unsigned long nextval;
87963
87964 /* At worse, next value is at end of module */
87965- if (within_module_init(addr, mod))
87966- nextval = (unsigned long)mod->module_init+mod->init_text_size;
87967+ if (within_module_init_rx(addr, mod))
87968+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87969+ else if (within_module_init_rw(addr, mod))
87970+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87971+ else if (within_module_core_rx(addr, mod))
87972+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87973+ else if (within_module_core_rw(addr, mod))
87974+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87975 else
87976- nextval = (unsigned long)mod->module_core+mod->core_text_size;
87977+ return NULL;
87978
87979 /* Scan for closest preceding symbol, and next symbol. (ELF
87980 starts real symbols at 1). */
87981@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
87982 return 0;
87983
87984 seq_printf(m, "%s %u",
87985- mod->name, mod->init_size + mod->core_size);
87986+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87987 print_unload_info(m, mod);
87988
87989 /* Informative for users. */
87990@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
87991 mod->state == MODULE_STATE_COMING ? "Loading":
87992 "Live");
87993 /* Used by oprofile and other similar tools. */
87994- seq_printf(m, " 0x%pK", mod->module_core);
87995+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87996
87997 /* Taints info */
87998 if (mod->taints)
87999@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
88000
88001 static int __init proc_modules_init(void)
88002 {
88003+#ifndef CONFIG_GRKERNSEC_HIDESYM
88004+#ifdef CONFIG_GRKERNSEC_PROC_USER
88005+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88006+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88007+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88008+#else
88009 proc_create("modules", 0, NULL, &proc_modules_operations);
88010+#endif
88011+#else
88012+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88013+#endif
88014 return 0;
88015 }
88016 module_init(proc_modules_init);
88017@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
88018 {
88019 struct module *mod;
88020
88021- if (addr < module_addr_min || addr > module_addr_max)
88022+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88023+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88024 return NULL;
88025
88026 list_for_each_entry_rcu(mod, &modules, list) {
88027 if (mod->state == MODULE_STATE_UNFORMED)
88028 continue;
88029- if (within_module_core(addr, mod)
88030- || within_module_init(addr, mod))
88031+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88032 return mod;
88033 }
88034 return NULL;
88035@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
88036 */
88037 struct module *__module_text_address(unsigned long addr)
88038 {
88039- struct module *mod = __module_address(addr);
88040+ struct module *mod;
88041+
88042+#ifdef CONFIG_X86_32
88043+ addr = ktla_ktva(addr);
88044+#endif
88045+
88046+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88047+ return NULL;
88048+
88049+ mod = __module_address(addr);
88050+
88051 if (mod) {
88052 /* Make sure it's within the text section. */
88053- if (!within(addr, mod->module_init, mod->init_text_size)
88054- && !within(addr, mod->module_core, mod->core_text_size))
88055+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88056 mod = NULL;
88057 }
88058 return mod;
88059diff --git a/kernel/notifier.c b/kernel/notifier.c
88060index 2d5cc4c..d9ea600 100644
88061--- a/kernel/notifier.c
88062+++ b/kernel/notifier.c
88063@@ -5,6 +5,7 @@
88064 #include <linux/rcupdate.h>
88065 #include <linux/vmalloc.h>
88066 #include <linux/reboot.h>
88067+#include <linux/mm.h>
88068
88069 /*
88070 * Notifier list for kernel code which wants to be called
88071@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88072 while ((*nl) != NULL) {
88073 if (n->priority > (*nl)->priority)
88074 break;
88075- nl = &((*nl)->next);
88076+ nl = (struct notifier_block **)&((*nl)->next);
88077 }
88078- n->next = *nl;
88079+ pax_open_kernel();
88080+ *(const void **)&n->next = *nl;
88081 rcu_assign_pointer(*nl, n);
88082+ pax_close_kernel();
88083 return 0;
88084 }
88085
88086@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88087 return 0;
88088 if (n->priority > (*nl)->priority)
88089 break;
88090- nl = &((*nl)->next);
88091+ nl = (struct notifier_block **)&((*nl)->next);
88092 }
88093- n->next = *nl;
88094+ pax_open_kernel();
88095+ *(const void **)&n->next = *nl;
88096 rcu_assign_pointer(*nl, n);
88097+ pax_close_kernel();
88098 return 0;
88099 }
88100
88101@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88102 {
88103 while ((*nl) != NULL) {
88104 if ((*nl) == n) {
88105+ pax_open_kernel();
88106 rcu_assign_pointer(*nl, n->next);
88107+ pax_close_kernel();
88108 return 0;
88109 }
88110- nl = &((*nl)->next);
88111+ nl = (struct notifier_block **)&((*nl)->next);
88112 }
88113 return -ENOENT;
88114 }
88115diff --git a/kernel/padata.c b/kernel/padata.c
88116index 161402f..598814c 100644
88117--- a/kernel/padata.c
88118+++ b/kernel/padata.c
88119@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88120 * seq_nr mod. number of cpus in use.
88121 */
88122
88123- seq_nr = atomic_inc_return(&pd->seq_nr);
88124+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88125 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88126
88127 return padata_index_to_cpu(pd, cpu_index);
88128@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88129 padata_init_pqueues(pd);
88130 padata_init_squeues(pd);
88131 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88132- atomic_set(&pd->seq_nr, -1);
88133+ atomic_set_unchecked(&pd->seq_nr, -1);
88134 atomic_set(&pd->reorder_objects, 0);
88135 atomic_set(&pd->refcnt, 0);
88136 pd->pinst = pinst;
88137diff --git a/kernel/panic.c b/kernel/panic.c
88138index 6d63003..486a109 100644
88139--- a/kernel/panic.c
88140+++ b/kernel/panic.c
88141@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88142 /*
88143 * Stop ourself in panic -- architecture code may override this
88144 */
88145-void __weak panic_smp_self_stop(void)
88146+void __weak __noreturn panic_smp_self_stop(void)
88147 {
88148 while (1)
88149 cpu_relax();
88150@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88151 disable_trace_on_warning();
88152
88153 pr_warn("------------[ cut here ]------------\n");
88154- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88155+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88156 raw_smp_processor_id(), current->pid, file, line, caller);
88157
88158 if (args)
88159@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88160 */
88161 void __stack_chk_fail(void)
88162 {
88163- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88164+ dump_stack();
88165+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88166 __builtin_return_address(0));
88167 }
88168 EXPORT_SYMBOL(__stack_chk_fail);
88169diff --git a/kernel/pid.c b/kernel/pid.c
88170index 9b9a266..c20ef80 100644
88171--- a/kernel/pid.c
88172+++ b/kernel/pid.c
88173@@ -33,6 +33,7 @@
88174 #include <linux/rculist.h>
88175 #include <linux/bootmem.h>
88176 #include <linux/hash.h>
88177+#include <linux/security.h>
88178 #include <linux/pid_namespace.h>
88179 #include <linux/init_task.h>
88180 #include <linux/syscalls.h>
88181@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88182
88183 int pid_max = PID_MAX_DEFAULT;
88184
88185-#define RESERVED_PIDS 300
88186+#define RESERVED_PIDS 500
88187
88188 int pid_max_min = RESERVED_PIDS + 1;
88189 int pid_max_max = PID_MAX_LIMIT;
88190@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88191 */
88192 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88193 {
88194+ struct task_struct *task;
88195+
88196 rcu_lockdep_assert(rcu_read_lock_held(),
88197 "find_task_by_pid_ns() needs rcu_read_lock()"
88198 " protection");
88199- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88200+
88201+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88202+
88203+ if (gr_pid_is_chrooted(task))
88204+ return NULL;
88205+
88206+ return task;
88207 }
88208
88209 struct task_struct *find_task_by_vpid(pid_t vnr)
88210@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88211 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88212 }
88213
88214+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88215+{
88216+ rcu_lockdep_assert(rcu_read_lock_held(),
88217+ "find_task_by_pid_ns() needs rcu_read_lock()"
88218+ " protection");
88219+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88220+}
88221+
88222 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88223 {
88224 struct pid *pid;
88225diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88226index db95d8e..a0ca23f 100644
88227--- a/kernel/pid_namespace.c
88228+++ b/kernel/pid_namespace.c
88229@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88230 void __user *buffer, size_t *lenp, loff_t *ppos)
88231 {
88232 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88233- struct ctl_table tmp = *table;
88234+ ctl_table_no_const tmp = *table;
88235
88236 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88237 return -EPERM;
88238diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88239index 3b89464..5e38379 100644
88240--- a/kernel/posix-cpu-timers.c
88241+++ b/kernel/posix-cpu-timers.c
88242@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88243
88244 static __init int init_posix_cpu_timers(void)
88245 {
88246- struct k_clock process = {
88247+ static struct k_clock process = {
88248 .clock_getres = process_cpu_clock_getres,
88249 .clock_get = process_cpu_clock_get,
88250 .timer_create = process_cpu_timer_create,
88251 .nsleep = process_cpu_nsleep,
88252 .nsleep_restart = process_cpu_nsleep_restart,
88253 };
88254- struct k_clock thread = {
88255+ static struct k_clock thread = {
88256 .clock_getres = thread_cpu_clock_getres,
88257 .clock_get = thread_cpu_clock_get,
88258 .timer_create = thread_cpu_timer_create,
88259diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88260index 424c2d4..679242f 100644
88261--- a/kernel/posix-timers.c
88262+++ b/kernel/posix-timers.c
88263@@ -43,6 +43,7 @@
88264 #include <linux/hash.h>
88265 #include <linux/posix-clock.h>
88266 #include <linux/posix-timers.h>
88267+#include <linux/grsecurity.h>
88268 #include <linux/syscalls.h>
88269 #include <linux/wait.h>
88270 #include <linux/workqueue.h>
88271@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88272 * which we beg off on and pass to do_sys_settimeofday().
88273 */
88274
88275-static struct k_clock posix_clocks[MAX_CLOCKS];
88276+static struct k_clock *posix_clocks[MAX_CLOCKS];
88277
88278 /*
88279 * These ones are defined below.
88280@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88281 */
88282 static __init int init_posix_timers(void)
88283 {
88284- struct k_clock clock_realtime = {
88285+ static struct k_clock clock_realtime = {
88286 .clock_getres = hrtimer_get_res,
88287 .clock_get = posix_clock_realtime_get,
88288 .clock_set = posix_clock_realtime_set,
88289@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88290 .timer_get = common_timer_get,
88291 .timer_del = common_timer_del,
88292 };
88293- struct k_clock clock_monotonic = {
88294+ static struct k_clock clock_monotonic = {
88295 .clock_getres = hrtimer_get_res,
88296 .clock_get = posix_ktime_get_ts,
88297 .nsleep = common_nsleep,
88298@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88299 .timer_get = common_timer_get,
88300 .timer_del = common_timer_del,
88301 };
88302- struct k_clock clock_monotonic_raw = {
88303+ static struct k_clock clock_monotonic_raw = {
88304 .clock_getres = hrtimer_get_res,
88305 .clock_get = posix_get_monotonic_raw,
88306 };
88307- struct k_clock clock_realtime_coarse = {
88308+ static struct k_clock clock_realtime_coarse = {
88309 .clock_getres = posix_get_coarse_res,
88310 .clock_get = posix_get_realtime_coarse,
88311 };
88312- struct k_clock clock_monotonic_coarse = {
88313+ static struct k_clock clock_monotonic_coarse = {
88314 .clock_getres = posix_get_coarse_res,
88315 .clock_get = posix_get_monotonic_coarse,
88316 };
88317- struct k_clock clock_tai = {
88318+ static struct k_clock clock_tai = {
88319 .clock_getres = hrtimer_get_res,
88320 .clock_get = posix_get_tai,
88321 .nsleep = common_nsleep,
88322@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88323 .timer_get = common_timer_get,
88324 .timer_del = common_timer_del,
88325 };
88326- struct k_clock clock_boottime = {
88327+ static struct k_clock clock_boottime = {
88328 .clock_getres = hrtimer_get_res,
88329 .clock_get = posix_get_boottime,
88330 .nsleep = common_nsleep,
88331@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88332 return;
88333 }
88334
88335- posix_clocks[clock_id] = *new_clock;
88336+ posix_clocks[clock_id] = new_clock;
88337 }
88338 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88339
88340@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88341 return (id & CLOCKFD_MASK) == CLOCKFD ?
88342 &clock_posix_dynamic : &clock_posix_cpu;
88343
88344- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88345+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88346 return NULL;
88347- return &posix_clocks[id];
88348+ return posix_clocks[id];
88349 }
88350
88351 static int common_timer_create(struct k_itimer *new_timer)
88352@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88353 struct k_clock *kc = clockid_to_kclock(which_clock);
88354 struct k_itimer *new_timer;
88355 int error, new_timer_id;
88356- sigevent_t event;
88357+ sigevent_t event = { };
88358 int it_id_set = IT_ID_NOT_SET;
88359
88360 if (!kc)
88361@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88362 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88363 return -EFAULT;
88364
88365+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88366+ have their clock_set fptr set to a nosettime dummy function
88367+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88368+ call common_clock_set, which calls do_sys_settimeofday, which
88369+ we hook
88370+ */
88371+
88372 return kc->clock_set(which_clock, &new_tp);
88373 }
88374
88375diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88376index 2fac9cc..56fef29 100644
88377--- a/kernel/power/Kconfig
88378+++ b/kernel/power/Kconfig
88379@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88380 config HIBERNATION
88381 bool "Hibernation (aka 'suspend to disk')"
88382 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88383+ depends on !GRKERNSEC_KMEM
88384+ depends on !PAX_MEMORY_SANITIZE
88385 select HIBERNATE_CALLBACKS
88386 select LZO_COMPRESS
88387 select LZO_DECOMPRESS
88388diff --git a/kernel/power/process.c b/kernel/power/process.c
88389index 06ec886..9dba35e 100644
88390--- a/kernel/power/process.c
88391+++ b/kernel/power/process.c
88392@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88393 unsigned int elapsed_msecs;
88394 bool wakeup = false;
88395 int sleep_usecs = USEC_PER_MSEC;
88396+ bool timedout = false;
88397
88398 do_gettimeofday(&start);
88399
88400@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88401
88402 while (true) {
88403 todo = 0;
88404+ if (time_after(jiffies, end_time))
88405+ timedout = true;
88406 read_lock(&tasklist_lock);
88407 do_each_thread(g, p) {
88408 if (p == current || !freeze_task(p))
88409 continue;
88410
88411- if (!freezer_should_skip(p))
88412+ if (!freezer_should_skip(p)) {
88413 todo++;
88414+ if (timedout) {
88415+ printk(KERN_ERR "Task refusing to freeze:\n");
88416+ sched_show_task(p);
88417+ }
88418+ }
88419 } while_each_thread(g, p);
88420 read_unlock(&tasklist_lock);
88421
88422@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88423 todo += wq_busy;
88424 }
88425
88426- if (!todo || time_after(jiffies, end_time))
88427+ if (!todo || timedout)
88428 break;
88429
88430 if (pm_wakeup_pending()) {
88431diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88432index 4dae9cb..039ffbb 100644
88433--- a/kernel/printk/printk.c
88434+++ b/kernel/printk/printk.c
88435@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88436 if (from_file && type != SYSLOG_ACTION_OPEN)
88437 return 0;
88438
88439+#ifdef CONFIG_GRKERNSEC_DMESG
88440+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88441+ return -EPERM;
88442+#endif
88443+
88444 if (syslog_action_restricted(type)) {
88445 if (capable(CAP_SYSLOG))
88446 return 0;
88447diff --git a/kernel/profile.c b/kernel/profile.c
88448index ebdd9c1..612ee05 100644
88449--- a/kernel/profile.c
88450+++ b/kernel/profile.c
88451@@ -37,7 +37,7 @@ struct profile_hit {
88452 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88453 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88454
88455-static atomic_t *prof_buffer;
88456+static atomic_unchecked_t *prof_buffer;
88457 static unsigned long prof_len, prof_shift;
88458
88459 int prof_on __read_mostly;
88460@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88461 hits[i].pc = 0;
88462 continue;
88463 }
88464- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88465+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88466 hits[i].hits = hits[i].pc = 0;
88467 }
88468 }
88469@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88470 * Add the current hit(s) and flush the write-queue out
88471 * to the global buffer:
88472 */
88473- atomic_add(nr_hits, &prof_buffer[pc]);
88474+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88475 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88476- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88477+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88478 hits[i].pc = hits[i].hits = 0;
88479 }
88480 out:
88481@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88482 {
88483 unsigned long pc;
88484 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88485- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88486+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88487 }
88488 #endif /* !CONFIG_SMP */
88489
88490@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88491 return -EFAULT;
88492 buf++; p++; count--; read++;
88493 }
88494- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88495+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88496 if (copy_to_user(buf, (void *)pnt, count))
88497 return -EFAULT;
88498 read += count;
88499@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88500 }
88501 #endif
88502 profile_discard_flip_buffers();
88503- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88504+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88505 return count;
88506 }
88507
88508diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88509index 1f4bcb3..99cf7ab 100644
88510--- a/kernel/ptrace.c
88511+++ b/kernel/ptrace.c
88512@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88513 if (seize)
88514 flags |= PT_SEIZED;
88515 rcu_read_lock();
88516- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88517+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88518 flags |= PT_PTRACE_CAP;
88519 rcu_read_unlock();
88520 task->ptrace = flags;
88521@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88522 break;
88523 return -EIO;
88524 }
88525- if (copy_to_user(dst, buf, retval))
88526+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88527 return -EFAULT;
88528 copied += retval;
88529 src += retval;
88530@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88531 bool seized = child->ptrace & PT_SEIZED;
88532 int ret = -EIO;
88533 siginfo_t siginfo, *si;
88534- void __user *datavp = (void __user *) data;
88535+ void __user *datavp = (__force void __user *) data;
88536 unsigned long __user *datalp = datavp;
88537 unsigned long flags;
88538
88539@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88540 goto out;
88541 }
88542
88543+ if (gr_handle_ptrace(child, request)) {
88544+ ret = -EPERM;
88545+ goto out_put_task_struct;
88546+ }
88547+
88548 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88549 ret = ptrace_attach(child, request, addr, data);
88550 /*
88551 * Some architectures need to do book-keeping after
88552 * a ptrace attach.
88553 */
88554- if (!ret)
88555+ if (!ret) {
88556 arch_ptrace_attach(child);
88557+ gr_audit_ptrace(child);
88558+ }
88559 goto out_put_task_struct;
88560 }
88561
88562@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88563 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88564 if (copied != sizeof(tmp))
88565 return -EIO;
88566- return put_user(tmp, (unsigned long __user *)data);
88567+ return put_user(tmp, (__force unsigned long __user *)data);
88568 }
88569
88570 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88571@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88572 }
88573
88574 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88575- compat_long_t addr, compat_long_t data)
88576+ compat_ulong_t addr, compat_ulong_t data)
88577 {
88578 struct task_struct *child;
88579 long ret;
88580@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88581 goto out;
88582 }
88583
88584+ if (gr_handle_ptrace(child, request)) {
88585+ ret = -EPERM;
88586+ goto out_put_task_struct;
88587+ }
88588+
88589 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88590 ret = ptrace_attach(child, request, addr, data);
88591 /*
88592 * Some architectures need to do book-keeping after
88593 * a ptrace attach.
88594 */
88595- if (!ret)
88596+ if (!ret) {
88597 arch_ptrace_attach(child);
88598+ gr_audit_ptrace(child);
88599+ }
88600 goto out_put_task_struct;
88601 }
88602
88603diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88604index 3318d82..1a5b2d1 100644
88605--- a/kernel/rcu/srcu.c
88606+++ b/kernel/rcu/srcu.c
88607@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88608
88609 idx = ACCESS_ONCE(sp->completed) & 0x1;
88610 preempt_disable();
88611- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88612+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88613 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88614- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88615+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88616 preempt_enable();
88617 return idx;
88618 }
88619diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88620index 1254f31..16258dc 100644
88621--- a/kernel/rcu/tiny.c
88622+++ b/kernel/rcu/tiny.c
88623@@ -46,7 +46,7 @@
88624 /* Forward declarations for tiny_plugin.h. */
88625 struct rcu_ctrlblk;
88626 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88627-static void rcu_process_callbacks(struct softirq_action *unused);
88628+static void rcu_process_callbacks(void);
88629 static void __call_rcu(struct rcu_head *head,
88630 void (*func)(struct rcu_head *rcu),
88631 struct rcu_ctrlblk *rcp);
88632@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88633 false));
88634 }
88635
88636-static void rcu_process_callbacks(struct softirq_action *unused)
88637+static __latent_entropy void rcu_process_callbacks(void)
88638 {
88639 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88640 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88641diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88642index 732f8ae..42c1919 100644
88643--- a/kernel/rcu/torture.c
88644+++ b/kernel/rcu/torture.c
88645@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88646 { 0 };
88647 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88648 { 0 };
88649-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88650-static atomic_t n_rcu_torture_alloc;
88651-static atomic_t n_rcu_torture_alloc_fail;
88652-static atomic_t n_rcu_torture_free;
88653-static atomic_t n_rcu_torture_mberror;
88654-static atomic_t n_rcu_torture_error;
88655+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88656+static atomic_unchecked_t n_rcu_torture_alloc;
88657+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88658+static atomic_unchecked_t n_rcu_torture_free;
88659+static atomic_unchecked_t n_rcu_torture_mberror;
88660+static atomic_unchecked_t n_rcu_torture_error;
88661 static long n_rcu_torture_barrier_error;
88662 static long n_rcu_torture_boost_ktrerror;
88663 static long n_rcu_torture_boost_rterror;
88664@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
88665
88666 spin_lock_bh(&rcu_torture_lock);
88667 if (list_empty(&rcu_torture_freelist)) {
88668- atomic_inc(&n_rcu_torture_alloc_fail);
88669+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88670 spin_unlock_bh(&rcu_torture_lock);
88671 return NULL;
88672 }
88673- atomic_inc(&n_rcu_torture_alloc);
88674+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88675 p = rcu_torture_freelist.next;
88676 list_del_init(p);
88677 spin_unlock_bh(&rcu_torture_lock);
88678@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88679 static void
88680 rcu_torture_free(struct rcu_torture *p)
88681 {
88682- atomic_inc(&n_rcu_torture_free);
88683+ atomic_inc_unchecked(&n_rcu_torture_free);
88684 spin_lock_bh(&rcu_torture_lock);
88685 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88686 spin_unlock_bh(&rcu_torture_lock);
88687@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88688 i = rp->rtort_pipe_count;
88689 if (i > RCU_TORTURE_PIPE_LEN)
88690 i = RCU_TORTURE_PIPE_LEN;
88691- atomic_inc(&rcu_torture_wcount[i]);
88692+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88693 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88694 rp->rtort_mbtest = 0;
88695 rcu_torture_free(rp);
88696@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
88697 i = old_rp->rtort_pipe_count;
88698 if (i > RCU_TORTURE_PIPE_LEN)
88699 i = RCU_TORTURE_PIPE_LEN;
88700- atomic_inc(&rcu_torture_wcount[i]);
88701+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88702 old_rp->rtort_pipe_count++;
88703 if (gp_normal == gp_exp)
88704 exp = !!(rcu_random(&rand) & 0x80);
88705@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
88706 i = rp->rtort_pipe_count;
88707 if (i > RCU_TORTURE_PIPE_LEN)
88708 i = RCU_TORTURE_PIPE_LEN;
88709- atomic_inc(&rcu_torture_wcount[i]);
88710+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88711 if (++rp->rtort_pipe_count >=
88712 RCU_TORTURE_PIPE_LEN) {
88713 rp->rtort_mbtest = 0;
88714@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
88715 return;
88716 }
88717 if (p->rtort_mbtest == 0)
88718- atomic_inc(&n_rcu_torture_mberror);
88719+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88720 spin_lock(&rand_lock);
88721 cur_ops->read_delay(&rand);
88722 n_rcu_torture_timers++;
88723@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
88724 continue;
88725 }
88726 if (p->rtort_mbtest == 0)
88727- atomic_inc(&n_rcu_torture_mberror);
88728+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88729 cur_ops->read_delay(&rand);
88730 preempt_disable();
88731 pipe_count = p->rtort_pipe_count;
88732@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
88733 }
88734 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
88735 page += sprintf(page,
88736- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88737+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88738 rcu_torture_current,
88739 rcu_torture_current_version,
88740 list_empty(&rcu_torture_freelist),
88741- atomic_read(&n_rcu_torture_alloc),
88742- atomic_read(&n_rcu_torture_alloc_fail),
88743- atomic_read(&n_rcu_torture_free));
88744+ atomic_read_unchecked(&n_rcu_torture_alloc),
88745+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88746+ atomic_read_unchecked(&n_rcu_torture_free));
88747 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88748- atomic_read(&n_rcu_torture_mberror),
88749+ atomic_read_unchecked(&n_rcu_torture_mberror),
88750 n_rcu_torture_boost_ktrerror,
88751 n_rcu_torture_boost_rterror);
88752 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88753@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
88754 n_barrier_attempts,
88755 n_rcu_torture_barrier_error);
88756 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88757- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88758+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88759 n_rcu_torture_barrier_error != 0 ||
88760 n_rcu_torture_boost_ktrerror != 0 ||
88761 n_rcu_torture_boost_rterror != 0 ||
88762 n_rcu_torture_boost_failure != 0 ||
88763 i > 1) {
88764 page += sprintf(page, "!!! ");
88765- atomic_inc(&n_rcu_torture_error);
88766+ atomic_inc_unchecked(&n_rcu_torture_error);
88767 WARN_ON_ONCE(1);
88768 }
88769 page += sprintf(page, "Reader Pipe: ");
88770@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
88771 page += sprintf(page, "Free-Block Circulation: ");
88772 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88773 page += sprintf(page, " %d",
88774- atomic_read(&rcu_torture_wcount[i]));
88775+ atomic_read_unchecked(&rcu_torture_wcount[i]));
88776 }
88777 page += sprintf(page, "\n");
88778 if (cur_ops->stats)
88779@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
88780
88781 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88782
88783- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88784+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88785 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88786 else if (n_online_successes != n_online_attempts ||
88787 n_offline_successes != n_offline_attempts)
88788@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
88789
88790 rcu_torture_current = NULL;
88791 rcu_torture_current_version = 0;
88792- atomic_set(&n_rcu_torture_alloc, 0);
88793- atomic_set(&n_rcu_torture_alloc_fail, 0);
88794- atomic_set(&n_rcu_torture_free, 0);
88795- atomic_set(&n_rcu_torture_mberror, 0);
88796- atomic_set(&n_rcu_torture_error, 0);
88797+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88798+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88799+ atomic_set_unchecked(&n_rcu_torture_free, 0);
88800+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88801+ atomic_set_unchecked(&n_rcu_torture_error, 0);
88802 n_rcu_torture_barrier_error = 0;
88803 n_rcu_torture_boost_ktrerror = 0;
88804 n_rcu_torture_boost_rterror = 0;
88805 n_rcu_torture_boost_failure = 0;
88806 n_rcu_torture_boosts = 0;
88807 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88808- atomic_set(&rcu_torture_wcount[i], 0);
88809+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88810 for_each_possible_cpu(cpu) {
88811 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88812 per_cpu(rcu_torture_count, cpu)[i] = 0;
88813diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88814index b3d116c..ebf6598 100644
88815--- a/kernel/rcu/tree.c
88816+++ b/kernel/rcu/tree.c
88817@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88818 rcu_prepare_for_idle(smp_processor_id());
88819 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88820 smp_mb__before_atomic_inc(); /* See above. */
88821- atomic_inc(&rdtp->dynticks);
88822+ atomic_inc_unchecked(&rdtp->dynticks);
88823 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88824- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88825+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88826
88827 /*
88828 * It is illegal to enter an extended quiescent state while
88829@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88830 int user)
88831 {
88832 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88833- atomic_inc(&rdtp->dynticks);
88834+ atomic_inc_unchecked(&rdtp->dynticks);
88835 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88836 smp_mb__after_atomic_inc(); /* See above. */
88837- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88838+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88839 rcu_cleanup_after_idle(smp_processor_id());
88840 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88841 if (!user && !is_idle_task(current)) {
88842@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
88843 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88844
88845 if (rdtp->dynticks_nmi_nesting == 0 &&
88846- (atomic_read(&rdtp->dynticks) & 0x1))
88847+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88848 return;
88849 rdtp->dynticks_nmi_nesting++;
88850 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88851- atomic_inc(&rdtp->dynticks);
88852+ atomic_inc_unchecked(&rdtp->dynticks);
88853 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88854 smp_mb__after_atomic_inc(); /* See above. */
88855- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88856+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88857 }
88858
88859 /**
88860@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
88861 return;
88862 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88863 smp_mb__before_atomic_inc(); /* See above. */
88864- atomic_inc(&rdtp->dynticks);
88865+ atomic_inc_unchecked(&rdtp->dynticks);
88866 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88867- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88868+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88869 }
88870
88871 /**
88872@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
88873 */
88874 bool notrace __rcu_is_watching(void)
88875 {
88876- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88877+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88878 }
88879
88880 /**
88881@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88882 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88883 bool *isidle, unsigned long *maxj)
88884 {
88885- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88886+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88887 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88888 return (rdp->dynticks_snap & 0x1) == 0;
88889 }
88890@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88891 unsigned int curr;
88892 unsigned int snap;
88893
88894- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88895+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88896 snap = (unsigned int)rdp->dynticks_snap;
88897
88898 /*
88899@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88900 rdp = this_cpu_ptr(rsp->rda);
88901 rcu_preempt_check_blocked_tasks(rnp);
88902 rnp->qsmask = rnp->qsmaskinit;
88903- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88904+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88905 WARN_ON_ONCE(rnp->completed != rsp->completed);
88906- ACCESS_ONCE(rnp->completed) = rsp->completed;
88907+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88908 if (rnp == rdp->mynode)
88909 __note_gp_changes(rsp, rnp, rdp);
88910 rcu_preempt_boost_start_gp(rnp);
88911@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88912 rcu_for_each_node_breadth_first(rsp, rnp) {
88913 raw_spin_lock_irq(&rnp->lock);
88914 smp_mb__after_unlock_lock();
88915- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88916+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88917 rdp = this_cpu_ptr(rsp->rda);
88918 if (rnp == rdp->mynode)
88919 __note_gp_changes(rsp, rnp, rdp);
88920@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88921 rsp->qlen += rdp->qlen;
88922 rdp->n_cbs_orphaned += rdp->qlen;
88923 rdp->qlen_lazy = 0;
88924- ACCESS_ONCE(rdp->qlen) = 0;
88925+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88926 }
88927
88928 /*
88929@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88930 }
88931 smp_mb(); /* List handling before counting for rcu_barrier(). */
88932 rdp->qlen_lazy -= count_lazy;
88933- ACCESS_ONCE(rdp->qlen) -= count;
88934+ ACCESS_ONCE_RW(rdp->qlen) -= count;
88935 rdp->n_cbs_invoked += count;
88936
88937 /* Reinstate batch limit if we have worked down the excess. */
88938@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88939 /*
88940 * Do RCU core processing for the current CPU.
88941 */
88942-static void rcu_process_callbacks(struct softirq_action *unused)
88943+static void rcu_process_callbacks(void)
88944 {
88945 struct rcu_state *rsp;
88946
88947@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88948 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88949 if (debug_rcu_head_queue(head)) {
88950 /* Probable double call_rcu(), so leak the callback. */
88951- ACCESS_ONCE(head->func) = rcu_leak_callback;
88952+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88953 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88954 return;
88955 }
88956@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88957 local_irq_restore(flags);
88958 return;
88959 }
88960- ACCESS_ONCE(rdp->qlen)++;
88961+ ACCESS_ONCE_RW(rdp->qlen)++;
88962 if (lazy)
88963 rdp->qlen_lazy++;
88964 else
88965@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
88966 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88967 * course be required on a 64-bit system.
88968 */
88969- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88970+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88971 (ulong)atomic_long_read(&rsp->expedited_done) +
88972 ULONG_MAX / 8)) {
88973 synchronize_sched();
88974- atomic_long_inc(&rsp->expedited_wrap);
88975+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
88976 return;
88977 }
88978
88979@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
88980 * Take a ticket. Note that atomic_inc_return() implies a
88981 * full memory barrier.
88982 */
88983- snap = atomic_long_inc_return(&rsp->expedited_start);
88984+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88985 firstsnap = snap;
88986 get_online_cpus();
88987 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88988@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
88989 synchronize_sched_expedited_cpu_stop,
88990 NULL) == -EAGAIN) {
88991 put_online_cpus();
88992- atomic_long_inc(&rsp->expedited_tryfail);
88993+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88994
88995 /* Check to see if someone else did our work for us. */
88996 s = atomic_long_read(&rsp->expedited_done);
88997 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88998 /* ensure test happens before caller kfree */
88999 smp_mb__before_atomic_inc(); /* ^^^ */
89000- atomic_long_inc(&rsp->expedited_workdone1);
89001+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89002 return;
89003 }
89004
89005@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
89006 udelay(trycount * num_online_cpus());
89007 } else {
89008 wait_rcu_gp(call_rcu_sched);
89009- atomic_long_inc(&rsp->expedited_normal);
89010+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89011 return;
89012 }
89013
89014@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
89015 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89016 /* ensure test happens before caller kfree */
89017 smp_mb__before_atomic_inc(); /* ^^^ */
89018- atomic_long_inc(&rsp->expedited_workdone2);
89019+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89020 return;
89021 }
89022
89023@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
89024 * period works for us.
89025 */
89026 get_online_cpus();
89027- snap = atomic_long_read(&rsp->expedited_start);
89028+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89029 smp_mb(); /* ensure read is before try_stop_cpus(). */
89030 }
89031- atomic_long_inc(&rsp->expedited_stoppedcpus);
89032+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89033
89034 /*
89035 * Everyone up to our most recent fetch is covered by our grace
89036@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
89037 * than we did already did their update.
89038 */
89039 do {
89040- atomic_long_inc(&rsp->expedited_done_tries);
89041+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89042 s = atomic_long_read(&rsp->expedited_done);
89043 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89044 /* ensure test happens before caller kfree */
89045 smp_mb__before_atomic_inc(); /* ^^^ */
89046- atomic_long_inc(&rsp->expedited_done_lost);
89047+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89048 break;
89049 }
89050 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89051- atomic_long_inc(&rsp->expedited_done_exit);
89052+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89053
89054 put_online_cpus();
89055 }
89056@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89057 * ACCESS_ONCE() to prevent the compiler from speculating
89058 * the increment to precede the early-exit check.
89059 */
89060- ACCESS_ONCE(rsp->n_barrier_done)++;
89061+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89062 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89063 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89064 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89065@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89066
89067 /* Increment ->n_barrier_done to prevent duplicate work. */
89068 smp_mb(); /* Keep increment after above mechanism. */
89069- ACCESS_ONCE(rsp->n_barrier_done)++;
89070+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89071 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89072 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89073 smp_mb(); /* Keep increment before caller's subsequent code. */
89074@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89075 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89076 init_callback_list(rdp);
89077 rdp->qlen_lazy = 0;
89078- ACCESS_ONCE(rdp->qlen) = 0;
89079+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89080 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89081 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89082- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89083+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89084 rdp->cpu = cpu;
89085 rdp->rsp = rsp;
89086 rcu_boot_init_nocb_percpu_data(rdp);
89087@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89088 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89089 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89090 rcu_sysidle_init_percpu_data(rdp->dynticks);
89091- atomic_set(&rdp->dynticks->dynticks,
89092- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89093+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89094+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89095 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89096
89097 /* Add CPU to rcu_node bitmasks. */
89098diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89099index 8c19873..bf83c57 100644
89100--- a/kernel/rcu/tree.h
89101+++ b/kernel/rcu/tree.h
89102@@ -87,11 +87,11 @@ struct rcu_dynticks {
89103 long long dynticks_nesting; /* Track irq/process nesting level. */
89104 /* Process level is worth LLONG_MAX/2. */
89105 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89106- atomic_t dynticks; /* Even value for idle, else odd. */
89107+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89108 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89109 long long dynticks_idle_nesting;
89110 /* irq/process nesting level from idle. */
89111- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89112+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89113 /* "Idle" excludes userspace execution. */
89114 unsigned long dynticks_idle_jiffies;
89115 /* End of last non-NMI non-idle period. */
89116@@ -431,17 +431,17 @@ struct rcu_state {
89117 /* _rcu_barrier(). */
89118 /* End of fields guarded by barrier_mutex. */
89119
89120- atomic_long_t expedited_start; /* Starting ticket. */
89121- atomic_long_t expedited_done; /* Done ticket. */
89122- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89123- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89124- atomic_long_t expedited_workdone1; /* # done by others #1. */
89125- atomic_long_t expedited_workdone2; /* # done by others #2. */
89126- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89127- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89128- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89129- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89130- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89131+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89132+ atomic_long_t expedited_done; /* Done ticket. */
89133+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89134+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89135+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89136+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89137+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89138+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89139+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89140+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89141+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89142
89143 unsigned long jiffies_force_qs; /* Time at which to invoke */
89144 /* force_quiescent_state(). */
89145diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89146index 6e2ef4b..c15df94 100644
89147--- a/kernel/rcu/tree_plugin.h
89148+++ b/kernel/rcu/tree_plugin.h
89149@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89150 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89151 {
89152 return !rcu_preempted_readers_exp(rnp) &&
89153- ACCESS_ONCE(rnp->expmask) == 0;
89154+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89155 }
89156
89157 /*
89158@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89159
89160 /* Clean up and exit. */
89161 smp_mb(); /* ensure expedited GP seen before counter increment. */
89162- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89163+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89164 unlock_mb_ret:
89165 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89166 mb_ret:
89167@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89168 free_cpumask_var(cm);
89169 }
89170
89171-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89172+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89173 .store = &rcu_cpu_kthread_task,
89174 .thread_should_run = rcu_cpu_kthread_should_run,
89175 .thread_fn = rcu_cpu_kthread,
89176@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89177 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89178 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89179 cpu, ticks_value, ticks_title,
89180- atomic_read(&rdtp->dynticks) & 0xfff,
89181+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89182 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89183 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89184 fast_no_hz);
89185@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89186
89187 /* Enqueue the callback on the nocb list and update counts. */
89188 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89189- ACCESS_ONCE(*old_rhpp) = rhp;
89190+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89191 atomic_long_add(rhcount, &rdp->nocb_q_count);
89192 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89193
89194@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89195 * Extract queued callbacks, update counts, and wait
89196 * for a grace period to elapse.
89197 */
89198- ACCESS_ONCE(rdp->nocb_head) = NULL;
89199+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89200 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89201 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89202 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89203- ACCESS_ONCE(rdp->nocb_p_count) += c;
89204- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89205+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89206+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89207 rcu_nocb_wait_gp(rdp);
89208
89209 /* Each pass through the following loop invokes a callback. */
89210@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89211 list = next;
89212 }
89213 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89214- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89215- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89216+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89217+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89218 rdp->n_nocbs_invoked += c;
89219 }
89220 return 0;
89221@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89222 {
89223 if (!rcu_nocb_need_deferred_wakeup(rdp))
89224 return;
89225- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89226+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89227 wake_up(&rdp->nocb_wq);
89228 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89229 }
89230@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89231 t = kthread_run(rcu_nocb_kthread, rdp,
89232 "rcuo%c/%d", rsp->abbr, cpu);
89233 BUG_ON(IS_ERR(t));
89234- ACCESS_ONCE(rdp->nocb_kthread) = t;
89235+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89236 }
89237 }
89238
89239@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89240
89241 /* Record start of fully idle period. */
89242 j = jiffies;
89243- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89244+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89245 smp_mb__before_atomic_inc();
89246- atomic_inc(&rdtp->dynticks_idle);
89247+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89248 smp_mb__after_atomic_inc();
89249- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89250+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89251 }
89252
89253 /*
89254@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89255
89256 /* Record end of idle period. */
89257 smp_mb__before_atomic_inc();
89258- atomic_inc(&rdtp->dynticks_idle);
89259+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89260 smp_mb__after_atomic_inc();
89261- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89262+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89263
89264 /*
89265 * If we are the timekeeping CPU, we are permitted to be non-idle
89266@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89267 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89268
89269 /* Pick up current idle and NMI-nesting counter and check. */
89270- cur = atomic_read(&rdtp->dynticks_idle);
89271+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89272 if (cur & 0x1) {
89273 *isidle = false; /* We are not idle! */
89274 return;
89275@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89276 case RCU_SYSIDLE_NOT:
89277
89278 /* First time all are idle, so note a short idle period. */
89279- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89280+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89281 break;
89282
89283 case RCU_SYSIDLE_SHORT:
89284@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89285 static void rcu_sysidle_cancel(void)
89286 {
89287 smp_mb();
89288- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89289+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89290 }
89291
89292 /*
89293@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89294 smp_mb(); /* grace period precedes setting inuse. */
89295
89296 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89297- ACCESS_ONCE(rshp->inuse) = 0;
89298+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89299 }
89300
89301 /*
89302diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89303index 4def475..8ffddde 100644
89304--- a/kernel/rcu/tree_trace.c
89305+++ b/kernel/rcu/tree_trace.c
89306@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89307 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89308 rdp->passed_quiesce, rdp->qs_pending);
89309 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89310- atomic_read(&rdp->dynticks->dynticks),
89311+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89312 rdp->dynticks->dynticks_nesting,
89313 rdp->dynticks->dynticks_nmi_nesting,
89314 rdp->dynticks_fqs);
89315@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89316 struct rcu_state *rsp = (struct rcu_state *)m->private;
89317
89318 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",
89319- atomic_long_read(&rsp->expedited_start),
89320+ atomic_long_read_unchecked(&rsp->expedited_start),
89321 atomic_long_read(&rsp->expedited_done),
89322- atomic_long_read(&rsp->expedited_wrap),
89323- atomic_long_read(&rsp->expedited_tryfail),
89324- atomic_long_read(&rsp->expedited_workdone1),
89325- atomic_long_read(&rsp->expedited_workdone2),
89326- atomic_long_read(&rsp->expedited_normal),
89327- atomic_long_read(&rsp->expedited_stoppedcpus),
89328- atomic_long_read(&rsp->expedited_done_tries),
89329- atomic_long_read(&rsp->expedited_done_lost),
89330- atomic_long_read(&rsp->expedited_done_exit));
89331+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89332+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89333+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89334+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89335+ atomic_long_read_unchecked(&rsp->expedited_normal),
89336+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89337+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89338+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89339+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89340 return 0;
89341 }
89342
89343diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89344index c54609f..2e8829c 100644
89345--- a/kernel/rcu/update.c
89346+++ b/kernel/rcu/update.c
89347@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89348 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89349 */
89350 if (till_stall_check < 3) {
89351- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89352+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89353 till_stall_check = 3;
89354 } else if (till_stall_check > 300) {
89355- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89356+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89357 till_stall_check = 300;
89358 }
89359 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89360diff --git a/kernel/resource.c b/kernel/resource.c
89361index 3f285dc..5755f62 100644
89362--- a/kernel/resource.c
89363+++ b/kernel/resource.c
89364@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89365
89366 static int __init ioresources_init(void)
89367 {
89368+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89369+#ifdef CONFIG_GRKERNSEC_PROC_USER
89370+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89371+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89372+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89373+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89374+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89375+#endif
89376+#else
89377 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89378 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89379+#endif
89380 return 0;
89381 }
89382 __initcall(ioresources_init);
89383diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89384index 4a07353..66b5291 100644
89385--- a/kernel/sched/auto_group.c
89386+++ b/kernel/sched/auto_group.c
89387@@ -11,7 +11,7 @@
89388
89389 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89390 static struct autogroup autogroup_default;
89391-static atomic_t autogroup_seq_nr;
89392+static atomic_unchecked_t autogroup_seq_nr;
89393
89394 void __init autogroup_init(struct task_struct *init_task)
89395 {
89396@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89397
89398 kref_init(&ag->kref);
89399 init_rwsem(&ag->lock);
89400- ag->id = atomic_inc_return(&autogroup_seq_nr);
89401+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89402 ag->tg = tg;
89403 #ifdef CONFIG_RT_GROUP_SCHED
89404 /*
89405diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89406index a63f4dc..349bbb0 100644
89407--- a/kernel/sched/completion.c
89408+++ b/kernel/sched/completion.c
89409@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89410 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89411 * or number of jiffies left till timeout) if completed.
89412 */
89413-long __sched
89414+long __sched __intentional_overflow(-1)
89415 wait_for_completion_interruptible_timeout(struct completion *x,
89416 unsigned long timeout)
89417 {
89418@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89419 *
89420 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89421 */
89422-int __sched wait_for_completion_killable(struct completion *x)
89423+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89424 {
89425 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89426 if (t == -ERESTARTSYS)
89427@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89428 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89429 * or number of jiffies left till timeout) if completed.
89430 */
89431-long __sched
89432+long __sched __intentional_overflow(-1)
89433 wait_for_completion_killable_timeout(struct completion *x,
89434 unsigned long timeout)
89435 {
89436diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89437index f5c6635..ab9f223 100644
89438--- a/kernel/sched/core.c
89439+++ b/kernel/sched/core.c
89440@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89441 int sysctl_numa_balancing(struct ctl_table *table, int write,
89442 void __user *buffer, size_t *lenp, loff_t *ppos)
89443 {
89444- struct ctl_table t;
89445+ ctl_table_no_const t;
89446 int err;
89447 int state = numabalancing_enabled;
89448
89449@@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
89450 /* convert nice value [19,-20] to rlimit style value [1,40] */
89451 int nice_rlim = 20 - nice;
89452
89453+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89454+
89455 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89456 capable(CAP_SYS_NICE));
89457 }
89458@@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89459 if (nice > 19)
89460 nice = 19;
89461
89462- if (increment < 0 && !can_nice(current, nice))
89463+ if (increment < 0 && (!can_nice(current, nice) ||
89464+ gr_handle_chroot_nice()))
89465 return -EPERM;
89466
89467 retval = security_task_setnice(current, nice);
89468@@ -3332,6 +3335,7 @@ recheck:
89469 if (policy != p->policy && !rlim_rtprio)
89470 return -EPERM;
89471
89472+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89473 /* can't increase priority */
89474 if (attr->sched_priority > p->rt_priority &&
89475 attr->sched_priority > rlim_rtprio)
89476@@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89477
89478 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89479
89480-static struct ctl_table sd_ctl_dir[] = {
89481+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89482 {
89483 .procname = "sched_domain",
89484 .mode = 0555,
89485@@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89486 {}
89487 };
89488
89489-static struct ctl_table *sd_alloc_ctl_entry(int n)
89490+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89491 {
89492- struct ctl_table *entry =
89493+ ctl_table_no_const *entry =
89494 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89495
89496 return entry;
89497 }
89498
89499-static void sd_free_ctl_entry(struct ctl_table **tablep)
89500+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89501 {
89502- struct ctl_table *entry;
89503+ ctl_table_no_const *entry;
89504
89505 /*
89506 * In the intermediate directories, both the child directory and
89507@@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89508 * will always be set. In the lowest directory the names are
89509 * static strings and all have proc handlers.
89510 */
89511- for (entry = *tablep; entry->mode; entry++) {
89512- if (entry->child)
89513- sd_free_ctl_entry(&entry->child);
89514+ for (entry = tablep; entry->mode; entry++) {
89515+ if (entry->child) {
89516+ sd_free_ctl_entry(entry->child);
89517+ pax_open_kernel();
89518+ entry->child = NULL;
89519+ pax_close_kernel();
89520+ }
89521 if (entry->proc_handler == NULL)
89522 kfree(entry->procname);
89523 }
89524
89525- kfree(*tablep);
89526- *tablep = NULL;
89527+ kfree(tablep);
89528 }
89529
89530 static int min_load_idx = 0;
89531 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89532
89533 static void
89534-set_table_entry(struct ctl_table *entry,
89535+set_table_entry(ctl_table_no_const *entry,
89536 const char *procname, void *data, int maxlen,
89537 umode_t mode, proc_handler *proc_handler,
89538 bool load_idx)
89539@@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89540 static struct ctl_table *
89541 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89542 {
89543- struct ctl_table *table = sd_alloc_ctl_entry(13);
89544+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89545
89546 if (table == NULL)
89547 return NULL;
89548@@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89549 return table;
89550 }
89551
89552-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89553+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89554 {
89555- struct ctl_table *entry, *table;
89556+ ctl_table_no_const *entry, *table;
89557 struct sched_domain *sd;
89558 int domain_num = 0, i;
89559 char buf[32];
89560@@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89561 static void register_sched_domain_sysctl(void)
89562 {
89563 int i, cpu_num = num_possible_cpus();
89564- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89565+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89566 char buf[32];
89567
89568 WARN_ON(sd_ctl_dir[0].child);
89569+ pax_open_kernel();
89570 sd_ctl_dir[0].child = entry;
89571+ pax_close_kernel();
89572
89573 if (entry == NULL)
89574 return;
89575@@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89576 if (sd_sysctl_header)
89577 unregister_sysctl_table(sd_sysctl_header);
89578 sd_sysctl_header = NULL;
89579- if (sd_ctl_dir[0].child)
89580- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89581+ if (sd_ctl_dir[0].child) {
89582+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89583+ pax_open_kernel();
89584+ sd_ctl_dir[0].child = NULL;
89585+ pax_close_kernel();
89586+ }
89587 }
89588 #else
89589 static void register_sched_domain_sysctl(void)
89590diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89591index 9b4c4f3..665489b 100644
89592--- a/kernel/sched/fair.c
89593+++ b/kernel/sched/fair.c
89594@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89595
89596 static void reset_ptenuma_scan(struct task_struct *p)
89597 {
89598- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89599+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89600 p->mm->numa_scan_offset = 0;
89601 }
89602
89603@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89604 * run_rebalance_domains is triggered when needed from the scheduler tick.
89605 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89606 */
89607-static void run_rebalance_domains(struct softirq_action *h)
89608+static __latent_entropy void run_rebalance_domains(void)
89609 {
89610 struct rq *this_rq = this_rq();
89611 enum cpu_idle_type idle = this_rq->idle_balance ?
89612diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89613index f964add..dcd823d 100644
89614--- a/kernel/sched/sched.h
89615+++ b/kernel/sched/sched.h
89616@@ -1157,7 +1157,7 @@ struct sched_class {
89617 #ifdef CONFIG_FAIR_GROUP_SCHED
89618 void (*task_move_group) (struct task_struct *p, int on_rq);
89619 #endif
89620-};
89621+} __do_const;
89622
89623 #define sched_class_highest (&stop_sched_class)
89624 #define for_each_class(class) \
89625diff --git a/kernel/signal.c b/kernel/signal.c
89626index 52f881d..1e9f941 100644
89627--- a/kernel/signal.c
89628+++ b/kernel/signal.c
89629@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89630
89631 int print_fatal_signals __read_mostly;
89632
89633-static void __user *sig_handler(struct task_struct *t, int sig)
89634+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89635 {
89636 return t->sighand->action[sig - 1].sa.sa_handler;
89637 }
89638
89639-static int sig_handler_ignored(void __user *handler, int sig)
89640+static int sig_handler_ignored(__sighandler_t handler, int sig)
89641 {
89642 /* Is it explicitly or implicitly ignored? */
89643 return handler == SIG_IGN ||
89644@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89645
89646 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89647 {
89648- void __user *handler;
89649+ __sighandler_t handler;
89650
89651 handler = sig_handler(t, sig);
89652
89653@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89654 atomic_inc(&user->sigpending);
89655 rcu_read_unlock();
89656
89657+ if (!override_rlimit)
89658+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89659+
89660 if (override_rlimit ||
89661 atomic_read(&user->sigpending) <=
89662 task_rlimit(t, RLIMIT_SIGPENDING)) {
89663@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89664
89665 int unhandled_signal(struct task_struct *tsk, int sig)
89666 {
89667- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89668+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89669 if (is_global_init(tsk))
89670 return 1;
89671 if (handler != SIG_IGN && handler != SIG_DFL)
89672@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89673 }
89674 }
89675
89676+ /* allow glibc communication via tgkill to other threads in our
89677+ thread group */
89678+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89679+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89680+ && gr_handle_signal(t, sig))
89681+ return -EPERM;
89682+
89683 return security_task_kill(t, info, sig, 0);
89684 }
89685
89686@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89687 return send_signal(sig, info, p, 1);
89688 }
89689
89690-static int
89691+int
89692 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89693 {
89694 return send_signal(sig, info, t, 0);
89695@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89696 unsigned long int flags;
89697 int ret, blocked, ignored;
89698 struct k_sigaction *action;
89699+ int is_unhandled = 0;
89700
89701 spin_lock_irqsave(&t->sighand->siglock, flags);
89702 action = &t->sighand->action[sig-1];
89703@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89704 }
89705 if (action->sa.sa_handler == SIG_DFL)
89706 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89707+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89708+ is_unhandled = 1;
89709 ret = specific_send_sig_info(sig, info, t);
89710 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89711
89712+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
89713+ normal operation */
89714+ if (is_unhandled) {
89715+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89716+ gr_handle_crash(t, sig);
89717+ }
89718+
89719 return ret;
89720 }
89721
89722@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89723 ret = check_kill_permission(sig, info, p);
89724 rcu_read_unlock();
89725
89726- if (!ret && sig)
89727+ if (!ret && sig) {
89728 ret = do_send_sig_info(sig, info, p, true);
89729+ if (!ret)
89730+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89731+ }
89732
89733 return ret;
89734 }
89735@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89736 int error = -ESRCH;
89737
89738 rcu_read_lock();
89739- p = find_task_by_vpid(pid);
89740+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89741+ /* allow glibc communication via tgkill to other threads in our
89742+ thread group */
89743+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89744+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
89745+ p = find_task_by_vpid_unrestricted(pid);
89746+ else
89747+#endif
89748+ p = find_task_by_vpid(pid);
89749 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89750 error = check_kill_permission(sig, info, p);
89751 /*
89752@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89753 }
89754 seg = get_fs();
89755 set_fs(KERNEL_DS);
89756- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89757- (stack_t __force __user *) &uoss,
89758+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89759+ (stack_t __force_user *) &uoss,
89760 compat_user_stack_pointer());
89761 set_fs(seg);
89762 if (ret >= 0 && uoss_ptr) {
89763diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89764index eb89e18..a4e6792 100644
89765--- a/kernel/smpboot.c
89766+++ b/kernel/smpboot.c
89767@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89768 }
89769 smpboot_unpark_thread(plug_thread, cpu);
89770 }
89771- list_add(&plug_thread->list, &hotplug_threads);
89772+ pax_list_add(&plug_thread->list, &hotplug_threads);
89773 out:
89774 mutex_unlock(&smpboot_threads_lock);
89775 return ret;
89776@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89777 {
89778 get_online_cpus();
89779 mutex_lock(&smpboot_threads_lock);
89780- list_del(&plug_thread->list);
89781+ pax_list_del(&plug_thread->list);
89782 smpboot_destroy_threads(plug_thread);
89783 mutex_unlock(&smpboot_threads_lock);
89784 put_online_cpus();
89785diff --git a/kernel/softirq.c b/kernel/softirq.c
89786index 490fcbb..1e502c6 100644
89787--- a/kernel/softirq.c
89788+++ b/kernel/softirq.c
89789@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89790 EXPORT_SYMBOL(irq_stat);
89791 #endif
89792
89793-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89794+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89795
89796 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89797
89798@@ -267,7 +267,7 @@ restart:
89799 kstat_incr_softirqs_this_cpu(vec_nr);
89800
89801 trace_softirq_entry(vec_nr);
89802- h->action(h);
89803+ h->action();
89804 trace_softirq_exit(vec_nr);
89805 if (unlikely(prev_count != preempt_count())) {
89806 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
89807@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89808 or_softirq_pending(1UL << nr);
89809 }
89810
89811-void open_softirq(int nr, void (*action)(struct softirq_action *))
89812+void __init open_softirq(int nr, void (*action)(void))
89813 {
89814 softirq_vec[nr].action = action;
89815 }
89816@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89817 }
89818 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89819
89820-static void tasklet_action(struct softirq_action *a)
89821+static void tasklet_action(void)
89822 {
89823 struct tasklet_struct *list;
89824
89825@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
89826 }
89827 }
89828
89829-static void tasklet_hi_action(struct softirq_action *a)
89830+static __latent_entropy void tasklet_hi_action(void)
89831 {
89832 struct tasklet_struct *list;
89833
89834@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
89835 .notifier_call = cpu_callback
89836 };
89837
89838-static struct smp_hotplug_thread softirq_threads = {
89839+static struct smp_hotplug_thread softirq_threads __read_only = {
89840 .store = &ksoftirqd,
89841 .thread_should_run = ksoftirqd_should_run,
89842 .thread_fn = run_ksoftirqd,
89843diff --git a/kernel/sys.c b/kernel/sys.c
89844index c0a58be..784c618 100644
89845--- a/kernel/sys.c
89846+++ b/kernel/sys.c
89847@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89848 error = -EACCES;
89849 goto out;
89850 }
89851+
89852+ if (gr_handle_chroot_setpriority(p, niceval)) {
89853+ error = -EACCES;
89854+ goto out;
89855+ }
89856+
89857 no_nice = security_task_setnice(p, niceval);
89858 if (no_nice) {
89859 error = no_nice;
89860@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89861 goto error;
89862 }
89863
89864+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89865+ goto error;
89866+
89867 if (rgid != (gid_t) -1 ||
89868 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89869 new->sgid = new->egid;
89870@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89871 old = current_cred();
89872
89873 retval = -EPERM;
89874+
89875+ if (gr_check_group_change(kgid, kgid, kgid))
89876+ goto error;
89877+
89878 if (ns_capable(old->user_ns, CAP_SETGID))
89879 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89880 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89881@@ -403,7 +416,7 @@ error:
89882 /*
89883 * change the user struct in a credentials set to match the new UID
89884 */
89885-static int set_user(struct cred *new)
89886+int set_user(struct cred *new)
89887 {
89888 struct user_struct *new_user;
89889
89890@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89891 goto error;
89892 }
89893
89894+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89895+ goto error;
89896+
89897 if (!uid_eq(new->uid, old->uid)) {
89898 retval = set_user(new);
89899 if (retval < 0)
89900@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89901 old = current_cred();
89902
89903 retval = -EPERM;
89904+
89905+ if (gr_check_crash_uid(kuid))
89906+ goto error;
89907+ if (gr_check_user_change(kuid, kuid, kuid))
89908+ goto error;
89909+
89910 if (ns_capable(old->user_ns, CAP_SETUID)) {
89911 new->suid = new->uid = kuid;
89912 if (!uid_eq(kuid, old->uid)) {
89913@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89914 goto error;
89915 }
89916
89917+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
89918+ goto error;
89919+
89920 if (ruid != (uid_t) -1) {
89921 new->uid = kruid;
89922 if (!uid_eq(kruid, old->uid)) {
89923@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89924 goto error;
89925 }
89926
89927+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
89928+ goto error;
89929+
89930 if (rgid != (gid_t) -1)
89931 new->gid = krgid;
89932 if (egid != (gid_t) -1)
89933@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89934 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89935 ns_capable(old->user_ns, CAP_SETUID)) {
89936 if (!uid_eq(kuid, old->fsuid)) {
89937+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89938+ goto error;
89939+
89940 new->fsuid = kuid;
89941 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89942 goto change_okay;
89943 }
89944 }
89945
89946+error:
89947 abort_creds(new);
89948 return old_fsuid;
89949
89950@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89951 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89952 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89953 ns_capable(old->user_ns, CAP_SETGID)) {
89954+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89955+ goto error;
89956+
89957 if (!gid_eq(kgid, old->fsgid)) {
89958 new->fsgid = kgid;
89959 goto change_okay;
89960 }
89961 }
89962
89963+error:
89964 abort_creds(new);
89965 return old_fsgid;
89966
89967@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89968 return -EFAULT;
89969
89970 down_read(&uts_sem);
89971- error = __copy_to_user(&name->sysname, &utsname()->sysname,
89972+ error = __copy_to_user(name->sysname, &utsname()->sysname,
89973 __OLD_UTS_LEN);
89974 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89975- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89976+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
89977 __OLD_UTS_LEN);
89978 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89979- error |= __copy_to_user(&name->release, &utsname()->release,
89980+ error |= __copy_to_user(name->release, &utsname()->release,
89981 __OLD_UTS_LEN);
89982 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89983- error |= __copy_to_user(&name->version, &utsname()->version,
89984+ error |= __copy_to_user(name->version, &utsname()->version,
89985 __OLD_UTS_LEN);
89986 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89987- error |= __copy_to_user(&name->machine, &utsname()->machine,
89988+ error |= __copy_to_user(name->machine, &utsname()->machine,
89989 __OLD_UTS_LEN);
89990 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89991 up_read(&uts_sem);
89992@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89993 */
89994 new_rlim->rlim_cur = 1;
89995 }
89996+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89997+ is changed to a lower value. Since tasks can be created by the same
89998+ user in between this limit change and an execve by this task, force
89999+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90000+ */
90001+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90002+ tsk->flags |= PF_NPROC_EXCEEDED;
90003 }
90004 if (!retval) {
90005 if (old_rlim)
90006diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90007index aae21e8..58d8c9a 100644
90008--- a/kernel/sysctl.c
90009+++ b/kernel/sysctl.c
90010@@ -94,7 +94,6 @@
90011
90012
90013 #if defined(CONFIG_SYSCTL)
90014-
90015 /* External variables not in a header file. */
90016 extern int max_threads;
90017 extern int suid_dumpable;
90018@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
90019
90020 /* Constants used for minimum and maximum */
90021 #ifdef CONFIG_LOCKUP_DETECTOR
90022-static int sixty = 60;
90023+static int sixty __read_only = 60;
90024 #endif
90025
90026-static int __maybe_unused neg_one = -1;
90027-
90028-static int zero;
90029-static int __maybe_unused one = 1;
90030-static int __maybe_unused two = 2;
90031-static int __maybe_unused three = 3;
90032-static unsigned long one_ul = 1;
90033-static int one_hundred = 100;
90034+static int __maybe_unused neg_one __read_only = -1;
90035+static int zero __read_only = 0;
90036+static int __maybe_unused one __read_only = 1;
90037+static int __maybe_unused two __read_only = 2;
90038+static int __maybe_unused three __read_only = 3;
90039+static unsigned long one_ul __read_only = 1;
90040+static int one_hundred __read_only = 100;
90041 #ifdef CONFIG_PRINTK
90042-static int ten_thousand = 10000;
90043+static int ten_thousand __read_only = 10000;
90044 #endif
90045
90046 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90047@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
90048 void __user *buffer, size_t *lenp, loff_t *ppos);
90049 #endif
90050
90051-#ifdef CONFIG_PRINTK
90052 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90053 void __user *buffer, size_t *lenp, loff_t *ppos);
90054-#endif
90055
90056 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90057 void __user *buffer, size_t *lenp, loff_t *ppos);
90058@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90059
90060 #endif
90061
90062+extern struct ctl_table grsecurity_table[];
90063+
90064 static struct ctl_table kern_table[];
90065 static struct ctl_table vm_table[];
90066 static struct ctl_table fs_table[];
90067@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
90068 int sysctl_legacy_va_layout;
90069 #endif
90070
90071+#ifdef CONFIG_PAX_SOFTMODE
90072+static ctl_table pax_table[] = {
90073+ {
90074+ .procname = "softmode",
90075+ .data = &pax_softmode,
90076+ .maxlen = sizeof(unsigned int),
90077+ .mode = 0600,
90078+ .proc_handler = &proc_dointvec,
90079+ },
90080+
90081+ { }
90082+};
90083+#endif
90084+
90085 /* The default sysctl tables: */
90086
90087 static struct ctl_table sysctl_base_table[] = {
90088@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
90089 #endif
90090
90091 static struct ctl_table kern_table[] = {
90092+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90093+ {
90094+ .procname = "grsecurity",
90095+ .mode = 0500,
90096+ .child = grsecurity_table,
90097+ },
90098+#endif
90099+
90100+#ifdef CONFIG_PAX_SOFTMODE
90101+ {
90102+ .procname = "pax",
90103+ .mode = 0500,
90104+ .child = pax_table,
90105+ },
90106+#endif
90107+
90108 {
90109 .procname = "sched_child_runs_first",
90110 .data = &sysctl_sched_child_runs_first,
90111@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
90112 .data = &modprobe_path,
90113 .maxlen = KMOD_PATH_LEN,
90114 .mode = 0644,
90115- .proc_handler = proc_dostring,
90116+ .proc_handler = proc_dostring_modpriv,
90117 },
90118 {
90119 .procname = "modules_disabled",
90120@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90121 .extra1 = &zero,
90122 .extra2 = &one,
90123 },
90124+#endif
90125 {
90126 .procname = "kptr_restrict",
90127 .data = &kptr_restrict,
90128 .maxlen = sizeof(int),
90129 .mode = 0644,
90130 .proc_handler = proc_dointvec_minmax_sysadmin,
90131+#ifdef CONFIG_GRKERNSEC_HIDESYM
90132+ .extra1 = &two,
90133+#else
90134 .extra1 = &zero,
90135+#endif
90136 .extra2 = &two,
90137 },
90138-#endif
90139 {
90140 .procname = "ngroups_max",
90141 .data = &ngroups_max,
90142@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90143 */
90144 {
90145 .procname = "perf_event_paranoid",
90146- .data = &sysctl_perf_event_paranoid,
90147- .maxlen = sizeof(sysctl_perf_event_paranoid),
90148+ .data = &sysctl_perf_event_legitimately_concerned,
90149+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90150 .mode = 0644,
90151- .proc_handler = proc_dointvec,
90152+ /* go ahead, be a hero */
90153+ .proc_handler = proc_dointvec_minmax_sysadmin,
90154+ .extra1 = &neg_one,
90155+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90156+ .extra2 = &three,
90157+#else
90158+ .extra2 = &two,
90159+#endif
90160 },
90161 {
90162 .procname = "perf_event_mlock_kb",
90163@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90164 .proc_handler = proc_dointvec_minmax,
90165 .extra1 = &zero,
90166 },
90167+ {
90168+ .procname = "heap_stack_gap",
90169+ .data = &sysctl_heap_stack_gap,
90170+ .maxlen = sizeof(sysctl_heap_stack_gap),
90171+ .mode = 0644,
90172+ .proc_handler = proc_doulongvec_minmax,
90173+ },
90174 #else
90175 {
90176 .procname = "nr_trim_pages",
90177@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90178 buffer, lenp, ppos);
90179 }
90180
90181+int proc_dostring_modpriv(struct ctl_table *table, int write,
90182+ void __user *buffer, size_t *lenp, loff_t *ppos)
90183+{
90184+ if (write && !capable(CAP_SYS_MODULE))
90185+ return -EPERM;
90186+
90187+ return _proc_do_string(table->data, table->maxlen, write,
90188+ buffer, lenp, ppos);
90189+}
90190+
90191 static size_t proc_skip_spaces(char **buf)
90192 {
90193 size_t ret;
90194@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90195 len = strlen(tmp);
90196 if (len > *size)
90197 len = *size;
90198+ if (len > sizeof(tmp))
90199+ len = sizeof(tmp);
90200 if (copy_to_user(*buf, tmp, len))
90201 return -EFAULT;
90202 *size -= len;
90203@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90204 static int proc_taint(struct ctl_table *table, int write,
90205 void __user *buffer, size_t *lenp, loff_t *ppos)
90206 {
90207- struct ctl_table t;
90208+ ctl_table_no_const t;
90209 unsigned long tmptaint = get_taint();
90210 int err;
90211
90212@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90213 return err;
90214 }
90215
90216-#ifdef CONFIG_PRINTK
90217 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90218 void __user *buffer, size_t *lenp, loff_t *ppos)
90219 {
90220@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90221
90222 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90223 }
90224-#endif
90225
90226 struct do_proc_dointvec_minmax_conv_param {
90227 int *min;
90228@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90229 return -ENOSYS;
90230 }
90231
90232+int proc_dostring_modpriv(struct ctl_table *table, int write,
90233+ void __user *buffer, size_t *lenp, loff_t *ppos)
90234+{
90235+ return -ENOSYS;
90236+}
90237+
90238 int proc_dointvec(struct ctl_table *table, int write,
90239 void __user *buffer, size_t *lenp, loff_t *ppos)
90240 {
90241@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90242 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90243 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90244 EXPORT_SYMBOL(proc_dostring);
90245+EXPORT_SYMBOL(proc_dostring_modpriv);
90246 EXPORT_SYMBOL(proc_doulongvec_minmax);
90247 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90248diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90249index 13d2f7c..c93d0b0 100644
90250--- a/kernel/taskstats.c
90251+++ b/kernel/taskstats.c
90252@@ -28,9 +28,12 @@
90253 #include <linux/fs.h>
90254 #include <linux/file.h>
90255 #include <linux/pid_namespace.h>
90256+#include <linux/grsecurity.h>
90257 #include <net/genetlink.h>
90258 #include <linux/atomic.h>
90259
90260+extern int gr_is_taskstats_denied(int pid);
90261+
90262 /*
90263 * Maximum length of a cpumask that can be specified in
90264 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90265@@ -576,6 +579,9 @@ err:
90266
90267 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90268 {
90269+ if (gr_is_taskstats_denied(current->pid))
90270+ return -EACCES;
90271+
90272 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90273 return cmd_attr_register_cpumask(info);
90274 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90275diff --git a/kernel/time.c b/kernel/time.c
90276index 7c7964c..2a0d412 100644
90277--- a/kernel/time.c
90278+++ b/kernel/time.c
90279@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90280 return error;
90281
90282 if (tz) {
90283+ /* we log in do_settimeofday called below, so don't log twice
90284+ */
90285+ if (!tv)
90286+ gr_log_timechange();
90287+
90288 sys_tz = *tz;
90289 update_vsyscall_tz();
90290 if (firsttime) {
90291diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90292index 88c9c65..7497ebc 100644
90293--- a/kernel/time/alarmtimer.c
90294+++ b/kernel/time/alarmtimer.c
90295@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90296 struct platform_device *pdev;
90297 int error = 0;
90298 int i;
90299- struct k_clock alarm_clock = {
90300+ static struct k_clock alarm_clock = {
90301 .clock_getres = alarm_clock_getres,
90302 .clock_get = alarm_clock_get,
90303 .timer_create = alarm_timer_create,
90304diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90305index 5b40279..81e58db 100644
90306--- a/kernel/time/timekeeping.c
90307+++ b/kernel/time/timekeeping.c
90308@@ -15,6 +15,7 @@
90309 #include <linux/init.h>
90310 #include <linux/mm.h>
90311 #include <linux/sched.h>
90312+#include <linux/grsecurity.h>
90313 #include <linux/syscore_ops.h>
90314 #include <linux/clocksource.h>
90315 #include <linux/jiffies.h>
90316@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90317 if (!timespec_valid_strict(tv))
90318 return -EINVAL;
90319
90320+ gr_log_timechange();
90321+
90322 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90323 write_seqcount_begin(&timekeeper_seq);
90324
90325diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90326index 61ed862..3b52c65 100644
90327--- a/kernel/time/timer_list.c
90328+++ b/kernel/time/timer_list.c
90329@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90330
90331 static void print_name_offset(struct seq_file *m, void *sym)
90332 {
90333+#ifdef CONFIG_GRKERNSEC_HIDESYM
90334+ SEQ_printf(m, "<%p>", NULL);
90335+#else
90336 char symname[KSYM_NAME_LEN];
90337
90338 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90339 SEQ_printf(m, "<%pK>", sym);
90340 else
90341 SEQ_printf(m, "%s", symname);
90342+#endif
90343 }
90344
90345 static void
90346@@ -119,7 +123,11 @@ next_one:
90347 static void
90348 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90349 {
90350+#ifdef CONFIG_GRKERNSEC_HIDESYM
90351+ SEQ_printf(m, " .base: %p\n", NULL);
90352+#else
90353 SEQ_printf(m, " .base: %pK\n", base);
90354+#endif
90355 SEQ_printf(m, " .index: %d\n",
90356 base->index);
90357 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90358@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90359 {
90360 struct proc_dir_entry *pe;
90361
90362+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90363+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90364+#else
90365 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90366+#endif
90367 if (!pe)
90368 return -ENOMEM;
90369 return 0;
90370diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90371index 1fb08f2..ca4bb1e 100644
90372--- a/kernel/time/timer_stats.c
90373+++ b/kernel/time/timer_stats.c
90374@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90375 static unsigned long nr_entries;
90376 static struct entry entries[MAX_ENTRIES];
90377
90378-static atomic_t overflow_count;
90379+static atomic_unchecked_t overflow_count;
90380
90381 /*
90382 * The entries are in a hash-table, for fast lookup:
90383@@ -140,7 +140,7 @@ static void reset_entries(void)
90384 nr_entries = 0;
90385 memset(entries, 0, sizeof(entries));
90386 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90387- atomic_set(&overflow_count, 0);
90388+ atomic_set_unchecked(&overflow_count, 0);
90389 }
90390
90391 static struct entry *alloc_entry(void)
90392@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90393 if (likely(entry))
90394 entry->count++;
90395 else
90396- atomic_inc(&overflow_count);
90397+ atomic_inc_unchecked(&overflow_count);
90398
90399 out_unlock:
90400 raw_spin_unlock_irqrestore(lock, flags);
90401@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90402
90403 static void print_name_offset(struct seq_file *m, unsigned long addr)
90404 {
90405+#ifdef CONFIG_GRKERNSEC_HIDESYM
90406+ seq_printf(m, "<%p>", NULL);
90407+#else
90408 char symname[KSYM_NAME_LEN];
90409
90410 if (lookup_symbol_name(addr, symname) < 0)
90411- seq_printf(m, "<%p>", (void *)addr);
90412+ seq_printf(m, "<%pK>", (void *)addr);
90413 else
90414 seq_printf(m, "%s", symname);
90415+#endif
90416 }
90417
90418 static int tstats_show(struct seq_file *m, void *v)
90419@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90420
90421 seq_puts(m, "Timer Stats Version: v0.3\n");
90422 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90423- if (atomic_read(&overflow_count))
90424- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90425+ if (atomic_read_unchecked(&overflow_count))
90426+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90427 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90428
90429 for (i = 0; i < nr_entries; i++) {
90430@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90431 {
90432 struct proc_dir_entry *pe;
90433
90434+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90435+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90436+#else
90437 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90438+#endif
90439 if (!pe)
90440 return -ENOMEM;
90441 return 0;
90442diff --git a/kernel/timer.c b/kernel/timer.c
90443index accfd24..e00f0c0 100644
90444--- a/kernel/timer.c
90445+++ b/kernel/timer.c
90446@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90447 /*
90448 * This function runs timers and the timer-tq in bottom half context.
90449 */
90450-static void run_timer_softirq(struct softirq_action *h)
90451+static __latent_entropy void run_timer_softirq(void)
90452 {
90453 struct tvec_base *base = __this_cpu_read(tvec_bases);
90454
90455@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90456 *
90457 * In all cases the return value is guaranteed to be non-negative.
90458 */
90459-signed long __sched schedule_timeout(signed long timeout)
90460+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90461 {
90462 struct timer_list timer;
90463 unsigned long expire;
90464diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90465index b418cb0..f879a3d 100644
90466--- a/kernel/trace/blktrace.c
90467+++ b/kernel/trace/blktrace.c
90468@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90469 struct blk_trace *bt = filp->private_data;
90470 char buf[16];
90471
90472- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90473+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90474
90475 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90476 }
90477@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90478 return 1;
90479
90480 bt = buf->chan->private_data;
90481- atomic_inc(&bt->dropped);
90482+ atomic_inc_unchecked(&bt->dropped);
90483 return 0;
90484 }
90485
90486@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90487
90488 bt->dir = dir;
90489 bt->dev = dev;
90490- atomic_set(&bt->dropped, 0);
90491+ atomic_set_unchecked(&bt->dropped, 0);
90492 INIT_LIST_HEAD(&bt->running_list);
90493
90494 ret = -EIO;
90495diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90496index cd7f76d..553c805 100644
90497--- a/kernel/trace/ftrace.c
90498+++ b/kernel/trace/ftrace.c
90499@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90500 if (unlikely(ftrace_disabled))
90501 return 0;
90502
90503+ ret = ftrace_arch_code_modify_prepare();
90504+ FTRACE_WARN_ON(ret);
90505+ if (ret)
90506+ return 0;
90507+
90508 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90509+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90510 if (ret) {
90511 ftrace_bug(ret, ip);
90512- return 0;
90513 }
90514- return 1;
90515+ return ret ? 0 : 1;
90516 }
90517
90518 /*
90519@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90520 if (!count)
90521 return 0;
90522
90523+ pax_open_kernel();
90524 sort(start, count, sizeof(*start),
90525 ftrace_cmp_ips, ftrace_swap_ips);
90526+ pax_close_kernel();
90527
90528 start_pg = ftrace_allocate_pages(count);
90529 if (!start_pg)
90530@@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90531 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90532
90533 static int ftrace_graph_active;
90534-static struct notifier_block ftrace_suspend_notifier;
90535-
90536 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90537 {
90538 return 0;
90539@@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90540 ftrace_graph_entry = ftrace_graph_entry_test;
90541 }
90542
90543+static struct notifier_block ftrace_suspend_notifier = {
90544+ .notifier_call = ftrace_suspend_notifier_call
90545+};
90546+
90547 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90548 trace_func_graph_ent_t entryfunc)
90549 {
90550@@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90551 goto out;
90552 }
90553
90554- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90555 register_pm_notifier(&ftrace_suspend_notifier);
90556
90557 ftrace_graph_active++;
90558diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90559index fc4da2d..f3e800b 100644
90560--- a/kernel/trace/ring_buffer.c
90561+++ b/kernel/trace/ring_buffer.c
90562@@ -352,9 +352,9 @@ struct buffer_data_page {
90563 */
90564 struct buffer_page {
90565 struct list_head list; /* list of buffer pages */
90566- local_t write; /* index for next write */
90567+ local_unchecked_t write; /* index for next write */
90568 unsigned read; /* index for next read */
90569- local_t entries; /* entries on this page */
90570+ local_unchecked_t entries; /* entries on this page */
90571 unsigned long real_end; /* real end of data */
90572 struct buffer_data_page *page; /* Actual data page */
90573 };
90574@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90575 unsigned long last_overrun;
90576 local_t entries_bytes;
90577 local_t entries;
90578- local_t overrun;
90579- local_t commit_overrun;
90580+ local_unchecked_t overrun;
90581+ local_unchecked_t commit_overrun;
90582 local_t dropped_events;
90583 local_t committing;
90584 local_t commits;
90585@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90586 *
90587 * We add a counter to the write field to denote this.
90588 */
90589- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90590- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90591+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90592+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90593
90594 /*
90595 * Just make sure we have seen our old_write and synchronize
90596@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90597 * cmpxchg to only update if an interrupt did not already
90598 * do it for us. If the cmpxchg fails, we don't care.
90599 */
90600- (void)local_cmpxchg(&next_page->write, old_write, val);
90601- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90602+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90603+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90604
90605 /*
90606 * No need to worry about races with clearing out the commit.
90607@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90608
90609 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90610 {
90611- return local_read(&bpage->entries) & RB_WRITE_MASK;
90612+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90613 }
90614
90615 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90616 {
90617- return local_read(&bpage->write) & RB_WRITE_MASK;
90618+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90619 }
90620
90621 static int
90622@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90623 * bytes consumed in ring buffer from here.
90624 * Increment overrun to account for the lost events.
90625 */
90626- local_add(page_entries, &cpu_buffer->overrun);
90627+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90628 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90629 }
90630
90631@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90632 * it is our responsibility to update
90633 * the counters.
90634 */
90635- local_add(entries, &cpu_buffer->overrun);
90636+ local_add_unchecked(entries, &cpu_buffer->overrun);
90637 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90638
90639 /*
90640@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90641 if (tail == BUF_PAGE_SIZE)
90642 tail_page->real_end = 0;
90643
90644- local_sub(length, &tail_page->write);
90645+ local_sub_unchecked(length, &tail_page->write);
90646 return;
90647 }
90648
90649@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90650 rb_event_set_padding(event);
90651
90652 /* Set the write back to the previous setting */
90653- local_sub(length, &tail_page->write);
90654+ local_sub_unchecked(length, &tail_page->write);
90655 return;
90656 }
90657
90658@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90659
90660 /* Set write to end of buffer */
90661 length = (tail + length) - BUF_PAGE_SIZE;
90662- local_sub(length, &tail_page->write);
90663+ local_sub_unchecked(length, &tail_page->write);
90664 }
90665
90666 /*
90667@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90668 * about it.
90669 */
90670 if (unlikely(next_page == commit_page)) {
90671- local_inc(&cpu_buffer->commit_overrun);
90672+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90673 goto out_reset;
90674 }
90675
90676@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90677 cpu_buffer->tail_page) &&
90678 (cpu_buffer->commit_page ==
90679 cpu_buffer->reader_page))) {
90680- local_inc(&cpu_buffer->commit_overrun);
90681+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90682 goto out_reset;
90683 }
90684 }
90685@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90686 length += RB_LEN_TIME_EXTEND;
90687
90688 tail_page = cpu_buffer->tail_page;
90689- write = local_add_return(length, &tail_page->write);
90690+ write = local_add_return_unchecked(length, &tail_page->write);
90691
90692 /* set write to only the index of the write */
90693 write &= RB_WRITE_MASK;
90694@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90695 kmemcheck_annotate_bitfield(event, bitfield);
90696 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90697
90698- local_inc(&tail_page->entries);
90699+ local_inc_unchecked(&tail_page->entries);
90700
90701 /*
90702 * If this is the first commit on the page, then update
90703@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90704
90705 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90706 unsigned long write_mask =
90707- local_read(&bpage->write) & ~RB_WRITE_MASK;
90708+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90709 unsigned long event_length = rb_event_length(event);
90710 /*
90711 * This is on the tail page. It is possible that
90712@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90713 */
90714 old_index += write_mask;
90715 new_index += write_mask;
90716- index = local_cmpxchg(&bpage->write, old_index, new_index);
90717+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90718 if (index == old_index) {
90719 /* update counters */
90720 local_sub(event_length, &cpu_buffer->entries_bytes);
90721@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90722
90723 /* Do the likely case first */
90724 if (likely(bpage->page == (void *)addr)) {
90725- local_dec(&bpage->entries);
90726+ local_dec_unchecked(&bpage->entries);
90727 return;
90728 }
90729
90730@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90731 start = bpage;
90732 do {
90733 if (bpage->page == (void *)addr) {
90734- local_dec(&bpage->entries);
90735+ local_dec_unchecked(&bpage->entries);
90736 return;
90737 }
90738 rb_inc_page(cpu_buffer, &bpage);
90739@@ -3146,7 +3146,7 @@ static inline unsigned long
90740 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90741 {
90742 return local_read(&cpu_buffer->entries) -
90743- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90744+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90745 }
90746
90747 /**
90748@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90749 return 0;
90750
90751 cpu_buffer = buffer->buffers[cpu];
90752- ret = local_read(&cpu_buffer->overrun);
90753+ ret = local_read_unchecked(&cpu_buffer->overrun);
90754
90755 return ret;
90756 }
90757@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90758 return 0;
90759
90760 cpu_buffer = buffer->buffers[cpu];
90761- ret = local_read(&cpu_buffer->commit_overrun);
90762+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90763
90764 return ret;
90765 }
90766@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90767 /* if you care about this being correct, lock the buffer */
90768 for_each_buffer_cpu(buffer, cpu) {
90769 cpu_buffer = buffer->buffers[cpu];
90770- overruns += local_read(&cpu_buffer->overrun);
90771+ overruns += local_read_unchecked(&cpu_buffer->overrun);
90772 }
90773
90774 return overruns;
90775@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90776 /*
90777 * Reset the reader page to size zero.
90778 */
90779- local_set(&cpu_buffer->reader_page->write, 0);
90780- local_set(&cpu_buffer->reader_page->entries, 0);
90781+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90782+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90783 local_set(&cpu_buffer->reader_page->page->commit, 0);
90784 cpu_buffer->reader_page->real_end = 0;
90785
90786@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90787 * want to compare with the last_overrun.
90788 */
90789 smp_mb();
90790- overwrite = local_read(&(cpu_buffer->overrun));
90791+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90792
90793 /*
90794 * Here's the tricky part.
90795@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90796
90797 cpu_buffer->head_page
90798 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90799- local_set(&cpu_buffer->head_page->write, 0);
90800- local_set(&cpu_buffer->head_page->entries, 0);
90801+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
90802+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90803 local_set(&cpu_buffer->head_page->page->commit, 0);
90804
90805 cpu_buffer->head_page->read = 0;
90806@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90807
90808 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90809 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90810- local_set(&cpu_buffer->reader_page->write, 0);
90811- local_set(&cpu_buffer->reader_page->entries, 0);
90812+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90813+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90814 local_set(&cpu_buffer->reader_page->page->commit, 0);
90815 cpu_buffer->reader_page->read = 0;
90816
90817 local_set(&cpu_buffer->entries_bytes, 0);
90818- local_set(&cpu_buffer->overrun, 0);
90819- local_set(&cpu_buffer->commit_overrun, 0);
90820+ local_set_unchecked(&cpu_buffer->overrun, 0);
90821+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90822 local_set(&cpu_buffer->dropped_events, 0);
90823 local_set(&cpu_buffer->entries, 0);
90824 local_set(&cpu_buffer->committing, 0);
90825@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90826 rb_init_page(bpage);
90827 bpage = reader->page;
90828 reader->page = *data_page;
90829- local_set(&reader->write, 0);
90830- local_set(&reader->entries, 0);
90831+ local_set_unchecked(&reader->write, 0);
90832+ local_set_unchecked(&reader->entries, 0);
90833 reader->read = 0;
90834 *data_page = bpage;
90835
90836diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90837index 24c1f23..781fd73f 100644
90838--- a/kernel/trace/trace.c
90839+++ b/kernel/trace/trace.c
90840@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90841 return 0;
90842 }
90843
90844-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90845+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90846 {
90847 /* do nothing if flag is already set */
90848 if (!!(trace_flags & mask) == !!enabled)
90849diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90850index 02b592f..f971546 100644
90851--- a/kernel/trace/trace.h
90852+++ b/kernel/trace/trace.h
90853@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
90854 void trace_printk_init_buffers(void);
90855 void trace_printk_start_comm(void);
90856 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90857-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90858+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90859
90860 /*
90861 * Normal trace_printk() and friends allocates special buffers
90862diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90863index 26dc348..8708ca7 100644
90864--- a/kernel/trace/trace_clock.c
90865+++ b/kernel/trace/trace_clock.c
90866@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90867 return now;
90868 }
90869
90870-static atomic64_t trace_counter;
90871+static atomic64_unchecked_t trace_counter;
90872
90873 /*
90874 * trace_clock_counter(): simply an atomic counter.
90875@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90876 */
90877 u64 notrace trace_clock_counter(void)
90878 {
90879- return atomic64_add_return(1, &trace_counter);
90880+ return atomic64_inc_return_unchecked(&trace_counter);
90881 }
90882diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90883index 7b16d40..1b2875d 100644
90884--- a/kernel/trace/trace_events.c
90885+++ b/kernel/trace/trace_events.c
90886@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90887 return 0;
90888 }
90889
90890-struct ftrace_module_file_ops;
90891 static void __add_event_to_tracers(struct ftrace_event_call *call);
90892
90893 /* Add an additional event_call dynamically */
90894diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90895index 0abd9b8..6a663a2 100644
90896--- a/kernel/trace/trace_mmiotrace.c
90897+++ b/kernel/trace/trace_mmiotrace.c
90898@@ -24,7 +24,7 @@ struct header_iter {
90899 static struct trace_array *mmio_trace_array;
90900 static bool overrun_detected;
90901 static unsigned long prev_overruns;
90902-static atomic_t dropped_count;
90903+static atomic_unchecked_t dropped_count;
90904
90905 static void mmio_reset_data(struct trace_array *tr)
90906 {
90907@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90908
90909 static unsigned long count_overruns(struct trace_iterator *iter)
90910 {
90911- unsigned long cnt = atomic_xchg(&dropped_count, 0);
90912+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90913 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90914
90915 if (over > prev_overruns)
90916@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90917 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90918 sizeof(*entry), 0, pc);
90919 if (!event) {
90920- atomic_inc(&dropped_count);
90921+ atomic_inc_unchecked(&dropped_count);
90922 return;
90923 }
90924 entry = ring_buffer_event_data(event);
90925@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90926 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90927 sizeof(*entry), 0, pc);
90928 if (!event) {
90929- atomic_inc(&dropped_count);
90930+ atomic_inc_unchecked(&dropped_count);
90931 return;
90932 }
90933 entry = ring_buffer_event_data(event);
90934diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90935index ed32284..884d6c3 100644
90936--- a/kernel/trace/trace_output.c
90937+++ b/kernel/trace/trace_output.c
90938@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90939
90940 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90941 if (!IS_ERR(p)) {
90942- p = mangle_path(s->buffer + s->len, p, "\n");
90943+ p = mangle_path(s->buffer + s->len, p, "\n\\");
90944 if (p) {
90945 s->len = p - s->buffer;
90946 return 1;
90947@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90948 goto out;
90949 }
90950
90951+ pax_open_kernel();
90952 if (event->funcs->trace == NULL)
90953- event->funcs->trace = trace_nop_print;
90954+ *(void **)&event->funcs->trace = trace_nop_print;
90955 if (event->funcs->raw == NULL)
90956- event->funcs->raw = trace_nop_print;
90957+ *(void **)&event->funcs->raw = trace_nop_print;
90958 if (event->funcs->hex == NULL)
90959- event->funcs->hex = trace_nop_print;
90960+ *(void **)&event->funcs->hex = trace_nop_print;
90961 if (event->funcs->binary == NULL)
90962- event->funcs->binary = trace_nop_print;
90963+ *(void **)&event->funcs->binary = trace_nop_print;
90964+ pax_close_kernel();
90965
90966 key = event->type & (EVENT_HASHSIZE - 1);
90967
90968diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90969index e6be585..d73ae5e 100644
90970--- a/kernel/trace/trace_stack.c
90971+++ b/kernel/trace/trace_stack.c
90972@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90973 return;
90974
90975 /* we do not handle interrupt stacks yet */
90976- if (!object_is_on_stack(stack))
90977+ if (!object_starts_on_stack(stack))
90978 return;
90979
90980 local_irq_save(flags);
90981diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90982index 80a57af..7f5a7ff 100644
90983--- a/kernel/user_namespace.c
90984+++ b/kernel/user_namespace.c
90985@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90986 !kgid_has_mapping(parent_ns, group))
90987 return -EPERM;
90988
90989+#ifdef CONFIG_GRKERNSEC
90990+ /*
90991+ * This doesn't really inspire confidence:
90992+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90993+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90994+ * Increases kernel attack surface in areas developers
90995+ * previously cared little about ("low importance due
90996+ * to requiring "root" capability")
90997+ * To be removed when this code receives *proper* review
90998+ */
90999+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91000+ !capable(CAP_SETGID))
91001+ return -EPERM;
91002+#endif
91003+
91004 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91005 if (!ns)
91006 return -ENOMEM;
91007@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91008 if (atomic_read(&current->mm->mm_users) > 1)
91009 return -EINVAL;
91010
91011- if (current->fs->users != 1)
91012+ if (atomic_read(&current->fs->users) != 1)
91013 return -EINVAL;
91014
91015 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91016diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91017index 4f69f9a..7c6f8f8 100644
91018--- a/kernel/utsname_sysctl.c
91019+++ b/kernel/utsname_sysctl.c
91020@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91021 static int proc_do_uts_string(ctl_table *table, int write,
91022 void __user *buffer, size_t *lenp, loff_t *ppos)
91023 {
91024- struct ctl_table uts_table;
91025+ ctl_table_no_const uts_table;
91026 int r;
91027 memcpy(&uts_table, table, sizeof(uts_table));
91028 uts_table.data = get_uts(table, write);
91029diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91030index 4431610..4265616 100644
91031--- a/kernel/watchdog.c
91032+++ b/kernel/watchdog.c
91033@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91034 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91035 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91036
91037-static struct smp_hotplug_thread watchdog_threads = {
91038+static struct smp_hotplug_thread watchdog_threads __read_only = {
91039 .store = &softlockup_watchdog,
91040 .thread_should_run = watchdog_should_run,
91041 .thread_fn = watchdog,
91042diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91043index 193e977..26dd63f 100644
91044--- a/kernel/workqueue.c
91045+++ b/kernel/workqueue.c
91046@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
91047 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91048 worker_flags |= WORKER_REBOUND;
91049 worker_flags &= ~WORKER_UNBOUND;
91050- ACCESS_ONCE(worker->flags) = worker_flags;
91051+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91052 }
91053
91054 spin_unlock_irq(&pool->lock);
91055diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91056index a48abea..e108def 100644
91057--- a/lib/Kconfig.debug
91058+++ b/lib/Kconfig.debug
91059@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
91060
91061 config DEBUG_WW_MUTEX_SLOWPATH
91062 bool "Wait/wound mutex debugging: Slowpath testing"
91063- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91064+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91065 select DEBUG_LOCK_ALLOC
91066 select DEBUG_SPINLOCK
91067 select DEBUG_MUTEXES
91068@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91069
91070 config DEBUG_LOCK_ALLOC
91071 bool "Lock debugging: detect incorrect freeing of live locks"
91072- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91073+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91074 select DEBUG_SPINLOCK
91075 select DEBUG_MUTEXES
91076 select LOCKDEP
91077@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
91078
91079 config PROVE_LOCKING
91080 bool "Lock debugging: prove locking correctness"
91081- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91082+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91083 select LOCKDEP
91084 select DEBUG_SPINLOCK
91085 select DEBUG_MUTEXES
91086@@ -932,7 +932,7 @@ config LOCKDEP
91087
91088 config LOCK_STAT
91089 bool "Lock usage statistics"
91090- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91091+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91092 select LOCKDEP
91093 select DEBUG_SPINLOCK
91094 select DEBUG_MUTEXES
91095@@ -1394,6 +1394,7 @@ config LATENCYTOP
91096 depends on DEBUG_KERNEL
91097 depends on STACKTRACE_SUPPORT
91098 depends on PROC_FS
91099+ depends on !GRKERNSEC_HIDESYM
91100 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91101 select KALLSYMS
91102 select KALLSYMS_ALL
91103@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91104 config DEBUG_STRICT_USER_COPY_CHECKS
91105 bool "Strict user copy size checks"
91106 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91107- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91108+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91109 help
91110 Enabling this option turns a certain set of sanity checks for user
91111 copy operations into compile time failures.
91112@@ -1529,7 +1530,7 @@ endmenu # runtime tests
91113
91114 config PROVIDE_OHCI1394_DMA_INIT
91115 bool "Remote debugging over FireWire early on boot"
91116- depends on PCI && X86
91117+ depends on PCI && X86 && !GRKERNSEC
91118 help
91119 If you want to debug problems which hang or crash the kernel early
91120 on boot and the crashing machine has a FireWire port, you can use
91121diff --git a/lib/Makefile b/lib/Makefile
91122index 48140e3..de854e5 100644
91123--- a/lib/Makefile
91124+++ b/lib/Makefile
91125@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91126 obj-$(CONFIG_BTREE) += btree.o
91127 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91128 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91129-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91130+obj-y += list_debug.o
91131 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91132
91133 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91134diff --git a/lib/average.c b/lib/average.c
91135index 114d1be..ab0350c 100644
91136--- a/lib/average.c
91137+++ b/lib/average.c
91138@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91139 {
91140 unsigned long internal = ACCESS_ONCE(avg->internal);
91141
91142- ACCESS_ONCE(avg->internal) = internal ?
91143+ ACCESS_ONCE_RW(avg->internal) = internal ?
91144 (((internal << avg->weight) - internal) +
91145 (val << avg->factor)) >> avg->weight :
91146 (val << avg->factor);
91147diff --git a/lib/bitmap.c b/lib/bitmap.c
91148index 06f7e4f..f3cf2b0 100644
91149--- a/lib/bitmap.c
91150+++ b/lib/bitmap.c
91151@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91152 {
91153 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91154 u32 chunk;
91155- const char __user __force *ubuf = (const char __user __force *)buf;
91156+ const char __user *ubuf = (const char __force_user *)buf;
91157
91158 bitmap_zero(maskp, nmaskbits);
91159
91160@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91161 {
91162 if (!access_ok(VERIFY_READ, ubuf, ulen))
91163 return -EFAULT;
91164- return __bitmap_parse((const char __force *)ubuf,
91165+ return __bitmap_parse((const char __force_kernel *)ubuf,
91166 ulen, 1, maskp, nmaskbits);
91167
91168 }
91169@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91170 {
91171 unsigned a, b;
91172 int c, old_c, totaldigits;
91173- const char __user __force *ubuf = (const char __user __force *)buf;
91174+ const char __user *ubuf = (const char __force_user *)buf;
91175 int exp_digit, in_range;
91176
91177 totaldigits = c = 0;
91178@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91179 {
91180 if (!access_ok(VERIFY_READ, ubuf, ulen))
91181 return -EFAULT;
91182- return __bitmap_parselist((const char __force *)ubuf,
91183+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91184 ulen, 1, maskp, nmaskbits);
91185 }
91186 EXPORT_SYMBOL(bitmap_parselist_user);
91187diff --git a/lib/bug.c b/lib/bug.c
91188index 1686034..a9c00c8 100644
91189--- a/lib/bug.c
91190+++ b/lib/bug.c
91191@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91192 return BUG_TRAP_TYPE_NONE;
91193
91194 bug = find_bug(bugaddr);
91195+ if (!bug)
91196+ return BUG_TRAP_TYPE_NONE;
91197
91198 file = NULL;
91199 line = 0;
91200diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91201index e0731c3..ad66444 100644
91202--- a/lib/debugobjects.c
91203+++ b/lib/debugobjects.c
91204@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91205 if (limit > 4)
91206 return;
91207
91208- is_on_stack = object_is_on_stack(addr);
91209+ is_on_stack = object_starts_on_stack(addr);
91210 if (is_on_stack == onstack)
91211 return;
91212
91213diff --git a/lib/devres.c b/lib/devres.c
91214index 8235331..5881053 100644
91215--- a/lib/devres.c
91216+++ b/lib/devres.c
91217@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91218 void devm_iounmap(struct device *dev, void __iomem *addr)
91219 {
91220 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91221- (void *)addr));
91222+ (void __force *)addr));
91223 iounmap(addr);
91224 }
91225 EXPORT_SYMBOL(devm_iounmap);
91226@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91227 {
91228 ioport_unmap(addr);
91229 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91230- devm_ioport_map_match, (void *)addr));
91231+ devm_ioport_map_match, (void __force *)addr));
91232 }
91233 EXPORT_SYMBOL(devm_ioport_unmap);
91234 #endif /* CONFIG_HAS_IOPORT */
91235diff --git a/lib/div64.c b/lib/div64.c
91236index 4382ad7..08aa558 100644
91237--- a/lib/div64.c
91238+++ b/lib/div64.c
91239@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91240 EXPORT_SYMBOL(__div64_32);
91241
91242 #ifndef div_s64_rem
91243-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91244+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91245 {
91246 u64 quotient;
91247
91248@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91249 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91250 */
91251 #ifndef div64_u64
91252-u64 div64_u64(u64 dividend, u64 divisor)
91253+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91254 {
91255 u32 high = divisor >> 32;
91256 u64 quot;
91257diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91258index 98f2d7e..899da5c 100644
91259--- a/lib/dma-debug.c
91260+++ b/lib/dma-debug.c
91261@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91262
91263 void dma_debug_add_bus(struct bus_type *bus)
91264 {
91265- struct notifier_block *nb;
91266+ notifier_block_no_const *nb;
91267
91268 if (global_disable)
91269 return;
91270@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91271
91272 static void check_for_stack(struct device *dev, void *addr)
91273 {
91274- if (object_is_on_stack(addr))
91275+ if (object_starts_on_stack(addr))
91276 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91277 "stack [addr=%p]\n", addr);
91278 }
91279diff --git a/lib/hash.c b/lib/hash.c
91280index fea973f..386626f 100644
91281--- a/lib/hash.c
91282+++ b/lib/hash.c
91283@@ -14,7 +14,7 @@
91284 #include <linux/hash.h>
91285 #include <linux/cache.h>
91286
91287-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91288+static struct fast_hash_ops arch_hash_ops __read_only = {
91289 .hash = jhash,
91290 .hash2 = jhash2,
91291 };
91292diff --git a/lib/inflate.c b/lib/inflate.c
91293index 013a761..c28f3fc 100644
91294--- a/lib/inflate.c
91295+++ b/lib/inflate.c
91296@@ -269,7 +269,7 @@ static void free(void *where)
91297 malloc_ptr = free_mem_ptr;
91298 }
91299 #else
91300-#define malloc(a) kmalloc(a, GFP_KERNEL)
91301+#define malloc(a) kmalloc((a), GFP_KERNEL)
91302 #define free(a) kfree(a)
91303 #endif
91304
91305diff --git a/lib/ioremap.c b/lib/ioremap.c
91306index 0c9216c..863bd89 100644
91307--- a/lib/ioremap.c
91308+++ b/lib/ioremap.c
91309@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91310 unsigned long next;
91311
91312 phys_addr -= addr;
91313- pmd = pmd_alloc(&init_mm, pud, addr);
91314+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91315 if (!pmd)
91316 return -ENOMEM;
91317 do {
91318@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91319 unsigned long next;
91320
91321 phys_addr -= addr;
91322- pud = pud_alloc(&init_mm, pgd, addr);
91323+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91324 if (!pud)
91325 return -ENOMEM;
91326 do {
91327diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91328index bd2bea9..6b3c95e 100644
91329--- a/lib/is_single_threaded.c
91330+++ b/lib/is_single_threaded.c
91331@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91332 struct task_struct *p, *t;
91333 bool ret;
91334
91335+ if (!mm)
91336+ return true;
91337+
91338 if (atomic_read(&task->signal->live) != 1)
91339 return false;
91340
91341diff --git a/lib/kobject.c b/lib/kobject.c
91342index cb14aea..8c53cdb 100644
91343--- a/lib/kobject.c
91344+++ b/lib/kobject.c
91345@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91346
91347
91348 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91349-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91350+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91351
91352-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91353+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91354 {
91355 enum kobj_ns_type type = ops->type;
91356 int error;
91357diff --git a/lib/list_debug.c b/lib/list_debug.c
91358index c24c2f7..f0296f4 100644
91359--- a/lib/list_debug.c
91360+++ b/lib/list_debug.c
91361@@ -11,7 +11,9 @@
91362 #include <linux/bug.h>
91363 #include <linux/kernel.h>
91364 #include <linux/rculist.h>
91365+#include <linux/mm.h>
91366
91367+#ifdef CONFIG_DEBUG_LIST
91368 /*
91369 * Insert a new entry between two known consecutive entries.
91370 *
91371@@ -19,21 +21,40 @@
91372 * the prev/next entries already!
91373 */
91374
91375+static bool __list_add_debug(struct list_head *new,
91376+ struct list_head *prev,
91377+ struct list_head *next)
91378+{
91379+ if (unlikely(next->prev != prev)) {
91380+ printk(KERN_ERR "list_add corruption. next->prev should be "
91381+ "prev (%p), but was %p. (next=%p).\n",
91382+ prev, next->prev, next);
91383+ BUG();
91384+ return false;
91385+ }
91386+ if (unlikely(prev->next != next)) {
91387+ printk(KERN_ERR "list_add corruption. prev->next should be "
91388+ "next (%p), but was %p. (prev=%p).\n",
91389+ next, prev->next, prev);
91390+ BUG();
91391+ return false;
91392+ }
91393+ if (unlikely(new == prev || new == next)) {
91394+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91395+ new, prev, next);
91396+ BUG();
91397+ return false;
91398+ }
91399+ return true;
91400+}
91401+
91402 void __list_add(struct list_head *new,
91403- struct list_head *prev,
91404- struct list_head *next)
91405+ struct list_head *prev,
91406+ struct list_head *next)
91407 {
91408- WARN(next->prev != prev,
91409- "list_add corruption. next->prev should be "
91410- "prev (%p), but was %p. (next=%p).\n",
91411- prev, next->prev, next);
91412- WARN(prev->next != next,
91413- "list_add corruption. prev->next should be "
91414- "next (%p), but was %p. (prev=%p).\n",
91415- next, prev->next, prev);
91416- WARN(new == prev || new == next,
91417- "list_add double add: new=%p, prev=%p, next=%p.\n",
91418- new, prev, next);
91419+ if (!__list_add_debug(new, prev, next))
91420+ return;
91421+
91422 next->prev = new;
91423 new->next = next;
91424 new->prev = prev;
91425@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91426 }
91427 EXPORT_SYMBOL(__list_add);
91428
91429-void __list_del_entry(struct list_head *entry)
91430+static bool __list_del_entry_debug(struct list_head *entry)
91431 {
91432 struct list_head *prev, *next;
91433
91434 prev = entry->prev;
91435 next = entry->next;
91436
91437- if (WARN(next == LIST_POISON1,
91438- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91439- entry, LIST_POISON1) ||
91440- WARN(prev == LIST_POISON2,
91441- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91442- entry, LIST_POISON2) ||
91443- WARN(prev->next != entry,
91444- "list_del corruption. prev->next should be %p, "
91445- "but was %p\n", entry, prev->next) ||
91446- WARN(next->prev != entry,
91447- "list_del corruption. next->prev should be %p, "
91448- "but was %p\n", entry, next->prev))
91449+ if (unlikely(next == LIST_POISON1)) {
91450+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91451+ entry, LIST_POISON1);
91452+ BUG();
91453+ return false;
91454+ }
91455+ if (unlikely(prev == LIST_POISON2)) {
91456+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91457+ entry, LIST_POISON2);
91458+ BUG();
91459+ return false;
91460+ }
91461+ if (unlikely(entry->prev->next != entry)) {
91462+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91463+ "but was %p\n", entry, prev->next);
91464+ BUG();
91465+ return false;
91466+ }
91467+ if (unlikely(entry->next->prev != entry)) {
91468+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91469+ "but was %p\n", entry, next->prev);
91470+ BUG();
91471+ return false;
91472+ }
91473+ return true;
91474+}
91475+
91476+void __list_del_entry(struct list_head *entry)
91477+{
91478+ if (!__list_del_entry_debug(entry))
91479 return;
91480
91481- __list_del(prev, next);
91482+ __list_del(entry->prev, entry->next);
91483 }
91484 EXPORT_SYMBOL(__list_del_entry);
91485
91486@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91487 void __list_add_rcu(struct list_head *new,
91488 struct list_head *prev, struct list_head *next)
91489 {
91490- WARN(next->prev != prev,
91491- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91492- prev, next->prev, next);
91493- WARN(prev->next != next,
91494- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91495- next, prev->next, prev);
91496+ if (!__list_add_debug(new, prev, next))
91497+ return;
91498+
91499 new->next = next;
91500 new->prev = prev;
91501 rcu_assign_pointer(list_next_rcu(prev), new);
91502 next->prev = new;
91503 }
91504 EXPORT_SYMBOL(__list_add_rcu);
91505+#endif
91506+
91507+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91508+{
91509+#ifdef CONFIG_DEBUG_LIST
91510+ if (!__list_add_debug(new, prev, next))
91511+ return;
91512+#endif
91513+
91514+ pax_open_kernel();
91515+ next->prev = new;
91516+ new->next = next;
91517+ new->prev = prev;
91518+ prev->next = new;
91519+ pax_close_kernel();
91520+}
91521+EXPORT_SYMBOL(__pax_list_add);
91522+
91523+void pax_list_del(struct list_head *entry)
91524+{
91525+#ifdef CONFIG_DEBUG_LIST
91526+ if (!__list_del_entry_debug(entry))
91527+ return;
91528+#endif
91529+
91530+ pax_open_kernel();
91531+ __list_del(entry->prev, entry->next);
91532+ entry->next = LIST_POISON1;
91533+ entry->prev = LIST_POISON2;
91534+ pax_close_kernel();
91535+}
91536+EXPORT_SYMBOL(pax_list_del);
91537+
91538+void pax_list_del_init(struct list_head *entry)
91539+{
91540+ pax_open_kernel();
91541+ __list_del(entry->prev, entry->next);
91542+ INIT_LIST_HEAD(entry);
91543+ pax_close_kernel();
91544+}
91545+EXPORT_SYMBOL(pax_list_del_init);
91546+
91547+void __pax_list_add_rcu(struct list_head *new,
91548+ struct list_head *prev, struct list_head *next)
91549+{
91550+#ifdef CONFIG_DEBUG_LIST
91551+ if (!__list_add_debug(new, prev, next))
91552+ return;
91553+#endif
91554+
91555+ pax_open_kernel();
91556+ new->next = next;
91557+ new->prev = prev;
91558+ rcu_assign_pointer(list_next_rcu(prev), new);
91559+ next->prev = new;
91560+ pax_close_kernel();
91561+}
91562+EXPORT_SYMBOL(__pax_list_add_rcu);
91563+
91564+void pax_list_del_rcu(struct list_head *entry)
91565+{
91566+#ifdef CONFIG_DEBUG_LIST
91567+ if (!__list_del_entry_debug(entry))
91568+ return;
91569+#endif
91570+
91571+ pax_open_kernel();
91572+ __list_del(entry->prev, entry->next);
91573+ entry->next = LIST_POISON1;
91574+ entry->prev = LIST_POISON2;
91575+ pax_close_kernel();
91576+}
91577+EXPORT_SYMBOL(pax_list_del_rcu);
91578diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91579index 963b703..438bc51 100644
91580--- a/lib/percpu-refcount.c
91581+++ b/lib/percpu-refcount.c
91582@@ -29,7 +29,7 @@
91583 * can't hit 0 before we've added up all the percpu refs.
91584 */
91585
91586-#define PCPU_COUNT_BIAS (1U << 31)
91587+#define PCPU_COUNT_BIAS (1U << 30)
91588
91589 /**
91590 * percpu_ref_init - initialize a percpu refcount
91591diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91592index bd4a8df..9e4804f 100644
91593--- a/lib/radix-tree.c
91594+++ b/lib/radix-tree.c
91595@@ -93,7 +93,7 @@ struct radix_tree_preload {
91596 int nr;
91597 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91598 };
91599-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91600+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91601
91602 static inline void *ptr_to_indirect(void *ptr)
91603 {
91604diff --git a/lib/random32.c b/lib/random32.c
91605index 6148967..009bfe8 100644
91606--- a/lib/random32.c
91607+++ b/lib/random32.c
91608@@ -44,7 +44,7 @@
91609 static void __init prandom_state_selftest(void);
91610 #endif
91611
91612-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91613+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91614
91615 /**
91616 * prandom_u32_state - seeded pseudo-random number generator.
91617diff --git a/lib/rbtree.c b/lib/rbtree.c
91618index 65f4eff..2cfa167 100644
91619--- a/lib/rbtree.c
91620+++ b/lib/rbtree.c
91621@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91622 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91623
91624 static const struct rb_augment_callbacks dummy_callbacks = {
91625- dummy_propagate, dummy_copy, dummy_rotate
91626+ .propagate = dummy_propagate,
91627+ .copy = dummy_copy,
91628+ .rotate = dummy_rotate
91629 };
91630
91631 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91632diff --git a/lib/show_mem.c b/lib/show_mem.c
91633index 0922579..9d7adb9 100644
91634--- a/lib/show_mem.c
91635+++ b/lib/show_mem.c
91636@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91637 quicklist_total_size());
91638 #endif
91639 #ifdef CONFIG_MEMORY_FAILURE
91640- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91641+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91642 #endif
91643 }
91644diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91645index bb2b201..46abaf9 100644
91646--- a/lib/strncpy_from_user.c
91647+++ b/lib/strncpy_from_user.c
91648@@ -21,7 +21,7 @@
91649 */
91650 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91651 {
91652- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91653+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91654 long res = 0;
91655
91656 /*
91657diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91658index a28df52..3d55877 100644
91659--- a/lib/strnlen_user.c
91660+++ b/lib/strnlen_user.c
91661@@ -26,7 +26,7 @@
91662 */
91663 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91664 {
91665- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91666+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91667 long align, res = 0;
91668 unsigned long c;
91669
91670diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91671index b604b83..c0547f6 100644
91672--- a/lib/swiotlb.c
91673+++ b/lib/swiotlb.c
91674@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91675
91676 void
91677 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91678- dma_addr_t dev_addr)
91679+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91680 {
91681 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91682
91683diff --git a/lib/usercopy.c b/lib/usercopy.c
91684index 4f5b1dd..7cab418 100644
91685--- a/lib/usercopy.c
91686+++ b/lib/usercopy.c
91687@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91688 WARN(1, "Buffer overflow detected!\n");
91689 }
91690 EXPORT_SYMBOL(copy_from_user_overflow);
91691+
91692+void copy_to_user_overflow(void)
91693+{
91694+ WARN(1, "Buffer overflow detected!\n");
91695+}
91696+EXPORT_SYMBOL(copy_to_user_overflow);
91697diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91698index 185b6d3..823c48c 100644
91699--- a/lib/vsprintf.c
91700+++ b/lib/vsprintf.c
91701@@ -16,6 +16,9 @@
91702 * - scnprintf and vscnprintf
91703 */
91704
91705+#ifdef CONFIG_GRKERNSEC_HIDESYM
91706+#define __INCLUDED_BY_HIDESYM 1
91707+#endif
91708 #include <stdarg.h>
91709 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91710 #include <linux/types.h>
91711@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
91712 return number(buf, end, num, spec);
91713 }
91714
91715+#ifdef CONFIG_GRKERNSEC_HIDESYM
91716+int kptr_restrict __read_mostly = 2;
91717+#else
91718 int kptr_restrict __read_mostly;
91719+#endif
91720
91721 /*
91722 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91723@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
91724 * - 'f' For simple symbolic function names without offset
91725 * - 'S' For symbolic direct pointers with offset
91726 * - 's' For symbolic direct pointers without offset
91727+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91728 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91729 * - 'B' For backtraced symbolic direct pointers with offset
91730 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91731@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91732
91733 if (!ptr && *fmt != 'K') {
91734 /*
91735- * Print (null) with the same width as a pointer so it makes
91736+ * Print (nil) with the same width as a pointer so it makes
91737 * tabular output look nice.
91738 */
91739 if (spec.field_width == -1)
91740 spec.field_width = default_width;
91741- return string(buf, end, "(null)", spec);
91742+ return string(buf, end, "(nil)", spec);
91743 }
91744
91745 switch (*fmt) {
91746@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91747 /* Fallthrough */
91748 case 'S':
91749 case 's':
91750+#ifdef CONFIG_GRKERNSEC_HIDESYM
91751+ break;
91752+#else
91753+ return symbol_string(buf, end, ptr, spec, fmt);
91754+#endif
91755+ case 'A':
91756 case 'B':
91757 return symbol_string(buf, end, ptr, spec, fmt);
91758 case 'R':
91759@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91760 va_end(va);
91761 return buf;
91762 }
91763+ case 'P':
91764+ break;
91765 case 'K':
91766 /*
91767 * %pK cannot be used in IRQ context because its test
91768@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91769 ((const struct file *)ptr)->f_path.dentry,
91770 spec, fmt);
91771 }
91772+
91773+#ifdef CONFIG_GRKERNSEC_HIDESYM
91774+ /* 'P' = approved pointers to copy to userland,
91775+ as in the /proc/kallsyms case, as we make it display nothing
91776+ for non-root users, and the real contents for root users
91777+ Also ignore 'K' pointers, since we force their NULLing for non-root users
91778+ above
91779+ */
91780+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91781+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91782+ dump_stack();
91783+ ptr = NULL;
91784+ }
91785+#endif
91786+
91787 spec.flags |= SMALL;
91788 if (spec.field_width == -1) {
91789 spec.field_width = default_width;
91790@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91791 typeof(type) value; \
91792 if (sizeof(type) == 8) { \
91793 args = PTR_ALIGN(args, sizeof(u32)); \
91794- *(u32 *)&value = *(u32 *)args; \
91795- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91796+ *(u32 *)&value = *(const u32 *)args; \
91797+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91798 } else { \
91799 args = PTR_ALIGN(args, sizeof(type)); \
91800- value = *(typeof(type) *)args; \
91801+ value = *(const typeof(type) *)args; \
91802 } \
91803 args += sizeof(type); \
91804 value; \
91805@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91806 case FORMAT_TYPE_STR: {
91807 const char *str_arg = args;
91808 args += strlen(str_arg) + 1;
91809- str = string(str, end, (char *)str_arg, spec);
91810+ str = string(str, end, str_arg, spec);
91811 break;
91812 }
91813
91814diff --git a/localversion-grsec b/localversion-grsec
91815new file mode 100644
91816index 0000000..7cd6065
91817--- /dev/null
91818+++ b/localversion-grsec
91819@@ -0,0 +1 @@
91820+-grsec
91821diff --git a/mm/Kconfig b/mm/Kconfig
91822index 2888024..c15a810 100644
91823--- a/mm/Kconfig
91824+++ b/mm/Kconfig
91825@@ -326,10 +326,11 @@ config KSM
91826 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91827
91828 config DEFAULT_MMAP_MIN_ADDR
91829- int "Low address space to protect from user allocation"
91830+ int "Low address space to protect from user allocation"
91831 depends on MMU
91832- default 4096
91833- help
91834+ default 32768 if ALPHA || ARM || PARISC || SPARC32
91835+ default 65536
91836+ help
91837 This is the portion of low virtual memory which should be protected
91838 from userspace allocation. Keeping a user from writing to low pages
91839 can help reduce the impact of kernel NULL pointer bugs.
91840@@ -360,7 +361,7 @@ config MEMORY_FAILURE
91841
91842 config HWPOISON_INJECT
91843 tristate "HWPoison pages injector"
91844- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91845+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91846 select PROC_PAGE_MONITOR
91847
91848 config NOMMU_INITIAL_TRIM_EXCESS
91849diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91850index 09d9591..165bb75 100644
91851--- a/mm/backing-dev.c
91852+++ b/mm/backing-dev.c
91853@@ -12,7 +12,7 @@
91854 #include <linux/device.h>
91855 #include <trace/events/writeback.h>
91856
91857-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91858+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91859
91860 struct backing_dev_info default_backing_dev_info = {
91861 .name = "default",
91862@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91863 return err;
91864
91865 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91866- atomic_long_inc_return(&bdi_seq));
91867+ atomic_long_inc_return_unchecked(&bdi_seq));
91868 if (err) {
91869 bdi_destroy(bdi);
91870 return err;
91871diff --git a/mm/filemap.c b/mm/filemap.c
91872index 7a13f6a..e52e841 100644
91873--- a/mm/filemap.c
91874+++ b/mm/filemap.c
91875@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91876 struct address_space *mapping = file->f_mapping;
91877
91878 if (!mapping->a_ops->readpage)
91879- return -ENOEXEC;
91880+ return -ENODEV;
91881 file_accessed(file);
91882 vma->vm_ops = &generic_file_vm_ops;
91883 return 0;
91884@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91885
91886 while (bytes) {
91887 char __user *buf = iov->iov_base + base;
91888- int copy = min(bytes, iov->iov_len - base);
91889+ size_t copy = min(bytes, iov->iov_len - base);
91890
91891 base = 0;
91892 left = __copy_from_user_inatomic(vaddr, buf, copy);
91893@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91894 BUG_ON(!in_atomic());
91895 kaddr = kmap_atomic(page);
91896 if (likely(i->nr_segs == 1)) {
91897- int left;
91898+ size_t left;
91899 char __user *buf = i->iov->iov_base + i->iov_offset;
91900 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91901 copied = bytes - left;
91902@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91903
91904 kaddr = kmap(page);
91905 if (likely(i->nr_segs == 1)) {
91906- int left;
91907+ size_t left;
91908 char __user *buf = i->iov->iov_base + i->iov_offset;
91909 left = __copy_from_user(kaddr + offset, buf, bytes);
91910 copied = bytes - left;
91911@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91912 * zero-length segments (without overruning the iovec).
91913 */
91914 while (bytes || unlikely(i->count && !iov->iov_len)) {
91915- int copy;
91916+ size_t copy;
91917
91918 copy = min(bytes, iov->iov_len - base);
91919 BUG_ON(!i->count || i->count < copy);
91920@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91921 *pos = i_size_read(inode);
91922
91923 if (limit != RLIM_INFINITY) {
91924+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91925 if (*pos >= limit) {
91926 send_sig(SIGXFSZ, current, 0);
91927 return -EFBIG;
91928diff --git a/mm/fremap.c b/mm/fremap.c
91929index 34feba6..315fe78 100644
91930--- a/mm/fremap.c
91931+++ b/mm/fremap.c
91932@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91933 retry:
91934 vma = find_vma(mm, start);
91935
91936+#ifdef CONFIG_PAX_SEGMEXEC
91937+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91938+ goto out;
91939+#endif
91940+
91941 /*
91942 * Make sure the vma is shared, that it supports prefaulting,
91943 * and that the remapped range is valid and fully within
91944diff --git a/mm/highmem.c b/mm/highmem.c
91945index b32b70c..e512eb0 100644
91946--- a/mm/highmem.c
91947+++ b/mm/highmem.c
91948@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91949 * So no dangers, even with speculative execution.
91950 */
91951 page = pte_page(pkmap_page_table[i]);
91952+ pax_open_kernel();
91953 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91954-
91955+ pax_close_kernel();
91956 set_page_address(page, NULL);
91957 need_flush = 1;
91958 }
91959@@ -198,9 +199,11 @@ start:
91960 }
91961 }
91962 vaddr = PKMAP_ADDR(last_pkmap_nr);
91963+
91964+ pax_open_kernel();
91965 set_pte_at(&init_mm, vaddr,
91966 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91967-
91968+ pax_close_kernel();
91969 pkmap_count[last_pkmap_nr] = 1;
91970 set_page_address(page, (void *)vaddr);
91971
91972diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91973index 2de3c84..4ecaf1b 100644
91974--- a/mm/hugetlb.c
91975+++ b/mm/hugetlb.c
91976@@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91977 struct hstate *h = &default_hstate;
91978 unsigned long tmp;
91979 int ret;
91980+ ctl_table_no_const hugetlb_table;
91981
91982 tmp = h->max_huge_pages;
91983
91984 if (write && h->order >= MAX_ORDER)
91985 return -EINVAL;
91986
91987- table->data = &tmp;
91988- table->maxlen = sizeof(unsigned long);
91989- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91990+ hugetlb_table = *table;
91991+ hugetlb_table.data = &tmp;
91992+ hugetlb_table.maxlen = sizeof(unsigned long);
91993+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91994 if (ret)
91995 goto out;
91996
91997@@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91998 struct hstate *h = &default_hstate;
91999 unsigned long tmp;
92000 int ret;
92001+ ctl_table_no_const hugetlb_table;
92002
92003 tmp = h->nr_overcommit_huge_pages;
92004
92005 if (write && h->order >= MAX_ORDER)
92006 return -EINVAL;
92007
92008- table->data = &tmp;
92009- table->maxlen = sizeof(unsigned long);
92010- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92011+ hugetlb_table = *table;
92012+ hugetlb_table.data = &tmp;
92013+ hugetlb_table.maxlen = sizeof(unsigned long);
92014+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92015 if (ret)
92016 goto out;
92017
92018@@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92019 return 1;
92020 }
92021
92022+#ifdef CONFIG_PAX_SEGMEXEC
92023+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92024+{
92025+ struct mm_struct *mm = vma->vm_mm;
92026+ struct vm_area_struct *vma_m;
92027+ unsigned long address_m;
92028+ pte_t *ptep_m;
92029+
92030+ vma_m = pax_find_mirror_vma(vma);
92031+ if (!vma_m)
92032+ return;
92033+
92034+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92035+ address_m = address + SEGMEXEC_TASK_SIZE;
92036+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92037+ get_page(page_m);
92038+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92039+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92040+}
92041+#endif
92042+
92043 /*
92044 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92045 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92046@@ -2715,6 +2740,11 @@ retry_avoidcopy:
92047 make_huge_pte(vma, new_page, 1));
92048 page_remove_rmap(old_page);
92049 hugepage_add_new_anon_rmap(new_page, vma, address);
92050+
92051+#ifdef CONFIG_PAX_SEGMEXEC
92052+ pax_mirror_huge_pte(vma, address, new_page);
92053+#endif
92054+
92055 /* Make the old page be freed below */
92056 new_page = old_page;
92057 }
92058@@ -2879,6 +2909,10 @@ retry:
92059 && (vma->vm_flags & VM_SHARED)));
92060 set_huge_pte_at(mm, address, ptep, new_pte);
92061
92062+#ifdef CONFIG_PAX_SEGMEXEC
92063+ pax_mirror_huge_pte(vma, address, page);
92064+#endif
92065+
92066 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92067 /* Optimization, do the COW without a second fault */
92068 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92069@@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92070 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
92071 struct hstate *h = hstate_vma(vma);
92072
92073+#ifdef CONFIG_PAX_SEGMEXEC
92074+ struct vm_area_struct *vma_m;
92075+#endif
92076+
92077 address &= huge_page_mask(h);
92078
92079 ptep = huge_pte_offset(mm, address);
92080@@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92081 VM_FAULT_SET_HINDEX(hstate_index(h));
92082 }
92083
92084+#ifdef CONFIG_PAX_SEGMEXEC
92085+ vma_m = pax_find_mirror_vma(vma);
92086+ if (vma_m) {
92087+ unsigned long address_m;
92088+
92089+ if (vma->vm_start > vma_m->vm_start) {
92090+ address_m = address;
92091+ address -= SEGMEXEC_TASK_SIZE;
92092+ vma = vma_m;
92093+ h = hstate_vma(vma);
92094+ } else
92095+ address_m = address + SEGMEXEC_TASK_SIZE;
92096+
92097+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92098+ return VM_FAULT_OOM;
92099+ address_m &= HPAGE_MASK;
92100+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92101+ }
92102+#endif
92103+
92104 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92105 if (!ptep)
92106 return VM_FAULT_OOM;
92107diff --git a/mm/internal.h b/mm/internal.h
92108index 3e91000..4741a60 100644
92109--- a/mm/internal.h
92110+++ b/mm/internal.h
92111@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92112 * in mm/page_alloc.c
92113 */
92114 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92115+extern void free_compound_page(struct page *page);
92116 extern void prep_compound_page(struct page *page, unsigned long order);
92117 #ifdef CONFIG_MEMORY_FAILURE
92118 extern bool is_free_buddy_page(struct page *page);
92119@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92120
92121 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92122 unsigned long, unsigned long,
92123- unsigned long, unsigned long);
92124+ unsigned long, unsigned long) __intentional_overflow(-1);
92125
92126 extern void set_pageblock_order(void);
92127 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92128diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92129index 31f01c5..7015178 100644
92130--- a/mm/kmemleak.c
92131+++ b/mm/kmemleak.c
92132@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92133
92134 for (i = 0; i < object->trace_len; i++) {
92135 void *ptr = (void *)object->trace[i];
92136- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92137+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92138 }
92139 }
92140
92141@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92142 return -ENOMEM;
92143 }
92144
92145- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92146+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92147 &kmemleak_fops);
92148 if (!dentry)
92149 pr_warning("Failed to create the debugfs kmemleak file\n");
92150diff --git a/mm/maccess.c b/mm/maccess.c
92151index d53adf9..03a24bf 100644
92152--- a/mm/maccess.c
92153+++ b/mm/maccess.c
92154@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92155 set_fs(KERNEL_DS);
92156 pagefault_disable();
92157 ret = __copy_from_user_inatomic(dst,
92158- (__force const void __user *)src, size);
92159+ (const void __force_user *)src, size);
92160 pagefault_enable();
92161 set_fs(old_fs);
92162
92163@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92164
92165 set_fs(KERNEL_DS);
92166 pagefault_disable();
92167- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92168+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92169 pagefault_enable();
92170 set_fs(old_fs);
92171
92172diff --git a/mm/madvise.c b/mm/madvise.c
92173index 539eeb9..e24a987 100644
92174--- a/mm/madvise.c
92175+++ b/mm/madvise.c
92176@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92177 pgoff_t pgoff;
92178 unsigned long new_flags = vma->vm_flags;
92179
92180+#ifdef CONFIG_PAX_SEGMEXEC
92181+ struct vm_area_struct *vma_m;
92182+#endif
92183+
92184 switch (behavior) {
92185 case MADV_NORMAL:
92186 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92187@@ -126,6 +130,13 @@ success:
92188 /*
92189 * vm_flags is protected by the mmap_sem held in write mode.
92190 */
92191+
92192+#ifdef CONFIG_PAX_SEGMEXEC
92193+ vma_m = pax_find_mirror_vma(vma);
92194+ if (vma_m)
92195+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92196+#endif
92197+
92198 vma->vm_flags = new_flags;
92199
92200 out:
92201@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92202 struct vm_area_struct **prev,
92203 unsigned long start, unsigned long end)
92204 {
92205+
92206+#ifdef CONFIG_PAX_SEGMEXEC
92207+ struct vm_area_struct *vma_m;
92208+#endif
92209+
92210 *prev = vma;
92211 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92212 return -EINVAL;
92213@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92214 zap_page_range(vma, start, end - start, &details);
92215 } else
92216 zap_page_range(vma, start, end - start, NULL);
92217+
92218+#ifdef CONFIG_PAX_SEGMEXEC
92219+ vma_m = pax_find_mirror_vma(vma);
92220+ if (vma_m) {
92221+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92222+ struct zap_details details = {
92223+ .nonlinear_vma = vma_m,
92224+ .last_index = ULONG_MAX,
92225+ };
92226+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92227+ } else
92228+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92229+ }
92230+#endif
92231+
92232 return 0;
92233 }
92234
92235@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92236 if (end < start)
92237 return error;
92238
92239+#ifdef CONFIG_PAX_SEGMEXEC
92240+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92241+ if (end > SEGMEXEC_TASK_SIZE)
92242+ return error;
92243+ } else
92244+#endif
92245+
92246+ if (end > TASK_SIZE)
92247+ return error;
92248+
92249 error = 0;
92250 if (end == start)
92251 return error;
92252diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92253index 90002ea..db1452d 100644
92254--- a/mm/memory-failure.c
92255+++ b/mm/memory-failure.c
92256@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92257
92258 int sysctl_memory_failure_recovery __read_mostly = 1;
92259
92260-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92261+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92262
92263 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92264
92265@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92266 pfn, t->comm, t->pid);
92267 si.si_signo = SIGBUS;
92268 si.si_errno = 0;
92269- si.si_addr = (void *)addr;
92270+ si.si_addr = (void __user *)addr;
92271 #ifdef __ARCH_SI_TRAPNO
92272 si.si_trapno = trapno;
92273 #endif
92274@@ -762,7 +762,7 @@ static struct page_state {
92275 unsigned long res;
92276 char *msg;
92277 int (*action)(struct page *p, unsigned long pfn);
92278-} error_states[] = {
92279+} __do_const error_states[] = {
92280 { reserved, reserved, "reserved kernel", me_kernel },
92281 /*
92282 * free pages are specially detected outside this table:
92283@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92284 nr_pages = 1 << compound_order(hpage);
92285 else /* normal page or thp */
92286 nr_pages = 1;
92287- atomic_long_add(nr_pages, &num_poisoned_pages);
92288+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92289
92290 /*
92291 * We need/can do nothing about count=0 pages.
92292@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92293 if (!PageHWPoison(hpage)
92294 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92295 || (p != hpage && TestSetPageHWPoison(hpage))) {
92296- atomic_long_sub(nr_pages, &num_poisoned_pages);
92297+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92298 return 0;
92299 }
92300 set_page_hwpoison_huge_page(hpage);
92301@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92302 }
92303 if (hwpoison_filter(p)) {
92304 if (TestClearPageHWPoison(p))
92305- atomic_long_sub(nr_pages, &num_poisoned_pages);
92306+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92307 unlock_page(hpage);
92308 put_page(hpage);
92309 return 0;
92310@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92311 return 0;
92312 }
92313 if (TestClearPageHWPoison(p))
92314- atomic_long_dec(&num_poisoned_pages);
92315+ atomic_long_dec_unchecked(&num_poisoned_pages);
92316 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92317 return 0;
92318 }
92319@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92320 */
92321 if (TestClearPageHWPoison(page)) {
92322 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92323- atomic_long_sub(nr_pages, &num_poisoned_pages);
92324+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92325 freeit = 1;
92326 if (PageHuge(page))
92327 clear_page_hwpoison_huge_page(page);
92328@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92329 if (PageHuge(page)) {
92330 set_page_hwpoison_huge_page(hpage);
92331 dequeue_hwpoisoned_huge_page(hpage);
92332- atomic_long_add(1 << compound_order(hpage),
92333+ atomic_long_add_unchecked(1 << compound_order(hpage),
92334 &num_poisoned_pages);
92335 } else {
92336 SetPageHWPoison(page);
92337- atomic_long_inc(&num_poisoned_pages);
92338+ atomic_long_inc_unchecked(&num_poisoned_pages);
92339 }
92340 }
92341 return ret;
92342@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92343 put_page(page);
92344 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92345 SetPageHWPoison(page);
92346- atomic_long_inc(&num_poisoned_pages);
92347+ atomic_long_inc_unchecked(&num_poisoned_pages);
92348 return 0;
92349 }
92350
92351@@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92352 if (!is_free_buddy_page(page))
92353 pr_info("soft offline: %#lx: page leaked\n",
92354 pfn);
92355- atomic_long_inc(&num_poisoned_pages);
92356+ atomic_long_inc_unchecked(&num_poisoned_pages);
92357 }
92358 } else {
92359 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92360@@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92361 if (PageHuge(page)) {
92362 set_page_hwpoison_huge_page(hpage);
92363 dequeue_hwpoisoned_huge_page(hpage);
92364- atomic_long_add(1 << compound_order(hpage),
92365+ atomic_long_add_unchecked(1 << compound_order(hpage),
92366 &num_poisoned_pages);
92367 } else {
92368 SetPageHWPoison(page);
92369- atomic_long_inc(&num_poisoned_pages);
92370+ atomic_long_inc_unchecked(&num_poisoned_pages);
92371 }
92372 }
92373 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92374diff --git a/mm/memory.c b/mm/memory.c
92375index 22dfa61..90d7ec5 100644
92376--- a/mm/memory.c
92377+++ b/mm/memory.c
92378@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92379 free_pte_range(tlb, pmd, addr);
92380 } while (pmd++, addr = next, addr != end);
92381
92382+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92383 start &= PUD_MASK;
92384 if (start < floor)
92385 return;
92386@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92387 pmd = pmd_offset(pud, start);
92388 pud_clear(pud);
92389 pmd_free_tlb(tlb, pmd, start);
92390+#endif
92391+
92392 }
92393
92394 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92395@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92396 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92397 } while (pud++, addr = next, addr != end);
92398
92399+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92400 start &= PGDIR_MASK;
92401 if (start < floor)
92402 return;
92403@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92404 pud = pud_offset(pgd, start);
92405 pgd_clear(pgd);
92406 pud_free_tlb(tlb, pud, start);
92407+#endif
92408+
92409 }
92410
92411 /*
92412@@ -1636,12 +1642,6 @@ no_page_table:
92413 return page;
92414 }
92415
92416-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92417-{
92418- return stack_guard_page_start(vma, addr) ||
92419- stack_guard_page_end(vma, addr+PAGE_SIZE);
92420-}
92421-
92422 /**
92423 * __get_user_pages() - pin user pages in memory
92424 * @tsk: task_struct of target task
92425@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92426
92427 i = 0;
92428
92429- do {
92430+ while (nr_pages) {
92431 struct vm_area_struct *vma;
92432
92433- vma = find_extend_vma(mm, start);
92434+ vma = find_vma(mm, start);
92435 if (!vma && in_gate_area(mm, start)) {
92436 unsigned long pg = start & PAGE_MASK;
92437 pgd_t *pgd;
92438@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92439 goto next_page;
92440 }
92441
92442- if (!vma ||
92443+ if (!vma || start < vma->vm_start ||
92444 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92445 !(vm_flags & vma->vm_flags))
92446 return i ? : -EFAULT;
92447@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92448 int ret;
92449 unsigned int fault_flags = 0;
92450
92451- /* For mlock, just skip the stack guard page. */
92452- if (foll_flags & FOLL_MLOCK) {
92453- if (stack_guard_page(vma, start))
92454- goto next_page;
92455- }
92456 if (foll_flags & FOLL_WRITE)
92457 fault_flags |= FAULT_FLAG_WRITE;
92458 if (nonblocking)
92459@@ -1893,7 +1888,7 @@ next_page:
92460 start += page_increm * PAGE_SIZE;
92461 nr_pages -= page_increm;
92462 } while (nr_pages && start < vma->vm_end);
92463- } while (nr_pages);
92464+ }
92465 return i;
92466 }
92467 EXPORT_SYMBOL(__get_user_pages);
92468@@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92469 unsigned long address, unsigned int fault_flags)
92470 {
92471 struct vm_area_struct *vma;
92472+ vm_flags_t vm_flags;
92473 int ret;
92474
92475 vma = find_extend_vma(mm, address);
92476 if (!vma || address < vma->vm_start)
92477 return -EFAULT;
92478
92479+ vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92480+ if (!(vm_flags & vma->vm_flags))
92481+ return -EFAULT;
92482+
92483 ret = handle_mm_fault(mm, vma, address, fault_flags);
92484 if (ret & VM_FAULT_ERROR) {
92485 if (ret & VM_FAULT_OOM)
92486@@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92487 page_add_file_rmap(page);
92488 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92489
92490+#ifdef CONFIG_PAX_SEGMEXEC
92491+ pax_mirror_file_pte(vma, addr, page, ptl);
92492+#endif
92493+
92494 retval = 0;
92495 pte_unmap_unlock(pte, ptl);
92496 return retval;
92497@@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92498 if (!page_count(page))
92499 return -EINVAL;
92500 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92501+
92502+#ifdef CONFIG_PAX_SEGMEXEC
92503+ struct vm_area_struct *vma_m;
92504+#endif
92505+
92506 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92507 BUG_ON(vma->vm_flags & VM_PFNMAP);
92508 vma->vm_flags |= VM_MIXEDMAP;
92509+
92510+#ifdef CONFIG_PAX_SEGMEXEC
92511+ vma_m = pax_find_mirror_vma(vma);
92512+ if (vma_m)
92513+ vma_m->vm_flags |= VM_MIXEDMAP;
92514+#endif
92515+
92516 }
92517 return insert_page(vma, addr, page, vma->vm_page_prot);
92518 }
92519@@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92520 unsigned long pfn)
92521 {
92522 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92523+ BUG_ON(vma->vm_mirror);
92524
92525 if (addr < vma->vm_start || addr >= vma->vm_end)
92526 return -EFAULT;
92527@@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92528
92529 BUG_ON(pud_huge(*pud));
92530
92531- pmd = pmd_alloc(mm, pud, addr);
92532+ pmd = (mm == &init_mm) ?
92533+ pmd_alloc_kernel(mm, pud, addr) :
92534+ pmd_alloc(mm, pud, addr);
92535 if (!pmd)
92536 return -ENOMEM;
92537 do {
92538@@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92539 unsigned long next;
92540 int err;
92541
92542- pud = pud_alloc(mm, pgd, addr);
92543+ pud = (mm == &init_mm) ?
92544+ pud_alloc_kernel(mm, pgd, addr) :
92545+ pud_alloc(mm, pgd, addr);
92546 if (!pud)
92547 return -ENOMEM;
92548 do {
92549@@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92550 copy_user_highpage(dst, src, va, vma);
92551 }
92552
92553+#ifdef CONFIG_PAX_SEGMEXEC
92554+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92555+{
92556+ struct mm_struct *mm = vma->vm_mm;
92557+ spinlock_t *ptl;
92558+ pte_t *pte, entry;
92559+
92560+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92561+ entry = *pte;
92562+ if (!pte_present(entry)) {
92563+ if (!pte_none(entry)) {
92564+ BUG_ON(pte_file(entry));
92565+ free_swap_and_cache(pte_to_swp_entry(entry));
92566+ pte_clear_not_present_full(mm, address, pte, 0);
92567+ }
92568+ } else {
92569+ struct page *page;
92570+
92571+ flush_cache_page(vma, address, pte_pfn(entry));
92572+ entry = ptep_clear_flush(vma, address, pte);
92573+ BUG_ON(pte_dirty(entry));
92574+ page = vm_normal_page(vma, address, entry);
92575+ if (page) {
92576+ update_hiwater_rss(mm);
92577+ if (PageAnon(page))
92578+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92579+ else
92580+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92581+ page_remove_rmap(page);
92582+ page_cache_release(page);
92583+ }
92584+ }
92585+ pte_unmap_unlock(pte, ptl);
92586+}
92587+
92588+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92589+ *
92590+ * the ptl of the lower mapped page is held on entry and is not released on exit
92591+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92592+ */
92593+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92594+{
92595+ struct mm_struct *mm = vma->vm_mm;
92596+ unsigned long address_m;
92597+ spinlock_t *ptl_m;
92598+ struct vm_area_struct *vma_m;
92599+ pmd_t *pmd_m;
92600+ pte_t *pte_m, entry_m;
92601+
92602+ BUG_ON(!page_m || !PageAnon(page_m));
92603+
92604+ vma_m = pax_find_mirror_vma(vma);
92605+ if (!vma_m)
92606+ return;
92607+
92608+ BUG_ON(!PageLocked(page_m));
92609+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92610+ address_m = address + SEGMEXEC_TASK_SIZE;
92611+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92612+ pte_m = pte_offset_map(pmd_m, address_m);
92613+ ptl_m = pte_lockptr(mm, pmd_m);
92614+ if (ptl != ptl_m) {
92615+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92616+ if (!pte_none(*pte_m))
92617+ goto out;
92618+ }
92619+
92620+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92621+ page_cache_get(page_m);
92622+ page_add_anon_rmap(page_m, vma_m, address_m);
92623+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92624+ set_pte_at(mm, address_m, pte_m, entry_m);
92625+ update_mmu_cache(vma_m, address_m, pte_m);
92626+out:
92627+ if (ptl != ptl_m)
92628+ spin_unlock(ptl_m);
92629+ pte_unmap(pte_m);
92630+ unlock_page(page_m);
92631+}
92632+
92633+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92634+{
92635+ struct mm_struct *mm = vma->vm_mm;
92636+ unsigned long address_m;
92637+ spinlock_t *ptl_m;
92638+ struct vm_area_struct *vma_m;
92639+ pmd_t *pmd_m;
92640+ pte_t *pte_m, entry_m;
92641+
92642+ BUG_ON(!page_m || PageAnon(page_m));
92643+
92644+ vma_m = pax_find_mirror_vma(vma);
92645+ if (!vma_m)
92646+ return;
92647+
92648+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92649+ address_m = address + SEGMEXEC_TASK_SIZE;
92650+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92651+ pte_m = pte_offset_map(pmd_m, address_m);
92652+ ptl_m = pte_lockptr(mm, pmd_m);
92653+ if (ptl != ptl_m) {
92654+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92655+ if (!pte_none(*pte_m))
92656+ goto out;
92657+ }
92658+
92659+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92660+ page_cache_get(page_m);
92661+ page_add_file_rmap(page_m);
92662+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92663+ set_pte_at(mm, address_m, pte_m, entry_m);
92664+ update_mmu_cache(vma_m, address_m, pte_m);
92665+out:
92666+ if (ptl != ptl_m)
92667+ spin_unlock(ptl_m);
92668+ pte_unmap(pte_m);
92669+}
92670+
92671+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92672+{
92673+ struct mm_struct *mm = vma->vm_mm;
92674+ unsigned long address_m;
92675+ spinlock_t *ptl_m;
92676+ struct vm_area_struct *vma_m;
92677+ pmd_t *pmd_m;
92678+ pte_t *pte_m, entry_m;
92679+
92680+ vma_m = pax_find_mirror_vma(vma);
92681+ if (!vma_m)
92682+ return;
92683+
92684+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92685+ address_m = address + SEGMEXEC_TASK_SIZE;
92686+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92687+ pte_m = pte_offset_map(pmd_m, address_m);
92688+ ptl_m = pte_lockptr(mm, pmd_m);
92689+ if (ptl != ptl_m) {
92690+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92691+ if (!pte_none(*pte_m))
92692+ goto out;
92693+ }
92694+
92695+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92696+ set_pte_at(mm, address_m, pte_m, entry_m);
92697+out:
92698+ if (ptl != ptl_m)
92699+ spin_unlock(ptl_m);
92700+ pte_unmap(pte_m);
92701+}
92702+
92703+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92704+{
92705+ struct page *page_m;
92706+ pte_t entry;
92707+
92708+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92709+ goto out;
92710+
92711+ entry = *pte;
92712+ page_m = vm_normal_page(vma, address, entry);
92713+ if (!page_m)
92714+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92715+ else if (PageAnon(page_m)) {
92716+ if (pax_find_mirror_vma(vma)) {
92717+ pte_unmap_unlock(pte, ptl);
92718+ lock_page(page_m);
92719+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92720+ if (pte_same(entry, *pte))
92721+ pax_mirror_anon_pte(vma, address, page_m, ptl);
92722+ else
92723+ unlock_page(page_m);
92724+ }
92725+ } else
92726+ pax_mirror_file_pte(vma, address, page_m, ptl);
92727+
92728+out:
92729+ pte_unmap_unlock(pte, ptl);
92730+}
92731+#endif
92732+
92733 /*
92734 * This routine handles present pages, when users try to write
92735 * to a shared page. It is done by copying the page to a new address
92736@@ -2810,6 +3011,12 @@ gotten:
92737 */
92738 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92739 if (likely(pte_same(*page_table, orig_pte))) {
92740+
92741+#ifdef CONFIG_PAX_SEGMEXEC
92742+ if (pax_find_mirror_vma(vma))
92743+ BUG_ON(!trylock_page(new_page));
92744+#endif
92745+
92746 if (old_page) {
92747 if (!PageAnon(old_page)) {
92748 dec_mm_counter_fast(mm, MM_FILEPAGES);
92749@@ -2861,6 +3068,10 @@ gotten:
92750 page_remove_rmap(old_page);
92751 }
92752
92753+#ifdef CONFIG_PAX_SEGMEXEC
92754+ pax_mirror_anon_pte(vma, address, new_page, ptl);
92755+#endif
92756+
92757 /* Free the old page.. */
92758 new_page = old_page;
92759 ret |= VM_FAULT_WRITE;
92760@@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92761 swap_free(entry);
92762 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92763 try_to_free_swap(page);
92764+
92765+#ifdef CONFIG_PAX_SEGMEXEC
92766+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92767+#endif
92768+
92769 unlock_page(page);
92770 if (page != swapcache) {
92771 /*
92772@@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92773
92774 /* No need to invalidate - it was non-present before */
92775 update_mmu_cache(vma, address, page_table);
92776+
92777+#ifdef CONFIG_PAX_SEGMEXEC
92778+ pax_mirror_anon_pte(vma, address, page, ptl);
92779+#endif
92780+
92781 unlock:
92782 pte_unmap_unlock(page_table, ptl);
92783 out:
92784@@ -3180,40 +3401,6 @@ out_release:
92785 }
92786
92787 /*
92788- * This is like a special single-page "expand_{down|up}wards()",
92789- * except we must first make sure that 'address{-|+}PAGE_SIZE'
92790- * doesn't hit another vma.
92791- */
92792-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92793-{
92794- address &= PAGE_MASK;
92795- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92796- struct vm_area_struct *prev = vma->vm_prev;
92797-
92798- /*
92799- * Is there a mapping abutting this one below?
92800- *
92801- * That's only ok if it's the same stack mapping
92802- * that has gotten split..
92803- */
92804- if (prev && prev->vm_end == address)
92805- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92806-
92807- expand_downwards(vma, address - PAGE_SIZE);
92808- }
92809- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92810- struct vm_area_struct *next = vma->vm_next;
92811-
92812- /* As VM_GROWSDOWN but s/below/above/ */
92813- if (next && next->vm_start == address + PAGE_SIZE)
92814- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92815-
92816- expand_upwards(vma, address + PAGE_SIZE);
92817- }
92818- return 0;
92819-}
92820-
92821-/*
92822 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92823 * but allow concurrent faults), and pte mapped but not yet locked.
92824 * We return with mmap_sem still held, but pte unmapped and unlocked.
92825@@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92826 unsigned long address, pte_t *page_table, pmd_t *pmd,
92827 unsigned int flags)
92828 {
92829- struct page *page;
92830+ struct page *page = NULL;
92831 spinlock_t *ptl;
92832 pte_t entry;
92833
92834- pte_unmap(page_table);
92835-
92836- /* Check if we need to add a guard page to the stack */
92837- if (check_stack_guard_page(vma, address) < 0)
92838- return VM_FAULT_SIGBUS;
92839-
92840- /* Use the zero-page for reads */
92841 if (!(flags & FAULT_FLAG_WRITE)) {
92842 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92843 vma->vm_page_prot));
92844- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92845+ ptl = pte_lockptr(mm, pmd);
92846+ spin_lock(ptl);
92847 if (!pte_none(*page_table))
92848 goto unlock;
92849 goto setpte;
92850 }
92851
92852 /* Allocate our own private page. */
92853+ pte_unmap(page_table);
92854+
92855 if (unlikely(anon_vma_prepare(vma)))
92856 goto oom;
92857 page = alloc_zeroed_user_highpage_movable(vma, address);
92858@@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92859 if (!pte_none(*page_table))
92860 goto release;
92861
92862+#ifdef CONFIG_PAX_SEGMEXEC
92863+ if (pax_find_mirror_vma(vma))
92864+ BUG_ON(!trylock_page(page));
92865+#endif
92866+
92867 inc_mm_counter_fast(mm, MM_ANONPAGES);
92868 page_add_new_anon_rmap(page, vma, address);
92869 setpte:
92870@@ -3273,6 +3461,12 @@ setpte:
92871
92872 /* No need to invalidate - it was non-present before */
92873 update_mmu_cache(vma, address, page_table);
92874+
92875+#ifdef CONFIG_PAX_SEGMEXEC
92876+ if (page)
92877+ pax_mirror_anon_pte(vma, address, page, ptl);
92878+#endif
92879+
92880 unlock:
92881 pte_unmap_unlock(page_table, ptl);
92882 return 0;
92883@@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92884 */
92885 /* Only go through if we didn't race with anybody else... */
92886 if (likely(pte_same(*page_table, orig_pte))) {
92887+
92888+#ifdef CONFIG_PAX_SEGMEXEC
92889+ if (anon && pax_find_mirror_vma(vma))
92890+ BUG_ON(!trylock_page(page));
92891+#endif
92892+
92893 flush_icache_page(vma, page);
92894 entry = mk_pte(page, vma->vm_page_prot);
92895 if (flags & FAULT_FLAG_WRITE)
92896@@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92897
92898 /* no need to invalidate: a not-present page won't be cached */
92899 update_mmu_cache(vma, address, page_table);
92900+
92901+#ifdef CONFIG_PAX_SEGMEXEC
92902+ if (anon)
92903+ pax_mirror_anon_pte(vma, address, page, ptl);
92904+ else
92905+ pax_mirror_file_pte(vma, address, page, ptl);
92906+#endif
92907+
92908 } else {
92909 if (cow_page)
92910 mem_cgroup_uncharge_page(cow_page);
92911@@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92912 if (flags & FAULT_FLAG_WRITE)
92913 flush_tlb_fix_spurious_fault(vma, address);
92914 }
92915+
92916+#ifdef CONFIG_PAX_SEGMEXEC
92917+ pax_mirror_pte(vma, address, pte, pmd, ptl);
92918+ return 0;
92919+#endif
92920+
92921 unlock:
92922 pte_unmap_unlock(pte, ptl);
92923 return 0;
92924@@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92925 pmd_t *pmd;
92926 pte_t *pte;
92927
92928+#ifdef CONFIG_PAX_SEGMEXEC
92929+ struct vm_area_struct *vma_m;
92930+#endif
92931+
92932 if (unlikely(is_vm_hugetlb_page(vma)))
92933 return hugetlb_fault(mm, vma, address, flags);
92934
92935+#ifdef CONFIG_PAX_SEGMEXEC
92936+ vma_m = pax_find_mirror_vma(vma);
92937+ if (vma_m) {
92938+ unsigned long address_m;
92939+ pgd_t *pgd_m;
92940+ pud_t *pud_m;
92941+ pmd_t *pmd_m;
92942+
92943+ if (vma->vm_start > vma_m->vm_start) {
92944+ address_m = address;
92945+ address -= SEGMEXEC_TASK_SIZE;
92946+ vma = vma_m;
92947+ } else
92948+ address_m = address + SEGMEXEC_TASK_SIZE;
92949+
92950+ pgd_m = pgd_offset(mm, address_m);
92951+ pud_m = pud_alloc(mm, pgd_m, address_m);
92952+ if (!pud_m)
92953+ return VM_FAULT_OOM;
92954+ pmd_m = pmd_alloc(mm, pud_m, address_m);
92955+ if (!pmd_m)
92956+ return VM_FAULT_OOM;
92957+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92958+ return VM_FAULT_OOM;
92959+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92960+ }
92961+#endif
92962+
92963 pgd = pgd_offset(mm, address);
92964 pud = pud_alloc(mm, pgd, address);
92965 if (!pud)
92966@@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92967 spin_unlock(&mm->page_table_lock);
92968 return 0;
92969 }
92970+
92971+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92972+{
92973+ pud_t *new = pud_alloc_one(mm, address);
92974+ if (!new)
92975+ return -ENOMEM;
92976+
92977+ smp_wmb(); /* See comment in __pte_alloc */
92978+
92979+ spin_lock(&mm->page_table_lock);
92980+ if (pgd_present(*pgd)) /* Another has populated it */
92981+ pud_free(mm, new);
92982+ else
92983+ pgd_populate_kernel(mm, pgd, new);
92984+ spin_unlock(&mm->page_table_lock);
92985+ return 0;
92986+}
92987 #endif /* __PAGETABLE_PUD_FOLDED */
92988
92989 #ifndef __PAGETABLE_PMD_FOLDED
92990@@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92991 spin_unlock(&mm->page_table_lock);
92992 return 0;
92993 }
92994+
92995+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92996+{
92997+ pmd_t *new = pmd_alloc_one(mm, address);
92998+ if (!new)
92999+ return -ENOMEM;
93000+
93001+ smp_wmb(); /* See comment in __pte_alloc */
93002+
93003+ spin_lock(&mm->page_table_lock);
93004+#ifndef __ARCH_HAS_4LEVEL_HACK
93005+ if (pud_present(*pud)) /* Another has populated it */
93006+ pmd_free(mm, new);
93007+ else
93008+ pud_populate_kernel(mm, pud, new);
93009+#else
93010+ if (pgd_present(*pud)) /* Another has populated it */
93011+ pmd_free(mm, new);
93012+ else
93013+ pgd_populate_kernel(mm, pud, new);
93014+#endif /* __ARCH_HAS_4LEVEL_HACK */
93015+ spin_unlock(&mm->page_table_lock);
93016+ return 0;
93017+}
93018 #endif /* __PAGETABLE_PMD_FOLDED */
93019
93020 #if !defined(__HAVE_ARCH_GATE_AREA)
93021@@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
93022 gate_vma.vm_start = FIXADDR_USER_START;
93023 gate_vma.vm_end = FIXADDR_USER_END;
93024 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93025- gate_vma.vm_page_prot = __P101;
93026+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93027
93028 return 0;
93029 }
93030@@ -4011,8 +4298,8 @@ out:
93031 return ret;
93032 }
93033
93034-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93035- void *buf, int len, int write)
93036+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93037+ void *buf, size_t len, int write)
93038 {
93039 resource_size_t phys_addr;
93040 unsigned long prot = 0;
93041@@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93042 * Access another process' address space as given in mm. If non-NULL, use the
93043 * given task for page fault accounting.
93044 */
93045-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93046- unsigned long addr, void *buf, int len, int write)
93047+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93048+ unsigned long addr, void *buf, size_t len, int write)
93049 {
93050 struct vm_area_struct *vma;
93051 void *old_buf = buf;
93052@@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93053 down_read(&mm->mmap_sem);
93054 /* ignore errors, just check how much was successfully transferred */
93055 while (len) {
93056- int bytes, ret, offset;
93057+ ssize_t bytes, ret, offset;
93058 void *maddr;
93059 struct page *page = NULL;
93060
93061@@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93062 *
93063 * The caller must hold a reference on @mm.
93064 */
93065-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93066- void *buf, int len, int write)
93067+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93068+ void *buf, size_t len, int write)
93069 {
93070 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93071 }
93072@@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93073 * Source/target buffer must be kernel space,
93074 * Do not walk the page table directly, use get_user_pages
93075 */
93076-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93077- void *buf, int len, int write)
93078+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93079+ void *buf, size_t len, int write)
93080 {
93081 struct mm_struct *mm;
93082- int ret;
93083+ ssize_t ret;
93084
93085 mm = get_task_mm(tsk);
93086 if (!mm)
93087diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93088index ae3c8f3..fa4ee8e 100644
93089--- a/mm/mempolicy.c
93090+++ b/mm/mempolicy.c
93091@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93092 unsigned long vmstart;
93093 unsigned long vmend;
93094
93095+#ifdef CONFIG_PAX_SEGMEXEC
93096+ struct vm_area_struct *vma_m;
93097+#endif
93098+
93099 vma = find_vma(mm, start);
93100 if (!vma || vma->vm_start > start)
93101 return -EFAULT;
93102@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93103 err = vma_replace_policy(vma, new_pol);
93104 if (err)
93105 goto out;
93106+
93107+#ifdef CONFIG_PAX_SEGMEXEC
93108+ vma_m = pax_find_mirror_vma(vma);
93109+ if (vma_m) {
93110+ err = vma_replace_policy(vma_m, new_pol);
93111+ if (err)
93112+ goto out;
93113+ }
93114+#endif
93115+
93116 }
93117
93118 out:
93119@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93120
93121 if (end < start)
93122 return -EINVAL;
93123+
93124+#ifdef CONFIG_PAX_SEGMEXEC
93125+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93126+ if (end > SEGMEXEC_TASK_SIZE)
93127+ return -EINVAL;
93128+ } else
93129+#endif
93130+
93131+ if (end > TASK_SIZE)
93132+ return -EINVAL;
93133+
93134 if (end == start)
93135 return 0;
93136
93137@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93138 */
93139 tcred = __task_cred(task);
93140 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93141- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93142- !capable(CAP_SYS_NICE)) {
93143+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93144 rcu_read_unlock();
93145 err = -EPERM;
93146 goto out_put;
93147@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93148 goto out;
93149 }
93150
93151+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93152+ if (mm != current->mm &&
93153+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93154+ mmput(mm);
93155+ err = -EPERM;
93156+ goto out;
93157+ }
93158+#endif
93159+
93160 err = do_migrate_pages(mm, old, new,
93161 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93162
93163diff --git a/mm/migrate.c b/mm/migrate.c
93164index bed4880..a493f67 100644
93165--- a/mm/migrate.c
93166+++ b/mm/migrate.c
93167@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93168 */
93169 tcred = __task_cred(task);
93170 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93171- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93172- !capable(CAP_SYS_NICE)) {
93173+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93174 rcu_read_unlock();
93175 err = -EPERM;
93176 goto out;
93177diff --git a/mm/mlock.c b/mm/mlock.c
93178index b1eb536..091d154 100644
93179--- a/mm/mlock.c
93180+++ b/mm/mlock.c
93181@@ -14,6 +14,7 @@
93182 #include <linux/pagevec.h>
93183 #include <linux/mempolicy.h>
93184 #include <linux/syscalls.h>
93185+#include <linux/security.h>
93186 #include <linux/sched.h>
93187 #include <linux/export.h>
93188 #include <linux/rmap.h>
93189@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93190 {
93191 unsigned long nstart, end, tmp;
93192 struct vm_area_struct * vma, * prev;
93193- int error;
93194+ int error = 0;
93195
93196 VM_BUG_ON(start & ~PAGE_MASK);
93197 VM_BUG_ON(len != PAGE_ALIGN(len));
93198@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93199 return -EINVAL;
93200 if (end == start)
93201 return 0;
93202+ if (end > TASK_SIZE)
93203+ return -EINVAL;
93204+
93205 vma = find_vma(current->mm, start);
93206 if (!vma || vma->vm_start > start)
93207 return -ENOMEM;
93208@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93209 for (nstart = start ; ; ) {
93210 vm_flags_t newflags;
93211
93212+#ifdef CONFIG_PAX_SEGMEXEC
93213+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93214+ break;
93215+#endif
93216+
93217 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93218
93219 newflags = vma->vm_flags & ~VM_LOCKED;
93220@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93221 locked += current->mm->locked_vm;
93222
93223 /* check against resource limits */
93224+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93225 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93226 error = do_mlock(start, len, 1);
93227
93228@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93229 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93230 vm_flags_t newflags;
93231
93232+#ifdef CONFIG_PAX_SEGMEXEC
93233+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93234+ break;
93235+#endif
93236+
93237 newflags = vma->vm_flags & ~VM_LOCKED;
93238 if (flags & MCL_CURRENT)
93239 newflags |= VM_LOCKED;
93240@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93241 lock_limit >>= PAGE_SHIFT;
93242
93243 ret = -ENOMEM;
93244+
93245+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93246+
93247 down_write(&current->mm->mmap_sem);
93248-
93249 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93250 capable(CAP_IPC_LOCK))
93251 ret = do_mlockall(flags);
93252diff --git a/mm/mmap.c b/mm/mmap.c
93253index 20ff0c3..a9eda98 100644
93254--- a/mm/mmap.c
93255+++ b/mm/mmap.c
93256@@ -36,6 +36,7 @@
93257 #include <linux/sched/sysctl.h>
93258 #include <linux/notifier.h>
93259 #include <linux/memory.h>
93260+#include <linux/random.h>
93261
93262 #include <asm/uaccess.h>
93263 #include <asm/cacheflush.h>
93264@@ -52,6 +53,16 @@
93265 #define arch_rebalance_pgtables(addr, len) (addr)
93266 #endif
93267
93268+static inline void verify_mm_writelocked(struct mm_struct *mm)
93269+{
93270+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93271+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93272+ up_read(&mm->mmap_sem);
93273+ BUG();
93274+ }
93275+#endif
93276+}
93277+
93278 static void unmap_region(struct mm_struct *mm,
93279 struct vm_area_struct *vma, struct vm_area_struct *prev,
93280 unsigned long start, unsigned long end);
93281@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93282 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93283 *
93284 */
93285-pgprot_t protection_map[16] = {
93286+pgprot_t protection_map[16] __read_only = {
93287 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93288 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93289 };
93290
93291-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93292+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93293 {
93294- return __pgprot(pgprot_val(protection_map[vm_flags &
93295+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93296 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93297 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93298+
93299+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93300+ if (!(__supported_pte_mask & _PAGE_NX) &&
93301+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93302+ (vm_flags & (VM_READ | VM_WRITE)))
93303+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93304+#endif
93305+
93306+ return prot;
93307 }
93308 EXPORT_SYMBOL(vm_get_page_prot);
93309
93310@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93311 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93312 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93313 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93314+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93315 /*
93316 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93317 * other variables. It can be updated by several CPUs frequently.
93318@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93319 struct vm_area_struct *next = vma->vm_next;
93320
93321 might_sleep();
93322+ BUG_ON(vma->vm_mirror);
93323 if (vma->vm_ops && vma->vm_ops->close)
93324 vma->vm_ops->close(vma);
93325 if (vma->vm_file)
93326@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93327 * not page aligned -Ram Gupta
93328 */
93329 rlim = rlimit(RLIMIT_DATA);
93330+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93331 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93332 (mm->end_data - mm->start_data) > rlim)
93333 goto out;
93334@@ -940,6 +963,12 @@ static int
93335 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93336 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93337 {
93338+
93339+#ifdef CONFIG_PAX_SEGMEXEC
93340+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93341+ return 0;
93342+#endif
93343+
93344 if (is_mergeable_vma(vma, file, vm_flags) &&
93345 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93346 if (vma->vm_pgoff == vm_pgoff)
93347@@ -959,6 +988,12 @@ static int
93348 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93349 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93350 {
93351+
93352+#ifdef CONFIG_PAX_SEGMEXEC
93353+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93354+ return 0;
93355+#endif
93356+
93357 if (is_mergeable_vma(vma, file, vm_flags) &&
93358 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93359 pgoff_t vm_pglen;
93360@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93361 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93362 struct vm_area_struct *prev, unsigned long addr,
93363 unsigned long end, unsigned long vm_flags,
93364- struct anon_vma *anon_vma, struct file *file,
93365+ struct anon_vma *anon_vma, struct file *file,
93366 pgoff_t pgoff, struct mempolicy *policy)
93367 {
93368 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93369 struct vm_area_struct *area, *next;
93370 int err;
93371
93372+#ifdef CONFIG_PAX_SEGMEXEC
93373+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93374+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93375+
93376+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93377+#endif
93378+
93379 /*
93380 * We later require that vma->vm_flags == vm_flags,
93381 * so this tests vma->vm_flags & VM_SPECIAL, too.
93382@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93383 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93384 next = next->vm_next;
93385
93386+#ifdef CONFIG_PAX_SEGMEXEC
93387+ if (prev)
93388+ prev_m = pax_find_mirror_vma(prev);
93389+ if (area)
93390+ area_m = pax_find_mirror_vma(area);
93391+ if (next)
93392+ next_m = pax_find_mirror_vma(next);
93393+#endif
93394+
93395 /*
93396 * Can it merge with the predecessor?
93397 */
93398@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93399 /* cases 1, 6 */
93400 err = vma_adjust(prev, prev->vm_start,
93401 next->vm_end, prev->vm_pgoff, NULL);
93402- } else /* cases 2, 5, 7 */
93403+
93404+#ifdef CONFIG_PAX_SEGMEXEC
93405+ if (!err && prev_m)
93406+ err = vma_adjust(prev_m, prev_m->vm_start,
93407+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93408+#endif
93409+
93410+ } else { /* cases 2, 5, 7 */
93411 err = vma_adjust(prev, prev->vm_start,
93412 end, prev->vm_pgoff, NULL);
93413+
93414+#ifdef CONFIG_PAX_SEGMEXEC
93415+ if (!err && prev_m)
93416+ err = vma_adjust(prev_m, prev_m->vm_start,
93417+ end_m, prev_m->vm_pgoff, NULL);
93418+#endif
93419+
93420+ }
93421 if (err)
93422 return NULL;
93423 khugepaged_enter_vma_merge(prev);
93424@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93425 mpol_equal(policy, vma_policy(next)) &&
93426 can_vma_merge_before(next, vm_flags,
93427 anon_vma, file, pgoff+pglen)) {
93428- if (prev && addr < prev->vm_end) /* case 4 */
93429+ if (prev && addr < prev->vm_end) { /* case 4 */
93430 err = vma_adjust(prev, prev->vm_start,
93431 addr, prev->vm_pgoff, NULL);
93432- else /* cases 3, 8 */
93433+
93434+#ifdef CONFIG_PAX_SEGMEXEC
93435+ if (!err && prev_m)
93436+ err = vma_adjust(prev_m, prev_m->vm_start,
93437+ addr_m, prev_m->vm_pgoff, NULL);
93438+#endif
93439+
93440+ } else { /* cases 3, 8 */
93441 err = vma_adjust(area, addr, next->vm_end,
93442 next->vm_pgoff - pglen, NULL);
93443+
93444+#ifdef CONFIG_PAX_SEGMEXEC
93445+ if (!err && area_m)
93446+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93447+ next_m->vm_pgoff - pglen, NULL);
93448+#endif
93449+
93450+ }
93451 if (err)
93452 return NULL;
93453 khugepaged_enter_vma_merge(area);
93454@@ -1172,8 +1253,10 @@ none:
93455 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93456 struct file *file, long pages)
93457 {
93458- const unsigned long stack_flags
93459- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93460+
93461+#ifdef CONFIG_PAX_RANDMMAP
93462+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93463+#endif
93464
93465 mm->total_vm += pages;
93466
93467@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93468 mm->shared_vm += pages;
93469 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93470 mm->exec_vm += pages;
93471- } else if (flags & stack_flags)
93472+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93473 mm->stack_vm += pages;
93474 }
93475 #endif /* CONFIG_PROC_FS */
93476@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93477 locked += mm->locked_vm;
93478 lock_limit = rlimit(RLIMIT_MEMLOCK);
93479 lock_limit >>= PAGE_SHIFT;
93480+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93481 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93482 return -EAGAIN;
93483 }
93484@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93485 * (the exception is when the underlying filesystem is noexec
93486 * mounted, in which case we dont add PROT_EXEC.)
93487 */
93488- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93489+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93490 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93491 prot |= PROT_EXEC;
93492
93493@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93494 /* Obtain the address to map to. we verify (or select) it and ensure
93495 * that it represents a valid section of the address space.
93496 */
93497- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93498+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93499 if (addr & ~PAGE_MASK)
93500 return addr;
93501
93502@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93503 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93504 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93505
93506+#ifdef CONFIG_PAX_MPROTECT
93507+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93508+
93509+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93510+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93511+ mm->binfmt->handle_mmap)
93512+ mm->binfmt->handle_mmap(file);
93513+#endif
93514+
93515+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93516+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93517+ gr_log_rwxmmap(file);
93518+
93519+#ifdef CONFIG_PAX_EMUPLT
93520+ vm_flags &= ~VM_EXEC;
93521+#else
93522+ return -EPERM;
93523+#endif
93524+
93525+ }
93526+
93527+ if (!(vm_flags & VM_EXEC))
93528+ vm_flags &= ~VM_MAYEXEC;
93529+#else
93530+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93531+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93532+#endif
93533+ else
93534+ vm_flags &= ~VM_MAYWRITE;
93535+ }
93536+#endif
93537+
93538+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93539+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93540+ vm_flags &= ~VM_PAGEEXEC;
93541+#endif
93542+
93543 if (flags & MAP_LOCKED)
93544 if (!can_do_mlock())
93545 return -EPERM;
93546@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93547 vm_flags |= VM_NORESERVE;
93548 }
93549
93550+ if (!gr_acl_handle_mmap(file, prot))
93551+ return -EACCES;
93552+
93553 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93554 if (!IS_ERR_VALUE(addr) &&
93555 ((vm_flags & VM_LOCKED) ||
93556@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93557 vm_flags_t vm_flags = vma->vm_flags;
93558
93559 /* If it was private or non-writable, the write bit is already clear */
93560- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93561+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93562 return 0;
93563
93564 /* The backer wishes to know when pages are first written to? */
93565@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93566 struct rb_node **rb_link, *rb_parent;
93567 unsigned long charged = 0;
93568
93569+#ifdef CONFIG_PAX_SEGMEXEC
93570+ struct vm_area_struct *vma_m = NULL;
93571+#endif
93572+
93573+ /*
93574+ * mm->mmap_sem is required to protect against another thread
93575+ * changing the mappings in case we sleep.
93576+ */
93577+ verify_mm_writelocked(mm);
93578+
93579 /* Check against address space limit. */
93580+
93581+#ifdef CONFIG_PAX_RANDMMAP
93582+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93583+#endif
93584+
93585 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93586 unsigned long nr_pages;
93587
93588@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93589
93590 /* Clear old maps */
93591 error = -ENOMEM;
93592-munmap_back:
93593 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93594 if (do_munmap(mm, addr, len))
93595 return -ENOMEM;
93596- goto munmap_back;
93597+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93598 }
93599
93600 /*
93601@@ -1554,6 +1692,16 @@ munmap_back:
93602 goto unacct_error;
93603 }
93604
93605+#ifdef CONFIG_PAX_SEGMEXEC
93606+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93607+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93608+ if (!vma_m) {
93609+ error = -ENOMEM;
93610+ goto free_vma;
93611+ }
93612+ }
93613+#endif
93614+
93615 vma->vm_mm = mm;
93616 vma->vm_start = addr;
93617 vma->vm_end = addr + len;
93618@@ -1573,6 +1721,13 @@ munmap_back:
93619 if (error)
93620 goto unmap_and_free_vma;
93621
93622+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93623+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93624+ vma->vm_flags |= VM_PAGEEXEC;
93625+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93626+ }
93627+#endif
93628+
93629 /* Can addr have changed??
93630 *
93631 * Answer: Yes, several device drivers can do it in their
93632@@ -1606,6 +1761,12 @@ munmap_back:
93633 }
93634
93635 vma_link(mm, vma, prev, rb_link, rb_parent);
93636+
93637+#ifdef CONFIG_PAX_SEGMEXEC
93638+ if (vma_m)
93639+ BUG_ON(pax_mirror_vma(vma_m, vma));
93640+#endif
93641+
93642 /* Once vma denies write, undo our temporary denial count */
93643 if (vm_flags & VM_DENYWRITE)
93644 allow_write_access(file);
93645@@ -1614,6 +1775,7 @@ out:
93646 perf_event_mmap(vma);
93647
93648 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93649+ track_exec_limit(mm, addr, addr + len, vm_flags);
93650 if (vm_flags & VM_LOCKED) {
93651 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93652 vma == get_gate_vma(current->mm)))
93653@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
93654 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93655 charged = 0;
93656 free_vma:
93657+
93658+#ifdef CONFIG_PAX_SEGMEXEC
93659+ if (vma_m)
93660+ kmem_cache_free(vm_area_cachep, vma_m);
93661+#endif
93662+
93663 kmem_cache_free(vm_area_cachep, vma);
93664 unacct_error:
93665 if (charged)
93666@@ -1653,7 +1821,63 @@ unacct_error:
93667 return error;
93668 }
93669
93670-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93671+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93672+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93673+{
93674+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93675+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93676+
93677+ return 0;
93678+}
93679+#endif
93680+
93681+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93682+{
93683+ if (!vma) {
93684+#ifdef CONFIG_STACK_GROWSUP
93685+ if (addr > sysctl_heap_stack_gap)
93686+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93687+ else
93688+ vma = find_vma(current->mm, 0);
93689+ if (vma && (vma->vm_flags & VM_GROWSUP))
93690+ return false;
93691+#endif
93692+ return true;
93693+ }
93694+
93695+ if (addr + len > vma->vm_start)
93696+ return false;
93697+
93698+ if (vma->vm_flags & VM_GROWSDOWN)
93699+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93700+#ifdef CONFIG_STACK_GROWSUP
93701+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93702+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93703+#endif
93704+ else if (offset)
93705+ return offset <= vma->vm_start - addr - len;
93706+
93707+ return true;
93708+}
93709+
93710+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93711+{
93712+ if (vma->vm_start < len)
93713+ return -ENOMEM;
93714+
93715+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
93716+ if (offset <= vma->vm_start - len)
93717+ return vma->vm_start - len - offset;
93718+ else
93719+ return -ENOMEM;
93720+ }
93721+
93722+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
93723+ return vma->vm_start - len - sysctl_heap_stack_gap;
93724+ return -ENOMEM;
93725+}
93726+
93727+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93728 {
93729 /*
93730 * We implement the search by looking for an rbtree node that
93731@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93732 }
93733 }
93734
93735- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93736+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93737 check_current:
93738 /* Check if current node has a suitable gap */
93739 if (gap_start > high_limit)
93740 return -ENOMEM;
93741+
93742+ if (gap_end - gap_start > info->threadstack_offset)
93743+ gap_start += info->threadstack_offset;
93744+ else
93745+ gap_start = gap_end;
93746+
93747+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93748+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93749+ gap_start += sysctl_heap_stack_gap;
93750+ else
93751+ gap_start = gap_end;
93752+ }
93753+ if (vma->vm_flags & VM_GROWSDOWN) {
93754+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93755+ gap_end -= sysctl_heap_stack_gap;
93756+ else
93757+ gap_end = gap_start;
93758+ }
93759 if (gap_end >= low_limit && gap_end - gap_start >= length)
93760 goto found;
93761
93762@@ -1755,7 +1997,7 @@ found:
93763 return gap_start;
93764 }
93765
93766-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93767+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93768 {
93769 struct mm_struct *mm = current->mm;
93770 struct vm_area_struct *vma;
93771@@ -1809,6 +2051,24 @@ check_current:
93772 gap_end = vma->vm_start;
93773 if (gap_end < low_limit)
93774 return -ENOMEM;
93775+
93776+ if (gap_end - gap_start > info->threadstack_offset)
93777+ gap_end -= info->threadstack_offset;
93778+ else
93779+ gap_end = gap_start;
93780+
93781+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93782+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93783+ gap_start += sysctl_heap_stack_gap;
93784+ else
93785+ gap_start = gap_end;
93786+ }
93787+ if (vma->vm_flags & VM_GROWSDOWN) {
93788+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93789+ gap_end -= sysctl_heap_stack_gap;
93790+ else
93791+ gap_end = gap_start;
93792+ }
93793 if (gap_start <= high_limit && gap_end - gap_start >= length)
93794 goto found;
93795
93796@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93797 struct mm_struct *mm = current->mm;
93798 struct vm_area_struct *vma;
93799 struct vm_unmapped_area_info info;
93800+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93801
93802 if (len > TASK_SIZE - mmap_min_addr)
93803 return -ENOMEM;
93804@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93805 if (flags & MAP_FIXED)
93806 return addr;
93807
93808+#ifdef CONFIG_PAX_RANDMMAP
93809+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93810+#endif
93811+
93812 if (addr) {
93813 addr = PAGE_ALIGN(addr);
93814 vma = find_vma(mm, addr);
93815 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93816- (!vma || addr + len <= vma->vm_start))
93817+ check_heap_stack_gap(vma, addr, len, offset))
93818 return addr;
93819 }
93820
93821@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93822 info.low_limit = mm->mmap_base;
93823 info.high_limit = TASK_SIZE;
93824 info.align_mask = 0;
93825+ info.threadstack_offset = offset;
93826 return vm_unmapped_area(&info);
93827 }
93828 #endif
93829@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93830 struct mm_struct *mm = current->mm;
93831 unsigned long addr = addr0;
93832 struct vm_unmapped_area_info info;
93833+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93834
93835 /* requested length too big for entire address space */
93836 if (len > TASK_SIZE - mmap_min_addr)
93837@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93838 if (flags & MAP_FIXED)
93839 return addr;
93840
93841+#ifdef CONFIG_PAX_RANDMMAP
93842+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93843+#endif
93844+
93845 /* requesting a specific address */
93846 if (addr) {
93847 addr = PAGE_ALIGN(addr);
93848 vma = find_vma(mm, addr);
93849 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93850- (!vma || addr + len <= vma->vm_start))
93851+ check_heap_stack_gap(vma, addr, len, offset))
93852 return addr;
93853 }
93854
93855@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93856 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93857 info.high_limit = mm->mmap_base;
93858 info.align_mask = 0;
93859+ info.threadstack_offset = offset;
93860 addr = vm_unmapped_area(&info);
93861
93862 /*
93863@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93864 VM_BUG_ON(addr != -ENOMEM);
93865 info.flags = 0;
93866 info.low_limit = TASK_UNMAPPED_BASE;
93867+
93868+#ifdef CONFIG_PAX_RANDMMAP
93869+ if (mm->pax_flags & MF_PAX_RANDMMAP)
93870+ info.low_limit += mm->delta_mmap;
93871+#endif
93872+
93873 info.high_limit = TASK_SIZE;
93874 addr = vm_unmapped_area(&info);
93875 }
93876@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93877 return vma;
93878 }
93879
93880+#ifdef CONFIG_PAX_SEGMEXEC
93881+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93882+{
93883+ struct vm_area_struct *vma_m;
93884+
93885+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93886+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93887+ BUG_ON(vma->vm_mirror);
93888+ return NULL;
93889+ }
93890+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93891+ vma_m = vma->vm_mirror;
93892+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93893+ BUG_ON(vma->vm_file != vma_m->vm_file);
93894+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93895+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93896+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93897+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93898+ return vma_m;
93899+}
93900+#endif
93901+
93902 /*
93903 * Verify that the stack growth is acceptable and
93904 * update accounting. This is shared with both the
93905@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93906 return -ENOMEM;
93907
93908 /* Stack limit test */
93909+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
93910 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93911 return -ENOMEM;
93912
93913@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93914 locked = mm->locked_vm + grow;
93915 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93916 limit >>= PAGE_SHIFT;
93917+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93918 if (locked > limit && !capable(CAP_IPC_LOCK))
93919 return -ENOMEM;
93920 }
93921@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93922 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93923 * vma is the last one with address > vma->vm_end. Have to extend vma.
93924 */
93925+#ifndef CONFIG_IA64
93926+static
93927+#endif
93928 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93929 {
93930 int error;
93931+ bool locknext;
93932
93933 if (!(vma->vm_flags & VM_GROWSUP))
93934 return -EFAULT;
93935
93936+ /* Also guard against wrapping around to address 0. */
93937+ if (address < PAGE_ALIGN(address+1))
93938+ address = PAGE_ALIGN(address+1);
93939+ else
93940+ return -ENOMEM;
93941+
93942 /*
93943 * We must make sure the anon_vma is allocated
93944 * so that the anon_vma locking is not a noop.
93945 */
93946 if (unlikely(anon_vma_prepare(vma)))
93947 return -ENOMEM;
93948+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93949+ if (locknext && anon_vma_prepare(vma->vm_next))
93950+ return -ENOMEM;
93951 vma_lock_anon_vma(vma);
93952+ if (locknext)
93953+ vma_lock_anon_vma(vma->vm_next);
93954
93955 /*
93956 * vma->vm_start/vm_end cannot change under us because the caller
93957 * is required to hold the mmap_sem in read mode. We need the
93958- * anon_vma lock to serialize against concurrent expand_stacks.
93959- * Also guard against wrapping around to address 0.
93960+ * anon_vma locks to serialize against concurrent expand_stacks
93961+ * and expand_upwards.
93962 */
93963- if (address < PAGE_ALIGN(address+4))
93964- address = PAGE_ALIGN(address+4);
93965- else {
93966- vma_unlock_anon_vma(vma);
93967- return -ENOMEM;
93968- }
93969 error = 0;
93970
93971 /* Somebody else might have raced and expanded it already */
93972- if (address > vma->vm_end) {
93973+ 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)
93974+ error = -ENOMEM;
93975+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93976 unsigned long size, grow;
93977
93978 size = address - vma->vm_start;
93979@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93980 }
93981 }
93982 }
93983+ if (locknext)
93984+ vma_unlock_anon_vma(vma->vm_next);
93985 vma_unlock_anon_vma(vma);
93986 khugepaged_enter_vma_merge(vma);
93987 validate_mm(vma->vm_mm);
93988@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
93989 unsigned long address)
93990 {
93991 int error;
93992+ bool lockprev = false;
93993+ struct vm_area_struct *prev;
93994
93995 /*
93996 * We must make sure the anon_vma is allocated
93997@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
93998 if (error)
93999 return error;
94000
94001+ prev = vma->vm_prev;
94002+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94003+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94004+#endif
94005+ if (lockprev && anon_vma_prepare(prev))
94006+ return -ENOMEM;
94007+ if (lockprev)
94008+ vma_lock_anon_vma(prev);
94009+
94010 vma_lock_anon_vma(vma);
94011
94012 /*
94013@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
94014 */
94015
94016 /* Somebody else might have raced and expanded it already */
94017- if (address < vma->vm_start) {
94018+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94019+ error = -ENOMEM;
94020+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94021 unsigned long size, grow;
94022
94023+#ifdef CONFIG_PAX_SEGMEXEC
94024+ struct vm_area_struct *vma_m;
94025+
94026+ vma_m = pax_find_mirror_vma(vma);
94027+#endif
94028+
94029 size = vma->vm_end - address;
94030 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94031
94032@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
94033 vma->vm_pgoff -= grow;
94034 anon_vma_interval_tree_post_update_vma(vma);
94035 vma_gap_update(vma);
94036+
94037+#ifdef CONFIG_PAX_SEGMEXEC
94038+ if (vma_m) {
94039+ anon_vma_interval_tree_pre_update_vma(vma_m);
94040+ vma_m->vm_start -= grow << PAGE_SHIFT;
94041+ vma_m->vm_pgoff -= grow;
94042+ anon_vma_interval_tree_post_update_vma(vma_m);
94043+ vma_gap_update(vma_m);
94044+ }
94045+#endif
94046+
94047 spin_unlock(&vma->vm_mm->page_table_lock);
94048
94049+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94050 perf_event_mmap(vma);
94051 }
94052 }
94053 }
94054 vma_unlock_anon_vma(vma);
94055+ if (lockprev)
94056+ vma_unlock_anon_vma(prev);
94057 khugepaged_enter_vma_merge(vma);
94058 validate_mm(vma->vm_mm);
94059 return error;
94060@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94061 do {
94062 long nrpages = vma_pages(vma);
94063
94064+#ifdef CONFIG_PAX_SEGMEXEC
94065+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94066+ vma = remove_vma(vma);
94067+ continue;
94068+ }
94069+#endif
94070+
94071 if (vma->vm_flags & VM_ACCOUNT)
94072 nr_accounted += nrpages;
94073 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94074@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94075 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94076 vma->vm_prev = NULL;
94077 do {
94078+
94079+#ifdef CONFIG_PAX_SEGMEXEC
94080+ if (vma->vm_mirror) {
94081+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94082+ vma->vm_mirror->vm_mirror = NULL;
94083+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94084+ vma->vm_mirror = NULL;
94085+ }
94086+#endif
94087+
94088 vma_rb_erase(vma, &mm->mm_rb);
94089 mm->map_count--;
94090 tail_vma = vma;
94091@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94092 struct vm_area_struct *new;
94093 int err = -ENOMEM;
94094
94095+#ifdef CONFIG_PAX_SEGMEXEC
94096+ struct vm_area_struct *vma_m, *new_m = NULL;
94097+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94098+#endif
94099+
94100 if (is_vm_hugetlb_page(vma) && (addr &
94101 ~(huge_page_mask(hstate_vma(vma)))))
94102 return -EINVAL;
94103
94104+#ifdef CONFIG_PAX_SEGMEXEC
94105+ vma_m = pax_find_mirror_vma(vma);
94106+#endif
94107+
94108 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94109 if (!new)
94110 goto out_err;
94111
94112+#ifdef CONFIG_PAX_SEGMEXEC
94113+ if (vma_m) {
94114+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94115+ if (!new_m) {
94116+ kmem_cache_free(vm_area_cachep, new);
94117+ goto out_err;
94118+ }
94119+ }
94120+#endif
94121+
94122 /* most fields are the same, copy all, and then fixup */
94123 *new = *vma;
94124
94125@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94126 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94127 }
94128
94129+#ifdef CONFIG_PAX_SEGMEXEC
94130+ if (vma_m) {
94131+ *new_m = *vma_m;
94132+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94133+ new_m->vm_mirror = new;
94134+ new->vm_mirror = new_m;
94135+
94136+ if (new_below)
94137+ new_m->vm_end = addr_m;
94138+ else {
94139+ new_m->vm_start = addr_m;
94140+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94141+ }
94142+ }
94143+#endif
94144+
94145 err = vma_dup_policy(vma, new);
94146 if (err)
94147 goto out_free_vma;
94148@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94149 else
94150 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94151
94152+#ifdef CONFIG_PAX_SEGMEXEC
94153+ if (!err && vma_m) {
94154+ struct mempolicy *pol = vma_policy(new);
94155+
94156+ if (anon_vma_clone(new_m, vma_m))
94157+ goto out_free_mpol;
94158+
94159+ mpol_get(pol);
94160+ set_vma_policy(new_m, pol);
94161+
94162+ if (new_m->vm_file)
94163+ get_file(new_m->vm_file);
94164+
94165+ if (new_m->vm_ops && new_m->vm_ops->open)
94166+ new_m->vm_ops->open(new_m);
94167+
94168+ if (new_below)
94169+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94170+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94171+ else
94172+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94173+
94174+ if (err) {
94175+ if (new_m->vm_ops && new_m->vm_ops->close)
94176+ new_m->vm_ops->close(new_m);
94177+ if (new_m->vm_file)
94178+ fput(new_m->vm_file);
94179+ mpol_put(pol);
94180+ }
94181+ }
94182+#endif
94183+
94184 /* Success. */
94185 if (!err)
94186 return 0;
94187@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94188 new->vm_ops->close(new);
94189 if (new->vm_file)
94190 fput(new->vm_file);
94191- unlink_anon_vmas(new);
94192 out_free_mpol:
94193 mpol_put(vma_policy(new));
94194 out_free_vma:
94195+
94196+#ifdef CONFIG_PAX_SEGMEXEC
94197+ if (new_m) {
94198+ unlink_anon_vmas(new_m);
94199+ kmem_cache_free(vm_area_cachep, new_m);
94200+ }
94201+#endif
94202+
94203+ unlink_anon_vmas(new);
94204 kmem_cache_free(vm_area_cachep, new);
94205 out_err:
94206 return err;
94207@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94208 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94209 unsigned long addr, int new_below)
94210 {
94211+
94212+#ifdef CONFIG_PAX_SEGMEXEC
94213+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94214+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94215+ if (mm->map_count >= sysctl_max_map_count-1)
94216+ return -ENOMEM;
94217+ } else
94218+#endif
94219+
94220 if (mm->map_count >= sysctl_max_map_count)
94221 return -ENOMEM;
94222
94223@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94224 * work. This now handles partial unmappings.
94225 * Jeremy Fitzhardinge <jeremy@goop.org>
94226 */
94227+#ifdef CONFIG_PAX_SEGMEXEC
94228 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94229 {
94230+ int ret = __do_munmap(mm, start, len);
94231+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94232+ return ret;
94233+
94234+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94235+}
94236+
94237+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94238+#else
94239+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94240+#endif
94241+{
94242 unsigned long end;
94243 struct vm_area_struct *vma, *prev, *last;
94244
94245+ /*
94246+ * mm->mmap_sem is required to protect against another thread
94247+ * changing the mappings in case we sleep.
94248+ */
94249+ verify_mm_writelocked(mm);
94250+
94251 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94252 return -EINVAL;
94253
94254@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94255 /* Fix up all other VM information */
94256 remove_vma_list(mm, vma);
94257
94258+ track_exec_limit(mm, start, end, 0UL);
94259+
94260 return 0;
94261 }
94262
94263@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94264 int ret;
94265 struct mm_struct *mm = current->mm;
94266
94267+
94268+#ifdef CONFIG_PAX_SEGMEXEC
94269+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94270+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94271+ return -EINVAL;
94272+#endif
94273+
94274 down_write(&mm->mmap_sem);
94275 ret = do_munmap(mm, start, len);
94276 up_write(&mm->mmap_sem);
94277@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94278 return vm_munmap(addr, len);
94279 }
94280
94281-static inline void verify_mm_writelocked(struct mm_struct *mm)
94282-{
94283-#ifdef CONFIG_DEBUG_VM
94284- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94285- WARN_ON(1);
94286- up_read(&mm->mmap_sem);
94287- }
94288-#endif
94289-}
94290-
94291 /*
94292 * this is really a simplified "do_mmap". it only handles
94293 * anonymous maps. eventually we may be able to do some
94294@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94295 struct rb_node ** rb_link, * rb_parent;
94296 pgoff_t pgoff = addr >> PAGE_SHIFT;
94297 int error;
94298+ unsigned long charged;
94299
94300 len = PAGE_ALIGN(len);
94301 if (!len)
94302@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94303
94304 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94305
94306+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94307+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94308+ flags &= ~VM_EXEC;
94309+
94310+#ifdef CONFIG_PAX_MPROTECT
94311+ if (mm->pax_flags & MF_PAX_MPROTECT)
94312+ flags &= ~VM_MAYEXEC;
94313+#endif
94314+
94315+ }
94316+#endif
94317+
94318 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94319 if (error & ~PAGE_MASK)
94320 return error;
94321
94322+ charged = len >> PAGE_SHIFT;
94323+
94324 error = mlock_future_check(mm, mm->def_flags, len);
94325 if (error)
94326 return error;
94327@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94328 /*
94329 * Clear old maps. this also does some error checking for us
94330 */
94331- munmap_back:
94332 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94333 if (do_munmap(mm, addr, len))
94334 return -ENOMEM;
94335- goto munmap_back;
94336+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94337 }
94338
94339 /* Check against address space limits *after* clearing old maps... */
94340- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94341+ if (!may_expand_vm(mm, charged))
94342 return -ENOMEM;
94343
94344 if (mm->map_count > sysctl_max_map_count)
94345 return -ENOMEM;
94346
94347- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94348+ if (security_vm_enough_memory_mm(mm, charged))
94349 return -ENOMEM;
94350
94351 /* Can we just expand an old private anonymous mapping? */
94352@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94353 */
94354 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94355 if (!vma) {
94356- vm_unacct_memory(len >> PAGE_SHIFT);
94357+ vm_unacct_memory(charged);
94358 return -ENOMEM;
94359 }
94360
94361@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94362 vma_link(mm, vma, prev, rb_link, rb_parent);
94363 out:
94364 perf_event_mmap(vma);
94365- mm->total_vm += len >> PAGE_SHIFT;
94366+ mm->total_vm += charged;
94367 if (flags & VM_LOCKED)
94368- mm->locked_vm += (len >> PAGE_SHIFT);
94369+ mm->locked_vm += charged;
94370 vma->vm_flags |= VM_SOFTDIRTY;
94371+ track_exec_limit(mm, addr, addr + len, flags);
94372 return addr;
94373 }
94374
94375@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94376 while (vma) {
94377 if (vma->vm_flags & VM_ACCOUNT)
94378 nr_accounted += vma_pages(vma);
94379+ vma->vm_mirror = NULL;
94380 vma = remove_vma(vma);
94381 }
94382 vm_unacct_memory(nr_accounted);
94383@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94384 struct vm_area_struct *prev;
94385 struct rb_node **rb_link, *rb_parent;
94386
94387+#ifdef CONFIG_PAX_SEGMEXEC
94388+ struct vm_area_struct *vma_m = NULL;
94389+#endif
94390+
94391+ if (security_mmap_addr(vma->vm_start))
94392+ return -EPERM;
94393+
94394 /*
94395 * The vm_pgoff of a purely anonymous vma should be irrelevant
94396 * until its first write fault, when page's anon_vma and index
94397@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94398 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94399 return -ENOMEM;
94400
94401+#ifdef CONFIG_PAX_SEGMEXEC
94402+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94403+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94404+ if (!vma_m)
94405+ return -ENOMEM;
94406+ }
94407+#endif
94408+
94409 vma_link(mm, vma, prev, rb_link, rb_parent);
94410+
94411+#ifdef CONFIG_PAX_SEGMEXEC
94412+ if (vma_m)
94413+ BUG_ON(pax_mirror_vma(vma_m, vma));
94414+#endif
94415+
94416 return 0;
94417 }
94418
94419@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94420 struct rb_node **rb_link, *rb_parent;
94421 bool faulted_in_anon_vma = true;
94422
94423+ BUG_ON(vma->vm_mirror);
94424+
94425 /*
94426 * If anonymous vma has not yet been faulted, update new pgoff
94427 * to match new location, to increase its chance of merging.
94428@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94429 return NULL;
94430 }
94431
94432+#ifdef CONFIG_PAX_SEGMEXEC
94433+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94434+{
94435+ struct vm_area_struct *prev_m;
94436+ struct rb_node **rb_link_m, *rb_parent_m;
94437+ struct mempolicy *pol_m;
94438+
94439+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94440+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94441+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94442+ *vma_m = *vma;
94443+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94444+ if (anon_vma_clone(vma_m, vma))
94445+ return -ENOMEM;
94446+ pol_m = vma_policy(vma_m);
94447+ mpol_get(pol_m);
94448+ set_vma_policy(vma_m, pol_m);
94449+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94450+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94451+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94452+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94453+ if (vma_m->vm_file)
94454+ get_file(vma_m->vm_file);
94455+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94456+ vma_m->vm_ops->open(vma_m);
94457+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94458+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94459+ vma_m->vm_mirror = vma;
94460+ vma->vm_mirror = vma_m;
94461+ return 0;
94462+}
94463+#endif
94464+
94465 /*
94466 * Return true if the calling process may expand its vm space by the passed
94467 * number of pages
94468@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94469
94470 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94471
94472+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94473 if (cur + npages > lim)
94474 return 0;
94475 return 1;
94476@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94477 vma->vm_start = addr;
94478 vma->vm_end = addr + len;
94479
94480+#ifdef CONFIG_PAX_MPROTECT
94481+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94482+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94483+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94484+ return -EPERM;
94485+ if (!(vm_flags & VM_EXEC))
94486+ vm_flags &= ~VM_MAYEXEC;
94487+#else
94488+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94489+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94490+#endif
94491+ else
94492+ vm_flags &= ~VM_MAYWRITE;
94493+ }
94494+#endif
94495+
94496 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94497 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94498
94499diff --git a/mm/mprotect.c b/mm/mprotect.c
94500index 769a67a..414d24f 100644
94501--- a/mm/mprotect.c
94502+++ b/mm/mprotect.c
94503@@ -24,10 +24,18 @@
94504 #include <linux/migrate.h>
94505 #include <linux/perf_event.h>
94506 #include <linux/ksm.h>
94507+#include <linux/sched/sysctl.h>
94508+
94509+#ifdef CONFIG_PAX_MPROTECT
94510+#include <linux/elf.h>
94511+#include <linux/binfmts.h>
94512+#endif
94513+
94514 #include <asm/uaccess.h>
94515 #include <asm/pgtable.h>
94516 #include <asm/cacheflush.h>
94517 #include <asm/tlbflush.h>
94518+#include <asm/mmu_context.h>
94519
94520 #ifndef pgprot_modify
94521 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94522@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94523 return pages;
94524 }
94525
94526+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94527+/* called while holding the mmap semaphor for writing except stack expansion */
94528+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94529+{
94530+ unsigned long oldlimit, newlimit = 0UL;
94531+
94532+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94533+ return;
94534+
94535+ spin_lock(&mm->page_table_lock);
94536+ oldlimit = mm->context.user_cs_limit;
94537+ if ((prot & VM_EXEC) && oldlimit < end)
94538+ /* USER_CS limit moved up */
94539+ newlimit = end;
94540+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94541+ /* USER_CS limit moved down */
94542+ newlimit = start;
94543+
94544+ if (newlimit) {
94545+ mm->context.user_cs_limit = newlimit;
94546+
94547+#ifdef CONFIG_SMP
94548+ wmb();
94549+ cpus_clear(mm->context.cpu_user_cs_mask);
94550+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94551+#endif
94552+
94553+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94554+ }
94555+ spin_unlock(&mm->page_table_lock);
94556+ if (newlimit == end) {
94557+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94558+
94559+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94560+ if (is_vm_hugetlb_page(vma))
94561+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94562+ else
94563+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94564+ }
94565+}
94566+#endif
94567+
94568 int
94569 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94570 unsigned long start, unsigned long end, unsigned long newflags)
94571@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94572 int error;
94573 int dirty_accountable = 0;
94574
94575+#ifdef CONFIG_PAX_SEGMEXEC
94576+ struct vm_area_struct *vma_m = NULL;
94577+ unsigned long start_m, end_m;
94578+
94579+ start_m = start + SEGMEXEC_TASK_SIZE;
94580+ end_m = end + SEGMEXEC_TASK_SIZE;
94581+#endif
94582+
94583 if (newflags == oldflags) {
94584 *pprev = vma;
94585 return 0;
94586 }
94587
94588+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94589+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94590+
94591+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94592+ return -ENOMEM;
94593+
94594+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94595+ return -ENOMEM;
94596+ }
94597+
94598 /*
94599 * If we make a private mapping writable we increase our commit;
94600 * but (without finer accounting) cannot reduce our commit if we
94601@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94602 }
94603 }
94604
94605+#ifdef CONFIG_PAX_SEGMEXEC
94606+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94607+ if (start != vma->vm_start) {
94608+ error = split_vma(mm, vma, start, 1);
94609+ if (error)
94610+ goto fail;
94611+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94612+ *pprev = (*pprev)->vm_next;
94613+ }
94614+
94615+ if (end != vma->vm_end) {
94616+ error = split_vma(mm, vma, end, 0);
94617+ if (error)
94618+ goto fail;
94619+ }
94620+
94621+ if (pax_find_mirror_vma(vma)) {
94622+ error = __do_munmap(mm, start_m, end_m - start_m);
94623+ if (error)
94624+ goto fail;
94625+ } else {
94626+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94627+ if (!vma_m) {
94628+ error = -ENOMEM;
94629+ goto fail;
94630+ }
94631+ vma->vm_flags = newflags;
94632+ error = pax_mirror_vma(vma_m, vma);
94633+ if (error) {
94634+ vma->vm_flags = oldflags;
94635+ goto fail;
94636+ }
94637+ }
94638+ }
94639+#endif
94640+
94641 /*
94642 * First try to merge with previous and/or next vma.
94643 */
94644@@ -277,9 +381,21 @@ success:
94645 * vm_flags and vm_page_prot are protected by the mmap_sem
94646 * held in write mode.
94647 */
94648+
94649+#ifdef CONFIG_PAX_SEGMEXEC
94650+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94651+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94652+#endif
94653+
94654 vma->vm_flags = newflags;
94655+
94656+#ifdef CONFIG_PAX_MPROTECT
94657+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94658+ mm->binfmt->handle_mprotect(vma, newflags);
94659+#endif
94660+
94661 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94662- vm_get_page_prot(newflags));
94663+ vm_get_page_prot(vma->vm_flags));
94664
94665 if (vma_wants_writenotify(vma)) {
94666 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94667@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94668 end = start + len;
94669 if (end <= start)
94670 return -ENOMEM;
94671+
94672+#ifdef CONFIG_PAX_SEGMEXEC
94673+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94674+ if (end > SEGMEXEC_TASK_SIZE)
94675+ return -EINVAL;
94676+ } else
94677+#endif
94678+
94679+ if (end > TASK_SIZE)
94680+ return -EINVAL;
94681+
94682 if (!arch_validate_prot(prot))
94683 return -EINVAL;
94684
94685@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94686 /*
94687 * Does the application expect PROT_READ to imply PROT_EXEC:
94688 */
94689- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94690+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94691 prot |= PROT_EXEC;
94692
94693 vm_flags = calc_vm_prot_bits(prot);
94694@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94695 if (start > vma->vm_start)
94696 prev = vma;
94697
94698+#ifdef CONFIG_PAX_MPROTECT
94699+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94700+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
94701+#endif
94702+
94703 for (nstart = start ; ; ) {
94704 unsigned long newflags;
94705
94706@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94707
94708 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94709 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94710+ if (prot & (PROT_WRITE | PROT_EXEC))
94711+ gr_log_rwxmprotect(vma);
94712+
94713+ error = -EACCES;
94714+ goto out;
94715+ }
94716+
94717+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94718 error = -EACCES;
94719 goto out;
94720 }
94721@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94722 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94723 if (error)
94724 goto out;
94725+
94726+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
94727+
94728 nstart = tmp;
94729
94730 if (nstart < prev->vm_end)
94731diff --git a/mm/mremap.c b/mm/mremap.c
94732index 0843feb..4f5b2e6 100644
94733--- a/mm/mremap.c
94734+++ b/mm/mremap.c
94735@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94736 continue;
94737 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94738 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94739+
94740+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94741+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94742+ pte = pte_exprotect(pte);
94743+#endif
94744+
94745 pte = move_soft_dirty_pte(pte);
94746 set_pte_at(mm, new_addr, new_pte, pte);
94747 }
94748@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94749 if (is_vm_hugetlb_page(vma))
94750 goto Einval;
94751
94752+#ifdef CONFIG_PAX_SEGMEXEC
94753+ if (pax_find_mirror_vma(vma))
94754+ goto Einval;
94755+#endif
94756+
94757 /* We can't remap across vm area boundaries */
94758 if (old_len > vma->vm_end - addr)
94759 goto Efault;
94760@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94761 unsigned long ret = -EINVAL;
94762 unsigned long charged = 0;
94763 unsigned long map_flags;
94764+ unsigned long pax_task_size = TASK_SIZE;
94765
94766 if (new_addr & ~PAGE_MASK)
94767 goto out;
94768
94769- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94770+#ifdef CONFIG_PAX_SEGMEXEC
94771+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94772+ pax_task_size = SEGMEXEC_TASK_SIZE;
94773+#endif
94774+
94775+ pax_task_size -= PAGE_SIZE;
94776+
94777+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94778 goto out;
94779
94780 /* Check if the location we're moving into overlaps the
94781 * old location at all, and fail if it does.
94782 */
94783- if ((new_addr <= addr) && (new_addr+new_len) > addr)
94784- goto out;
94785-
94786- if ((addr <= new_addr) && (addr+old_len) > new_addr)
94787+ if (addr + old_len > new_addr && new_addr + new_len > addr)
94788 goto out;
94789
94790 ret = do_munmap(mm, new_addr, new_len);
94791@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94792 unsigned long ret = -EINVAL;
94793 unsigned long charged = 0;
94794 bool locked = false;
94795+ unsigned long pax_task_size = TASK_SIZE;
94796
94797 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94798 return ret;
94799@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94800 if (!new_len)
94801 return ret;
94802
94803+#ifdef CONFIG_PAX_SEGMEXEC
94804+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94805+ pax_task_size = SEGMEXEC_TASK_SIZE;
94806+#endif
94807+
94808+ pax_task_size -= PAGE_SIZE;
94809+
94810+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94811+ old_len > pax_task_size || addr > pax_task_size-old_len)
94812+ return ret;
94813+
94814 down_write(&current->mm->mmap_sem);
94815
94816 if (flags & MREMAP_FIXED) {
94817@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94818 new_addr = addr;
94819 }
94820 ret = addr;
94821+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94822 goto out;
94823 }
94824 }
94825@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94826 goto out;
94827 }
94828
94829+ map_flags = vma->vm_flags;
94830 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94831+ if (!(ret & ~PAGE_MASK)) {
94832+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94833+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94834+ }
94835 }
94836 out:
94837 if (ret & ~PAGE_MASK)
94838diff --git a/mm/nommu.c b/mm/nommu.c
94839index 8740213..f87e25b 100644
94840--- a/mm/nommu.c
94841+++ b/mm/nommu.c
94842@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94843 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94844 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94845 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94846-int heap_stack_gap = 0;
94847
94848 atomic_long_t mmap_pages_allocated;
94849
94850@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94851 EXPORT_SYMBOL(find_vma);
94852
94853 /*
94854- * find a VMA
94855- * - we don't extend stack VMAs under NOMMU conditions
94856- */
94857-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94858-{
94859- return find_vma(mm, addr);
94860-}
94861-
94862-/*
94863 * expand a stack to a given address
94864 * - not supported under NOMMU conditions
94865 */
94866@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94867
94868 /* most fields are the same, copy all, and then fixup */
94869 *new = *vma;
94870+ INIT_LIST_HEAD(&new->anon_vma_chain);
94871 *region = *vma->vm_region;
94872 new->vm_region = region;
94873
94874@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94875 }
94876 EXPORT_SYMBOL(generic_file_remap_pages);
94877
94878-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94879- unsigned long addr, void *buf, int len, int write)
94880+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94881+ unsigned long addr, void *buf, size_t len, int write)
94882 {
94883 struct vm_area_struct *vma;
94884
94885@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94886 *
94887 * The caller must hold a reference on @mm.
94888 */
94889-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94890- void *buf, int len, int write)
94891+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94892+ void *buf, size_t len, int write)
94893 {
94894 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94895 }
94896@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94897 * Access another process' address space.
94898 * - source/target buffer must be kernel space
94899 */
94900-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94901+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94902 {
94903 struct mm_struct *mm;
94904
94905diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94906index 7106cb1..0805f48 100644
94907--- a/mm/page-writeback.c
94908+++ b/mm/page-writeback.c
94909@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94910 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94911 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94912 */
94913-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94914+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94915 unsigned long thresh,
94916 unsigned long bg_thresh,
94917 unsigned long dirty,
94918diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94919index 7387a67..3994687 100644
94920--- a/mm/page_alloc.c
94921+++ b/mm/page_alloc.c
94922@@ -61,6 +61,7 @@
94923 #include <linux/page-debug-flags.h>
94924 #include <linux/hugetlb.h>
94925 #include <linux/sched/rt.h>
94926+#include <linux/random.h>
94927
94928 #include <asm/sections.h>
94929 #include <asm/tlbflush.h>
94930@@ -354,7 +355,7 @@ out:
94931 * This usage means that zero-order pages may not be compound.
94932 */
94933
94934-static void free_compound_page(struct page *page)
94935+void free_compound_page(struct page *page)
94936 {
94937 __free_pages_ok(page, compound_order(page));
94938 }
94939@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94940 int i;
94941 int bad = 0;
94942
94943+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94944+ unsigned long index = 1UL << order;
94945+#endif
94946+
94947 trace_mm_page_free(page, order);
94948 kmemcheck_free_shadow(page, order);
94949
94950@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94951 debug_check_no_obj_freed(page_address(page),
94952 PAGE_SIZE << order);
94953 }
94954+
94955+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94956+ for (; index; --index)
94957+ sanitize_highpage(page + index - 1);
94958+#endif
94959+
94960 arch_free_page(page, order);
94961 kernel_map_pages(page, 1 << order, 0);
94962
94963@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94964 local_irq_restore(flags);
94965 }
94966
94967+#ifdef CONFIG_PAX_LATENT_ENTROPY
94968+bool __meminitdata extra_latent_entropy;
94969+
94970+static int __init setup_pax_extra_latent_entropy(char *str)
94971+{
94972+ extra_latent_entropy = true;
94973+ return 0;
94974+}
94975+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94976+
94977+volatile u64 latent_entropy __latent_entropy;
94978+EXPORT_SYMBOL(latent_entropy);
94979+#endif
94980+
94981 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94982 {
94983 unsigned int nr_pages = 1 << order;
94984@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94985 __ClearPageReserved(p);
94986 set_page_count(p, 0);
94987
94988+#ifdef CONFIG_PAX_LATENT_ENTROPY
94989+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94990+ u64 hash = 0;
94991+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94992+ const u64 *data = lowmem_page_address(page);
94993+
94994+ for (index = 0; index < end; index++)
94995+ hash ^= hash + data[index];
94996+ latent_entropy ^= hash;
94997+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94998+ }
94999+#endif
95000+
95001 page_zone(page)->managed_pages += nr_pages;
95002 set_page_refcounted(page);
95003 __free_pages(page, order);
95004@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95005 arch_alloc_page(page, order);
95006 kernel_map_pages(page, 1 << order, 1);
95007
95008+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95009 if (gfp_flags & __GFP_ZERO)
95010 prep_zero_page(page, order, gfp_flags);
95011+#endif
95012
95013 if (order && (gfp_flags & __GFP_COMP))
95014 prep_compound_page(page, order);
95015diff --git a/mm/page_io.c b/mm/page_io.c
95016index 7c59ef6..1358905 100644
95017--- a/mm/page_io.c
95018+++ b/mm/page_io.c
95019@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95020 struct file *swap_file = sis->swap_file;
95021 struct address_space *mapping = swap_file->f_mapping;
95022 struct iovec iov = {
95023- .iov_base = kmap(page),
95024+ .iov_base = (void __force_user *)kmap(page),
95025 .iov_len = PAGE_SIZE,
95026 };
95027
95028diff --git a/mm/percpu.c b/mm/percpu.c
95029index 036cfe0..980d0fa 100644
95030--- a/mm/percpu.c
95031+++ b/mm/percpu.c
95032@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95033 static unsigned int pcpu_high_unit_cpu __read_mostly;
95034
95035 /* the address of the first chunk which starts with the kernel static area */
95036-void *pcpu_base_addr __read_mostly;
95037+void *pcpu_base_addr __read_only;
95038 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95039
95040 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95041diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95042index fd26d04..0cea1b0 100644
95043--- a/mm/process_vm_access.c
95044+++ b/mm/process_vm_access.c
95045@@ -13,6 +13,7 @@
95046 #include <linux/uio.h>
95047 #include <linux/sched.h>
95048 #include <linux/highmem.h>
95049+#include <linux/security.h>
95050 #include <linux/ptrace.h>
95051 #include <linux/slab.h>
95052 #include <linux/syscalls.h>
95053@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95054 size_t iov_l_curr_offset = 0;
95055 ssize_t iov_len;
95056
95057+ return -ENOSYS; // PaX: until properly audited
95058+
95059 /*
95060 * Work out how many pages of struct pages we're going to need
95061 * when eventually calling get_user_pages
95062 */
95063 for (i = 0; i < riovcnt; i++) {
95064 iov_len = rvec[i].iov_len;
95065- if (iov_len > 0) {
95066- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95067- + iov_len)
95068- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95069- / PAGE_SIZE + 1;
95070- nr_pages = max(nr_pages, nr_pages_iov);
95071- }
95072+ if (iov_len <= 0)
95073+ continue;
95074+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95075+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95076+ nr_pages = max(nr_pages, nr_pages_iov);
95077 }
95078
95079 if (nr_pages == 0)
95080@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95081 goto free_proc_pages;
95082 }
95083
95084+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95085+ rc = -EPERM;
95086+ goto put_task_struct;
95087+ }
95088+
95089 mm = mm_access(task, PTRACE_MODE_ATTACH);
95090 if (!mm || IS_ERR(mm)) {
95091 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95092diff --git a/mm/rmap.c b/mm/rmap.c
95093index d3cbac5..0788da4 100644
95094--- a/mm/rmap.c
95095+++ b/mm/rmap.c
95096@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95097 struct anon_vma *anon_vma = vma->anon_vma;
95098 struct anon_vma_chain *avc;
95099
95100+#ifdef CONFIG_PAX_SEGMEXEC
95101+ struct anon_vma_chain *avc_m = NULL;
95102+#endif
95103+
95104 might_sleep();
95105 if (unlikely(!anon_vma)) {
95106 struct mm_struct *mm = vma->vm_mm;
95107@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95108 if (!avc)
95109 goto out_enomem;
95110
95111+#ifdef CONFIG_PAX_SEGMEXEC
95112+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95113+ if (!avc_m)
95114+ goto out_enomem_free_avc;
95115+#endif
95116+
95117 anon_vma = find_mergeable_anon_vma(vma);
95118 allocated = NULL;
95119 if (!anon_vma) {
95120@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95121 /* page_table_lock to protect against threads */
95122 spin_lock(&mm->page_table_lock);
95123 if (likely(!vma->anon_vma)) {
95124+
95125+#ifdef CONFIG_PAX_SEGMEXEC
95126+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95127+
95128+ if (vma_m) {
95129+ BUG_ON(vma_m->anon_vma);
95130+ vma_m->anon_vma = anon_vma;
95131+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95132+ avc_m = NULL;
95133+ }
95134+#endif
95135+
95136 vma->anon_vma = anon_vma;
95137 anon_vma_chain_link(vma, avc, anon_vma);
95138 allocated = NULL;
95139@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95140
95141 if (unlikely(allocated))
95142 put_anon_vma(allocated);
95143+
95144+#ifdef CONFIG_PAX_SEGMEXEC
95145+ if (unlikely(avc_m))
95146+ anon_vma_chain_free(avc_m);
95147+#endif
95148+
95149 if (unlikely(avc))
95150 anon_vma_chain_free(avc);
95151 }
95152 return 0;
95153
95154 out_enomem_free_avc:
95155+
95156+#ifdef CONFIG_PAX_SEGMEXEC
95157+ if (avc_m)
95158+ anon_vma_chain_free(avc_m);
95159+#endif
95160+
95161 anon_vma_chain_free(avc);
95162 out_enomem:
95163 return -ENOMEM;
95164@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95165 * Attach the anon_vmas from src to dst.
95166 * Returns 0 on success, -ENOMEM on failure.
95167 */
95168-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95169+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95170 {
95171 struct anon_vma_chain *avc, *pavc;
95172 struct anon_vma *root = NULL;
95173@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95174 * the corresponding VMA in the parent process is attached to.
95175 * Returns 0 on success, non-zero on failure.
95176 */
95177-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95178+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95179 {
95180 struct anon_vma_chain *avc;
95181 struct anon_vma *anon_vma;
95182@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95183 void __init anon_vma_init(void)
95184 {
95185 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95186- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95187- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95188+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95189+ anon_vma_ctor);
95190+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95191+ SLAB_PANIC|SLAB_NO_SANITIZE);
95192 }
95193
95194 /*
95195diff --git a/mm/shmem.c b/mm/shmem.c
95196index 1f18c9d..3e03d33 100644
95197--- a/mm/shmem.c
95198+++ b/mm/shmem.c
95199@@ -33,7 +33,7 @@
95200 #include <linux/swap.h>
95201 #include <linux/aio.h>
95202
95203-static struct vfsmount *shm_mnt;
95204+struct vfsmount *shm_mnt;
95205
95206 #ifdef CONFIG_SHMEM
95207 /*
95208@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
95209 #define BOGO_DIRENT_SIZE 20
95210
95211 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95212-#define SHORT_SYMLINK_LEN 128
95213+#define SHORT_SYMLINK_LEN 64
95214
95215 /*
95216 * shmem_fallocate and shmem_writepage communicate via inode->i_private
95217@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95218 static int shmem_xattr_validate(const char *name)
95219 {
95220 struct { const char *prefix; size_t len; } arr[] = {
95221+
95222+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95223+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95224+#endif
95225+
95226 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95227 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95228 };
95229@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95230 if (err)
95231 return err;
95232
95233+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95234+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95235+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95236+ return -EOPNOTSUPP;
95237+ if (size > 8)
95238+ return -EINVAL;
95239+ }
95240+#endif
95241+
95242 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95243 }
95244
95245@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95246 int err = -ENOMEM;
95247
95248 /* Round up to L1_CACHE_BYTES to resist false sharing */
95249- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95250- L1_CACHE_BYTES), GFP_KERNEL);
95251+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95252 if (!sbinfo)
95253 return -ENOMEM;
95254
95255diff --git a/mm/slab.c b/mm/slab.c
95256index b264214..83872cd 100644
95257--- a/mm/slab.c
95258+++ b/mm/slab.c
95259@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95260 if ((x)->max_freeable < i) \
95261 (x)->max_freeable = i; \
95262 } while (0)
95263-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95264-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95265-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95266-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95267+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95268+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95269+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95270+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95271+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95272+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95273 #else
95274 #define STATS_INC_ACTIVE(x) do { } while (0)
95275 #define STATS_DEC_ACTIVE(x) do { } while (0)
95276@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95277 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95278 #define STATS_INC_FREEHIT(x) do { } while (0)
95279 #define STATS_INC_FREEMISS(x) do { } while (0)
95280+#define STATS_INC_SANITIZED(x) do { } while (0)
95281+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95282 #endif
95283
95284 #if DEBUG
95285@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95286 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95287 */
95288 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95289- const struct page *page, void *obj)
95290+ const struct page *page, const void *obj)
95291 {
95292 u32 offset = (obj - page->s_mem);
95293 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95294@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95295 */
95296
95297 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95298- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95299+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95300
95301 if (INDEX_AC != INDEX_NODE)
95302 kmalloc_caches[INDEX_NODE] =
95303 create_kmalloc_cache("kmalloc-node",
95304- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95305+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95306
95307 slab_early_init = 0;
95308
95309@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95310 struct array_cache *ac = cpu_cache_get(cachep);
95311
95312 check_irq_off();
95313+
95314+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95315+ if (pax_sanitize_slab) {
95316+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95317+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95318+
95319+ if (cachep->ctor)
95320+ cachep->ctor(objp);
95321+
95322+ STATS_INC_SANITIZED(cachep);
95323+ } else
95324+ STATS_INC_NOT_SANITIZED(cachep);
95325+ }
95326+#endif
95327+
95328 kmemleak_free_recursive(objp, cachep->flags);
95329 objp = cache_free_debugcheck(cachep, objp, caller);
95330
95331@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95332
95333 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95334 return;
95335+ VM_BUG_ON(!virt_addr_valid(objp));
95336 local_irq_save(flags);
95337 kfree_debugcheck(objp);
95338 c = virt_to_cache(objp);
95339@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95340 }
95341 /* cpu stats */
95342 {
95343- unsigned long allochit = atomic_read(&cachep->allochit);
95344- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95345- unsigned long freehit = atomic_read(&cachep->freehit);
95346- unsigned long freemiss = atomic_read(&cachep->freemiss);
95347+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95348+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95349+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95350+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95351
95352 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95353 allochit, allocmiss, freehit, freemiss);
95354 }
95355+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95356+ {
95357+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95358+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95359+
95360+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95361+ }
95362+#endif
95363 #endif
95364 }
95365
95366@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95367 static int __init slab_proc_init(void)
95368 {
95369 #ifdef CONFIG_DEBUG_SLAB_LEAK
95370- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95371+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95372 #endif
95373 return 0;
95374 }
95375 module_init(slab_proc_init);
95376 #endif
95377
95378+bool is_usercopy_object(const void *ptr)
95379+{
95380+ struct page *page;
95381+ struct kmem_cache *cachep;
95382+
95383+ if (ZERO_OR_NULL_PTR(ptr))
95384+ return false;
95385+
95386+ if (!slab_is_available())
95387+ return false;
95388+
95389+ if (!virt_addr_valid(ptr))
95390+ return false;
95391+
95392+ page = virt_to_head_page(ptr);
95393+
95394+ if (!PageSlab(page))
95395+ return false;
95396+
95397+ cachep = page->slab_cache;
95398+ return cachep->flags & SLAB_USERCOPY;
95399+}
95400+
95401+#ifdef CONFIG_PAX_USERCOPY
95402+const char *check_heap_object(const void *ptr, unsigned long n)
95403+{
95404+ struct page *page;
95405+ struct kmem_cache *cachep;
95406+ unsigned int objnr;
95407+ unsigned long offset;
95408+
95409+ if (ZERO_OR_NULL_PTR(ptr))
95410+ return "<null>";
95411+
95412+ if (!virt_addr_valid(ptr))
95413+ return NULL;
95414+
95415+ page = virt_to_head_page(ptr);
95416+
95417+ if (!PageSlab(page))
95418+ return NULL;
95419+
95420+ cachep = page->slab_cache;
95421+ if (!(cachep->flags & SLAB_USERCOPY))
95422+ return cachep->name;
95423+
95424+ objnr = obj_to_index(cachep, page, ptr);
95425+ BUG_ON(objnr >= cachep->num);
95426+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95427+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95428+ return NULL;
95429+
95430+ return cachep->name;
95431+}
95432+#endif
95433+
95434 /**
95435 * ksize - get the actual amount of memory allocated for a given object
95436 * @objp: Pointer to the object
95437diff --git a/mm/slab.h b/mm/slab.h
95438index 8184a7c..ab27737 100644
95439--- a/mm/slab.h
95440+++ b/mm/slab.h
95441@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95442 /* The slab cache that manages slab cache information */
95443 extern struct kmem_cache *kmem_cache;
95444
95445+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95446+#ifdef CONFIG_X86_64
95447+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95448+#else
95449+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95450+#endif
95451+extern bool pax_sanitize_slab;
95452+#endif
95453+
95454 unsigned long calculate_alignment(unsigned long flags,
95455 unsigned long align, unsigned long size);
95456
95457@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95458
95459 /* Legal flag mask for kmem_cache_create(), for various configurations */
95460 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95461- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95462+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95463+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95464
95465 #if defined(CONFIG_DEBUG_SLAB)
95466 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95467@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95468 return s;
95469
95470 page = virt_to_head_page(x);
95471+
95472+ BUG_ON(!PageSlab(page));
95473+
95474 cachep = page->slab_cache;
95475 if (slab_equal_or_root(cachep, s))
95476 return cachep;
95477diff --git a/mm/slab_common.c b/mm/slab_common.c
95478index 1ec3c61..2067c11 100644
95479--- a/mm/slab_common.c
95480+++ b/mm/slab_common.c
95481@@ -23,11 +23,22 @@
95482
95483 #include "slab.h"
95484
95485-enum slab_state slab_state;
95486+enum slab_state slab_state __read_only;
95487 LIST_HEAD(slab_caches);
95488 DEFINE_MUTEX(slab_mutex);
95489 struct kmem_cache *kmem_cache;
95490
95491+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95492+bool pax_sanitize_slab __read_only = true;
95493+static int __init pax_sanitize_slab_setup(char *str)
95494+{
95495+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95496+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95497+ return 1;
95498+}
95499+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95500+#endif
95501+
95502 #ifdef CONFIG_DEBUG_VM
95503 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95504 size_t size)
95505@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95506 if (err)
95507 goto out_free_cache;
95508
95509- s->refcount = 1;
95510+ atomic_set(&s->refcount, 1);
95511 list_add(&s->list, &slab_caches);
95512 memcg_register_cache(s);
95513
95514@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95515
95516 get_online_cpus();
95517 mutex_lock(&slab_mutex);
95518- s->refcount--;
95519- if (!s->refcount) {
95520+ if (atomic_dec_and_test(&s->refcount)) {
95521 list_del(&s->list);
95522
95523 if (!__kmem_cache_shutdown(s)) {
95524@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95525 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95526 name, size, err);
95527
95528- s->refcount = -1; /* Exempt from merging for now */
95529+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95530 }
95531
95532 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95533@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95534
95535 create_boot_cache(s, name, size, flags);
95536 list_add(&s->list, &slab_caches);
95537- s->refcount = 1;
95538+ atomic_set(&s->refcount, 1);
95539 return s;
95540 }
95541
95542@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95543 EXPORT_SYMBOL(kmalloc_dma_caches);
95544 #endif
95545
95546+#ifdef CONFIG_PAX_USERCOPY_SLABS
95547+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95548+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95549+#endif
95550+
95551 /*
95552 * Conversion table for small slabs sizes / 8 to the index in the
95553 * kmalloc array. This is necessary for slabs < 192 since we have non power
95554@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95555 return kmalloc_dma_caches[index];
95556
95557 #endif
95558+
95559+#ifdef CONFIG_PAX_USERCOPY_SLABS
95560+ if (unlikely((flags & GFP_USERCOPY)))
95561+ return kmalloc_usercopy_caches[index];
95562+
95563+#endif
95564+
95565 return kmalloc_caches[index];
95566 }
95567
95568@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95569 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95570 if (!kmalloc_caches[i]) {
95571 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95572- 1 << i, flags);
95573+ 1 << i, SLAB_USERCOPY | flags);
95574 }
95575
95576 /*
95577@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95578 * earlier power of two caches
95579 */
95580 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95581- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95582+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95583
95584 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95585- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95586+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95587 }
95588
95589 /* Kmalloc array is now usable */
95590@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95591 }
95592 }
95593 #endif
95594+
95595+#ifdef CONFIG_PAX_USERCOPY_SLABS
95596+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95597+ struct kmem_cache *s = kmalloc_caches[i];
95598+
95599+ if (s) {
95600+ int size = kmalloc_size(i);
95601+ char *n = kasprintf(GFP_NOWAIT,
95602+ "usercopy-kmalloc-%d", size);
95603+
95604+ BUG_ON(!n);
95605+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95606+ size, SLAB_USERCOPY | flags);
95607+ }
95608+ }
95609+#endif
95610+
95611 }
95612 #endif /* !CONFIG_SLOB */
95613
95614@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
95615 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95616 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95617 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95618+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95619+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
95620+#endif
95621 #endif
95622 seq_putc(m, '\n');
95623 }
95624diff --git a/mm/slob.c b/mm/slob.c
95625index 4bf8809..98a6914 100644
95626--- a/mm/slob.c
95627+++ b/mm/slob.c
95628@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95629 /*
95630 * Return the size of a slob block.
95631 */
95632-static slobidx_t slob_units(slob_t *s)
95633+static slobidx_t slob_units(const slob_t *s)
95634 {
95635 if (s->units > 0)
95636 return s->units;
95637@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95638 /*
95639 * Return the next free slob block pointer after this one.
95640 */
95641-static slob_t *slob_next(slob_t *s)
95642+static slob_t *slob_next(const slob_t *s)
95643 {
95644 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95645 slobidx_t next;
95646@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95647 /*
95648 * Returns true if s is the last free block in its page.
95649 */
95650-static int slob_last(slob_t *s)
95651+static int slob_last(const slob_t *s)
95652 {
95653 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95654 }
95655
95656-static void *slob_new_pages(gfp_t gfp, int order, int node)
95657+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95658 {
95659- void *page;
95660+ struct page *page;
95661
95662 #ifdef CONFIG_NUMA
95663 if (node != NUMA_NO_NODE)
95664@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95665 if (!page)
95666 return NULL;
95667
95668- return page_address(page);
95669+ __SetPageSlab(page);
95670+ return page;
95671 }
95672
95673-static void slob_free_pages(void *b, int order)
95674+static void slob_free_pages(struct page *sp, int order)
95675 {
95676 if (current->reclaim_state)
95677 current->reclaim_state->reclaimed_slab += 1 << order;
95678- free_pages((unsigned long)b, order);
95679+ __ClearPageSlab(sp);
95680+ page_mapcount_reset(sp);
95681+ sp->private = 0;
95682+ __free_pages(sp, order);
95683 }
95684
95685 /*
95686@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95687
95688 /* Not enough space: must allocate a new page */
95689 if (!b) {
95690- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95691- if (!b)
95692+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95693+ if (!sp)
95694 return NULL;
95695- sp = virt_to_page(b);
95696- __SetPageSlab(sp);
95697+ b = page_address(sp);
95698
95699 spin_lock_irqsave(&slob_lock, flags);
95700 sp->units = SLOB_UNITS(PAGE_SIZE);
95701 sp->freelist = b;
95702+ sp->private = 0;
95703 INIT_LIST_HEAD(&sp->list);
95704 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95705 set_slob_page_free(sp, slob_list);
95706@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95707 if (slob_page_free(sp))
95708 clear_slob_page_free(sp);
95709 spin_unlock_irqrestore(&slob_lock, flags);
95710- __ClearPageSlab(sp);
95711- page_mapcount_reset(sp);
95712- slob_free_pages(b, 0);
95713+ slob_free_pages(sp, 0);
95714 return;
95715 }
95716
95717+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95718+ if (pax_sanitize_slab)
95719+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95720+#endif
95721+
95722 if (!slob_page_free(sp)) {
95723 /* This slob page is about to become partially free. Easy! */
95724 sp->units = units;
95725@@ -424,11 +431,10 @@ out:
95726 */
95727
95728 static __always_inline void *
95729-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95730+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95731 {
95732- unsigned int *m;
95733- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95734- void *ret;
95735+ slob_t *m;
95736+ void *ret = NULL;
95737
95738 gfp &= gfp_allowed_mask;
95739
95740@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95741
95742 if (!m)
95743 return NULL;
95744- *m = size;
95745+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95746+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95747+ m[0].units = size;
95748+ m[1].units = align;
95749 ret = (void *)m + align;
95750
95751 trace_kmalloc_node(caller, ret,
95752 size, size + align, gfp, node);
95753 } else {
95754 unsigned int order = get_order(size);
95755+ struct page *page;
95756
95757 if (likely(order))
95758 gfp |= __GFP_COMP;
95759- ret = slob_new_pages(gfp, order, node);
95760+ page = slob_new_pages(gfp, order, node);
95761+ if (page) {
95762+ ret = page_address(page);
95763+ page->private = size;
95764+ }
95765
95766 trace_kmalloc_node(caller, ret,
95767 size, PAGE_SIZE << order, gfp, node);
95768 }
95769
95770- kmemleak_alloc(ret, size, 1, gfp);
95771+ return ret;
95772+}
95773+
95774+static __always_inline void *
95775+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95776+{
95777+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95778+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95779+
95780+ if (!ZERO_OR_NULL_PTR(ret))
95781+ kmemleak_alloc(ret, size, 1, gfp);
95782 return ret;
95783 }
95784
95785@@ -493,34 +517,112 @@ void kfree(const void *block)
95786 return;
95787 kmemleak_free(block);
95788
95789+ VM_BUG_ON(!virt_addr_valid(block));
95790 sp = virt_to_page(block);
95791- if (PageSlab(sp)) {
95792+ VM_BUG_ON(!PageSlab(sp));
95793+ if (!sp->private) {
95794 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95795- unsigned int *m = (unsigned int *)(block - align);
95796- slob_free(m, *m + align);
95797- } else
95798+ slob_t *m = (slob_t *)(block - align);
95799+ slob_free(m, m[0].units + align);
95800+ } else {
95801+ __ClearPageSlab(sp);
95802+ page_mapcount_reset(sp);
95803+ sp->private = 0;
95804 __free_pages(sp, compound_order(sp));
95805+ }
95806 }
95807 EXPORT_SYMBOL(kfree);
95808
95809+bool is_usercopy_object(const void *ptr)
95810+{
95811+ if (!slab_is_available())
95812+ return false;
95813+
95814+ // PAX: TODO
95815+
95816+ return false;
95817+}
95818+
95819+#ifdef CONFIG_PAX_USERCOPY
95820+const char *check_heap_object(const void *ptr, unsigned long n)
95821+{
95822+ struct page *page;
95823+ const slob_t *free;
95824+ const void *base;
95825+ unsigned long flags;
95826+
95827+ if (ZERO_OR_NULL_PTR(ptr))
95828+ return "<null>";
95829+
95830+ if (!virt_addr_valid(ptr))
95831+ return NULL;
95832+
95833+ page = virt_to_head_page(ptr);
95834+ if (!PageSlab(page))
95835+ return NULL;
95836+
95837+ if (page->private) {
95838+ base = page;
95839+ if (base <= ptr && n <= page->private - (ptr - base))
95840+ return NULL;
95841+ return "<slob>";
95842+ }
95843+
95844+ /* some tricky double walking to find the chunk */
95845+ spin_lock_irqsave(&slob_lock, flags);
95846+ base = (void *)((unsigned long)ptr & PAGE_MASK);
95847+ free = page->freelist;
95848+
95849+ while (!slob_last(free) && (void *)free <= ptr) {
95850+ base = free + slob_units(free);
95851+ free = slob_next(free);
95852+ }
95853+
95854+ while (base < (void *)free) {
95855+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95856+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
95857+ int offset;
95858+
95859+ if (ptr < base + align)
95860+ break;
95861+
95862+ offset = ptr - base - align;
95863+ if (offset >= m) {
95864+ base += size;
95865+ continue;
95866+ }
95867+
95868+ if (n > m - offset)
95869+ break;
95870+
95871+ spin_unlock_irqrestore(&slob_lock, flags);
95872+ return NULL;
95873+ }
95874+
95875+ spin_unlock_irqrestore(&slob_lock, flags);
95876+ return "<slob>";
95877+}
95878+#endif
95879+
95880 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95881 size_t ksize(const void *block)
95882 {
95883 struct page *sp;
95884 int align;
95885- unsigned int *m;
95886+ slob_t *m;
95887
95888 BUG_ON(!block);
95889 if (unlikely(block == ZERO_SIZE_PTR))
95890 return 0;
95891
95892 sp = virt_to_page(block);
95893- if (unlikely(!PageSlab(sp)))
95894- return PAGE_SIZE << compound_order(sp);
95895+ VM_BUG_ON(!PageSlab(sp));
95896+ if (sp->private)
95897+ return sp->private;
95898
95899 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95900- m = (unsigned int *)(block - align);
95901- return SLOB_UNITS(*m) * SLOB_UNIT;
95902+ m = (slob_t *)(block - align);
95903+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95904 }
95905 EXPORT_SYMBOL(ksize);
95906
95907@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95908
95909 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95910 {
95911- void *b;
95912+ void *b = NULL;
95913
95914 flags &= gfp_allowed_mask;
95915
95916 lockdep_trace_alloc(flags);
95917
95918+#ifdef CONFIG_PAX_USERCOPY_SLABS
95919+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95920+#else
95921 if (c->size < PAGE_SIZE) {
95922 b = slob_alloc(c->size, flags, c->align, node);
95923 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95924 SLOB_UNITS(c->size) * SLOB_UNIT,
95925 flags, node);
95926 } else {
95927- b = slob_new_pages(flags, get_order(c->size), node);
95928+ struct page *sp;
95929+
95930+ sp = slob_new_pages(flags, get_order(c->size), node);
95931+ if (sp) {
95932+ b = page_address(sp);
95933+ sp->private = c->size;
95934+ }
95935 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95936 PAGE_SIZE << get_order(c->size),
95937 flags, node);
95938 }
95939+#endif
95940
95941 if (b && c->ctor)
95942 c->ctor(b);
95943@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95944
95945 static void __kmem_cache_free(void *b, int size)
95946 {
95947- if (size < PAGE_SIZE)
95948+ struct page *sp;
95949+
95950+ sp = virt_to_page(b);
95951+ BUG_ON(!PageSlab(sp));
95952+ if (!sp->private)
95953 slob_free(b, size);
95954 else
95955- slob_free_pages(b, get_order(size));
95956+ slob_free_pages(sp, get_order(size));
95957 }
95958
95959 static void kmem_rcu_free(struct rcu_head *head)
95960@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95961
95962 void kmem_cache_free(struct kmem_cache *c, void *b)
95963 {
95964+ int size = c->size;
95965+
95966+#ifdef CONFIG_PAX_USERCOPY_SLABS
95967+ if (size + c->align < PAGE_SIZE) {
95968+ size += c->align;
95969+ b -= c->align;
95970+ }
95971+#endif
95972+
95973 kmemleak_free_recursive(b, c->flags);
95974 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95975 struct slob_rcu *slob_rcu;
95976- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95977- slob_rcu->size = c->size;
95978+ slob_rcu = b + (size - sizeof(struct slob_rcu));
95979+ slob_rcu->size = size;
95980 call_rcu(&slob_rcu->head, kmem_rcu_free);
95981 } else {
95982- __kmem_cache_free(b, c->size);
95983+ __kmem_cache_free(b, size);
95984 }
95985
95986+#ifdef CONFIG_PAX_USERCOPY_SLABS
95987+ trace_kfree(_RET_IP_, b);
95988+#else
95989 trace_kmem_cache_free(_RET_IP_, b);
95990+#endif
95991+
95992 }
95993 EXPORT_SYMBOL(kmem_cache_free);
95994
95995diff --git a/mm/slub.c b/mm/slub.c
95996index 25f14ad..ff4d0b7 100644
95997--- a/mm/slub.c
95998+++ b/mm/slub.c
95999@@ -207,7 +207,7 @@ struct track {
96000
96001 enum track_item { TRACK_ALLOC, TRACK_FREE };
96002
96003-#ifdef CONFIG_SYSFS
96004+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96005 static int sysfs_slab_add(struct kmem_cache *);
96006 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96007 static void sysfs_slab_remove(struct kmem_cache *);
96008@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
96009 if (!t->addr)
96010 return;
96011
96012- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96013+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96014 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96015 #ifdef CONFIG_STACKTRACE
96016 {
96017@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96018
96019 slab_free_hook(s, x);
96020
96021+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96022+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96023+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96024+ if (s->ctor)
96025+ s->ctor(x);
96026+ }
96027+#endif
96028+
96029 redo:
96030 /*
96031 * Determine the currently cpus per cpu slab.
96032@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96033 * Merge control. If this is set then no merging of slab caches will occur.
96034 * (Could be removed. This was introduced to pacify the merge skeptics.)
96035 */
96036-static int slub_nomerge;
96037+static int slub_nomerge = 1;
96038
96039 /*
96040 * Calculate the order of allocation given an slab object size.
96041@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96042 s->inuse = size;
96043
96044 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96045+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96046+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96047+#endif
96048 s->ctor)) {
96049 /*
96050 * Relocate free pointer after the object if it is not
96051@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96052 EXPORT_SYMBOL(__kmalloc_node);
96053 #endif
96054
96055+bool is_usercopy_object(const void *ptr)
96056+{
96057+ struct page *page;
96058+ struct kmem_cache *s;
96059+
96060+ if (ZERO_OR_NULL_PTR(ptr))
96061+ return false;
96062+
96063+ if (!slab_is_available())
96064+ return false;
96065+
96066+ if (!virt_addr_valid(ptr))
96067+ return false;
96068+
96069+ page = virt_to_head_page(ptr);
96070+
96071+ if (!PageSlab(page))
96072+ return false;
96073+
96074+ s = page->slab_cache;
96075+ return s->flags & SLAB_USERCOPY;
96076+}
96077+
96078+#ifdef CONFIG_PAX_USERCOPY
96079+const char *check_heap_object(const void *ptr, unsigned long n)
96080+{
96081+ struct page *page;
96082+ struct kmem_cache *s;
96083+ unsigned long offset;
96084+
96085+ if (ZERO_OR_NULL_PTR(ptr))
96086+ return "<null>";
96087+
96088+ if (!virt_addr_valid(ptr))
96089+ return NULL;
96090+
96091+ page = virt_to_head_page(ptr);
96092+
96093+ if (!PageSlab(page))
96094+ return NULL;
96095+
96096+ s = page->slab_cache;
96097+ if (!(s->flags & SLAB_USERCOPY))
96098+ return s->name;
96099+
96100+ offset = (ptr - page_address(page)) % s->size;
96101+ if (offset <= s->object_size && n <= s->object_size - offset)
96102+ return NULL;
96103+
96104+ return s->name;
96105+}
96106+#endif
96107+
96108 size_t ksize(const void *object)
96109 {
96110 struct page *page;
96111@@ -3387,6 +3451,7 @@ void kfree(const void *x)
96112 if (unlikely(ZERO_OR_NULL_PTR(x)))
96113 return;
96114
96115+ VM_BUG_ON(!virt_addr_valid(x));
96116 page = virt_to_head_page(x);
96117 if (unlikely(!PageSlab(page))) {
96118 BUG_ON(!PageCompound(page));
96119@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96120 /*
96121 * We may have set a slab to be unmergeable during bootstrap.
96122 */
96123- if (s->refcount < 0)
96124+ if (atomic_read(&s->refcount) < 0)
96125 return 1;
96126
96127 return 0;
96128@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96129
96130 s = find_mergeable(memcg, size, align, flags, name, ctor);
96131 if (s) {
96132- s->refcount++;
96133+ atomic_inc(&s->refcount);
96134 /*
96135 * Adjust the object sizes so that we clear
96136 * the complete object on kzalloc.
96137@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96138 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96139
96140 if (sysfs_slab_alias(s, name)) {
96141- s->refcount--;
96142+ atomic_dec(&s->refcount);
96143 s = NULL;
96144 }
96145 }
96146@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96147 }
96148 #endif
96149
96150-#ifdef CONFIG_SYSFS
96151+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96152 static int count_inuse(struct page *page)
96153 {
96154 return page->inuse;
96155@@ -4268,12 +4333,12 @@ static void resiliency_test(void)
96156 validate_slab_cache(kmalloc_caches[9]);
96157 }
96158 #else
96159-#ifdef CONFIG_SYSFS
96160+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96161 static void resiliency_test(void) {};
96162 #endif
96163 #endif
96164
96165-#ifdef CONFIG_SYSFS
96166+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96167 enum slab_stat_type {
96168 SL_ALL, /* All slabs */
96169 SL_PARTIAL, /* Only partially allocated slabs */
96170@@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
96171
96172 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96173 {
96174- return sprintf(buf, "%d\n", s->refcount - 1);
96175+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96176 }
96177 SLAB_ATTR_RO(aliases);
96178
96179@@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96180 SLAB_ATTR_RO(cache_dma);
96181 #endif
96182
96183+#ifdef CONFIG_PAX_USERCOPY_SLABS
96184+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96185+{
96186+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96187+}
96188+SLAB_ATTR_RO(usercopy);
96189+#endif
96190+
96191 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96192 {
96193 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96194@@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
96195 #ifdef CONFIG_ZONE_DMA
96196 &cache_dma_attr.attr,
96197 #endif
96198+#ifdef CONFIG_PAX_USERCOPY_SLABS
96199+ &usercopy_attr.attr,
96200+#endif
96201 #ifdef CONFIG_NUMA
96202 &remote_node_defrag_ratio_attr.attr,
96203 #endif
96204@@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
96205 return name;
96206 }
96207
96208+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96209 static int sysfs_slab_add(struct kmem_cache *s)
96210 {
96211 int err;
96212@@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96213 kobject_del(&s->kobj);
96214 kobject_put(&s->kobj);
96215 }
96216+#endif
96217
96218 /*
96219 * Need to buffer aliases during bootup until sysfs becomes
96220@@ -5243,6 +5321,7 @@ struct saved_alias {
96221
96222 static struct saved_alias *alias_list;
96223
96224+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96225 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96226 {
96227 struct saved_alias *al;
96228@@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96229 alias_list = al;
96230 return 0;
96231 }
96232+#endif
96233
96234 static int __init slab_sysfs_init(void)
96235 {
96236diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96237index 4cba9c2..b4f9fcc 100644
96238--- a/mm/sparse-vmemmap.c
96239+++ b/mm/sparse-vmemmap.c
96240@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96241 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96242 if (!p)
96243 return NULL;
96244- pud_populate(&init_mm, pud, p);
96245+ pud_populate_kernel(&init_mm, pud, p);
96246 }
96247 return pud;
96248 }
96249@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96250 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96251 if (!p)
96252 return NULL;
96253- pgd_populate(&init_mm, pgd, p);
96254+ pgd_populate_kernel(&init_mm, pgd, p);
96255 }
96256 return pgd;
96257 }
96258diff --git a/mm/sparse.c b/mm/sparse.c
96259index 63c3ea5..95c0858 100644
96260--- a/mm/sparse.c
96261+++ b/mm/sparse.c
96262@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96263
96264 for (i = 0; i < PAGES_PER_SECTION; i++) {
96265 if (PageHWPoison(&memmap[i])) {
96266- atomic_long_sub(1, &num_poisoned_pages);
96267+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96268 ClearPageHWPoison(&memmap[i]);
96269 }
96270 }
96271diff --git a/mm/swap.c b/mm/swap.c
96272index 0092097..33361ff 100644
96273--- a/mm/swap.c
96274+++ b/mm/swap.c
96275@@ -31,6 +31,7 @@
96276 #include <linux/memcontrol.h>
96277 #include <linux/gfp.h>
96278 #include <linux/uio.h>
96279+#include <linux/hugetlb.h>
96280
96281 #include "internal.h"
96282
96283@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96284
96285 __page_cache_release(page);
96286 dtor = get_compound_page_dtor(page);
96287+ if (!PageHuge(page))
96288+ BUG_ON(dtor != free_compound_page);
96289 (*dtor)(page);
96290 }
96291
96292diff --git a/mm/swapfile.c b/mm/swapfile.c
96293index 4a7f7e6..22cddf5 100644
96294--- a/mm/swapfile.c
96295+++ b/mm/swapfile.c
96296@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96297
96298 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96299 /* Activity counter to indicate that a swapon or swapoff has occurred */
96300-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96301+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96302
96303 static inline unsigned char swap_count(unsigned char ent)
96304 {
96305@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96306 spin_unlock(&swap_lock);
96307
96308 err = 0;
96309- atomic_inc(&proc_poll_event);
96310+ atomic_inc_unchecked(&proc_poll_event);
96311 wake_up_interruptible(&proc_poll_wait);
96312
96313 out_dput:
96314@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96315
96316 poll_wait(file, &proc_poll_wait, wait);
96317
96318- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96319- seq->poll_event = atomic_read(&proc_poll_event);
96320+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96321+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96322 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96323 }
96324
96325@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96326 return ret;
96327
96328 seq = file->private_data;
96329- seq->poll_event = atomic_read(&proc_poll_event);
96330+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96331 return 0;
96332 }
96333
96334@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96335 (frontswap_map) ? "FS" : "");
96336
96337 mutex_unlock(&swapon_mutex);
96338- atomic_inc(&proc_poll_event);
96339+ atomic_inc_unchecked(&proc_poll_event);
96340 wake_up_interruptible(&proc_poll_wait);
96341
96342 if (S_ISREG(inode->i_mode))
96343diff --git a/mm/util.c b/mm/util.c
96344index a24aa22..a0d41ae 100644
96345--- a/mm/util.c
96346+++ b/mm/util.c
96347@@ -297,6 +297,12 @@ done:
96348 void arch_pick_mmap_layout(struct mm_struct *mm)
96349 {
96350 mm->mmap_base = TASK_UNMAPPED_BASE;
96351+
96352+#ifdef CONFIG_PAX_RANDMMAP
96353+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96354+ mm->mmap_base += mm->delta_mmap;
96355+#endif
96356+
96357 mm->get_unmapped_area = arch_get_unmapped_area;
96358 }
96359 #endif
96360diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96361index 0fdf968..d6686e8 100644
96362--- a/mm/vmalloc.c
96363+++ b/mm/vmalloc.c
96364@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96365
96366 pte = pte_offset_kernel(pmd, addr);
96367 do {
96368- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96369- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96370+
96371+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96372+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96373+ BUG_ON(!pte_exec(*pte));
96374+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96375+ continue;
96376+ }
96377+#endif
96378+
96379+ {
96380+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96381+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96382+ }
96383 } while (pte++, addr += PAGE_SIZE, addr != end);
96384 }
96385
96386@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96387 pte = pte_alloc_kernel(pmd, addr);
96388 if (!pte)
96389 return -ENOMEM;
96390+
96391+ pax_open_kernel();
96392 do {
96393 struct page *page = pages[*nr];
96394
96395- if (WARN_ON(!pte_none(*pte)))
96396+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96397+ if (pgprot_val(prot) & _PAGE_NX)
96398+#endif
96399+
96400+ if (!pte_none(*pte)) {
96401+ pax_close_kernel();
96402+ WARN_ON(1);
96403 return -EBUSY;
96404- if (WARN_ON(!page))
96405+ }
96406+ if (!page) {
96407+ pax_close_kernel();
96408+ WARN_ON(1);
96409 return -ENOMEM;
96410+ }
96411 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96412 (*nr)++;
96413 } while (pte++, addr += PAGE_SIZE, addr != end);
96414+ pax_close_kernel();
96415 return 0;
96416 }
96417
96418@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96419 pmd_t *pmd;
96420 unsigned long next;
96421
96422- pmd = pmd_alloc(&init_mm, pud, addr);
96423+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96424 if (!pmd)
96425 return -ENOMEM;
96426 do {
96427@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96428 pud_t *pud;
96429 unsigned long next;
96430
96431- pud = pud_alloc(&init_mm, pgd, addr);
96432+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96433 if (!pud)
96434 return -ENOMEM;
96435 do {
96436@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96437 if (addr >= MODULES_VADDR && addr < MODULES_END)
96438 return 1;
96439 #endif
96440+
96441+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96442+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96443+ return 1;
96444+#endif
96445+
96446 return is_vmalloc_addr(x);
96447 }
96448
96449@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96450
96451 if (!pgd_none(*pgd)) {
96452 pud_t *pud = pud_offset(pgd, addr);
96453+#ifdef CONFIG_X86
96454+ if (!pud_large(*pud))
96455+#endif
96456 if (!pud_none(*pud)) {
96457 pmd_t *pmd = pmd_offset(pud, addr);
96458+#ifdef CONFIG_X86
96459+ if (!pmd_large(*pmd))
96460+#endif
96461 if (!pmd_none(*pmd)) {
96462 pte_t *ptep, pte;
96463
96464@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96465 struct vm_struct *area;
96466
96467 BUG_ON(in_interrupt());
96468+
96469+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96470+ if (flags & VM_KERNEXEC) {
96471+ if (start != VMALLOC_START || end != VMALLOC_END)
96472+ return NULL;
96473+ start = (unsigned long)MODULES_EXEC_VADDR;
96474+ end = (unsigned long)MODULES_EXEC_END;
96475+ }
96476+#endif
96477+
96478 if (flags & VM_IOREMAP)
96479 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96480
96481@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96482 if (count > totalram_pages)
96483 return NULL;
96484
96485+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96486+ if (!(pgprot_val(prot) & _PAGE_NX))
96487+ flags |= VM_KERNEXEC;
96488+#endif
96489+
96490 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96491 __builtin_return_address(0));
96492 if (!area)
96493@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96494 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96495 goto fail;
96496
96497+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96498+ if (!(pgprot_val(prot) & _PAGE_NX))
96499+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96500+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96501+ else
96502+#endif
96503+
96504 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96505 start, end, node, gfp_mask, caller);
96506 if (!area)
96507@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96508 * For tight control over page level allocator and protection flags
96509 * use __vmalloc() instead.
96510 */
96511-
96512 void *vmalloc_exec(unsigned long size)
96513 {
96514- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96515+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96516 NUMA_NO_NODE, __builtin_return_address(0));
96517 }
96518
96519@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96520 {
96521 struct vm_struct *area;
96522
96523+ BUG_ON(vma->vm_mirror);
96524+
96525 size = PAGE_ALIGN(size);
96526
96527 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96528@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96529 v->addr, v->addr + v->size, v->size);
96530
96531 if (v->caller)
96532+#ifdef CONFIG_GRKERNSEC_HIDESYM
96533+ seq_printf(m, " %pK", v->caller);
96534+#else
96535 seq_printf(m, " %pS", v->caller);
96536+#endif
96537
96538 if (v->nr_pages)
96539 seq_printf(m, " pages=%d", v->nr_pages);
96540diff --git a/mm/vmstat.c b/mm/vmstat.c
96541index def5dd2..4ce55cec 100644
96542--- a/mm/vmstat.c
96543+++ b/mm/vmstat.c
96544@@ -20,6 +20,7 @@
96545 #include <linux/writeback.h>
96546 #include <linux/compaction.h>
96547 #include <linux/mm_inline.h>
96548+#include <linux/grsecurity.h>
96549
96550 #include "internal.h"
96551
96552@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96553 *
96554 * vm_stat contains the global counters
96555 */
96556-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96557+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96558 EXPORT_SYMBOL(vm_stat);
96559
96560 #ifdef CONFIG_SMP
96561@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96562
96563 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96564 if (diff[i])
96565- atomic_long_add(diff[i], &vm_stat[i]);
96566+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96567 }
96568
96569 /*
96570@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96571 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96572 if (v) {
96573
96574- atomic_long_add(v, &zone->vm_stat[i]);
96575+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96576 global_diff[i] += v;
96577 #ifdef CONFIG_NUMA
96578 /* 3 seconds idle till flush */
96579@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96580
96581 v = p->vm_stat_diff[i];
96582 p->vm_stat_diff[i] = 0;
96583- atomic_long_add(v, &zone->vm_stat[i]);
96584+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96585 global_diff[i] += v;
96586 }
96587 }
96588@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96589 if (pset->vm_stat_diff[i]) {
96590 int v = pset->vm_stat_diff[i];
96591 pset->vm_stat_diff[i] = 0;
96592- atomic_long_add(v, &zone->vm_stat[i]);
96593- atomic_long_add(v, &vm_stat[i]);
96594+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96595+ atomic_long_add_unchecked(v, &vm_stat[i]);
96596 }
96597 }
96598 #endif
96599@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96600 stat_items_size += sizeof(struct vm_event_state);
96601 #endif
96602
96603- v = kmalloc(stat_items_size, GFP_KERNEL);
96604+ v = kzalloc(stat_items_size, GFP_KERNEL);
96605 m->private = v;
96606 if (!v)
96607 return ERR_PTR(-ENOMEM);
96608+
96609+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96610+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96611+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96612+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96613+ && !in_group_p(grsec_proc_gid)
96614+#endif
96615+ )
96616+ return (unsigned long *)m->private + *pos;
96617+#endif
96618+#endif
96619+
96620 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96621 v[i] = global_page_state(i);
96622 v += NR_VM_ZONE_STAT_ITEMS;
96623@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
96624 put_online_cpus();
96625 #endif
96626 #ifdef CONFIG_PROC_FS
96627- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96628- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96629- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96630- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96631+ {
96632+ mode_t gr_mode = S_IRUGO;
96633+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96634+ gr_mode = S_IRUSR;
96635+#endif
96636+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96637+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96638+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96639+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96640+ }
96641 #endif
96642 return 0;
96643 }
96644diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96645index 175273f..1c63e05 100644
96646--- a/net/8021q/vlan.c
96647+++ b/net/8021q/vlan.c
96648@@ -474,7 +474,7 @@ out:
96649 return NOTIFY_DONE;
96650 }
96651
96652-static struct notifier_block vlan_notifier_block __read_mostly = {
96653+static struct notifier_block vlan_notifier_block = {
96654 .notifier_call = vlan_device_event,
96655 };
96656
96657@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96658 err = -EPERM;
96659 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96660 break;
96661- if ((args.u.name_type >= 0) &&
96662- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96663+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96664 struct vlan_net *vn;
96665
96666 vn = net_generic(net, vlan_net_id);
96667diff --git a/net/9p/client.c b/net/9p/client.c
96668index 9186550..e604a2f 100644
96669--- a/net/9p/client.c
96670+++ b/net/9p/client.c
96671@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96672 len - inline_len);
96673 } else {
96674 err = copy_from_user(ename + inline_len,
96675- uidata, len - inline_len);
96676+ (char __force_user *)uidata, len - inline_len);
96677 if (err) {
96678 err = -EFAULT;
96679 goto out_err;
96680@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96681 kernel_buf = 1;
96682 indata = data;
96683 } else
96684- indata = (__force char *)udata;
96685+ indata = (__force_kernel char *)udata;
96686 /*
96687 * response header len is 11
96688 * PDU Header(7) + IO Size (4)
96689@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96690 kernel_buf = 1;
96691 odata = data;
96692 } else
96693- odata = (char *)udata;
96694+ odata = (char __force_kernel *)udata;
96695 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96696 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96697 fid->fid, offset, rsize);
96698diff --git a/net/9p/mod.c b/net/9p/mod.c
96699index 6ab36ae..6f1841b 100644
96700--- a/net/9p/mod.c
96701+++ b/net/9p/mod.c
96702@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96703 void v9fs_register_trans(struct p9_trans_module *m)
96704 {
96705 spin_lock(&v9fs_trans_lock);
96706- list_add_tail(&m->list, &v9fs_trans_list);
96707+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96708 spin_unlock(&v9fs_trans_lock);
96709 }
96710 EXPORT_SYMBOL(v9fs_register_trans);
96711@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96712 void v9fs_unregister_trans(struct p9_trans_module *m)
96713 {
96714 spin_lock(&v9fs_trans_lock);
96715- list_del_init(&m->list);
96716+ pax_list_del_init((struct list_head *)&m->list);
96717 spin_unlock(&v9fs_trans_lock);
96718 }
96719 EXPORT_SYMBOL(v9fs_unregister_trans);
96720diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96721index b7bd7f2..2498bf7 100644
96722--- a/net/9p/trans_fd.c
96723+++ b/net/9p/trans_fd.c
96724@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96725 oldfs = get_fs();
96726 set_fs(get_ds());
96727 /* The cast to a user pointer is valid due to the set_fs() */
96728- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96729+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96730 set_fs(oldfs);
96731
96732 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96733diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
96734index af46bc4..f9adfcd 100644
96735--- a/net/appletalk/atalk_proc.c
96736+++ b/net/appletalk/atalk_proc.c
96737@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
96738 struct proc_dir_entry *p;
96739 int rc = -ENOMEM;
96740
96741- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
96742+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
96743 if (!atalk_proc_dir)
96744 goto out;
96745
96746diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96747index 876fbe8..8bbea9f 100644
96748--- a/net/atm/atm_misc.c
96749+++ b/net/atm/atm_misc.c
96750@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96751 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96752 return 1;
96753 atm_return(vcc, truesize);
96754- atomic_inc(&vcc->stats->rx_drop);
96755+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96756 return 0;
96757 }
96758 EXPORT_SYMBOL(atm_charge);
96759@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96760 }
96761 }
96762 atm_return(vcc, guess);
96763- atomic_inc(&vcc->stats->rx_drop);
96764+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96765 return NULL;
96766 }
96767 EXPORT_SYMBOL(atm_alloc_charge);
96768@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96769
96770 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96771 {
96772-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96773+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96774 __SONET_ITEMS
96775 #undef __HANDLE_ITEM
96776 }
96777@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96778
96779 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96780 {
96781-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96782+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96783 __SONET_ITEMS
96784 #undef __HANDLE_ITEM
96785 }
96786diff --git a/net/atm/lec.c b/net/atm/lec.c
96787index 5a2f602..9396143 100644
96788--- a/net/atm/lec.c
96789+++ b/net/atm/lec.c
96790@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96791 }
96792
96793 static struct lane2_ops lane2_ops = {
96794- lane2_resolve, /* resolve, spec 3.1.3 */
96795- lane2_associate_req, /* associate_req, spec 3.1.4 */
96796- NULL /* associate indicator, spec 3.1.5 */
96797+ .resolve = lane2_resolve,
96798+ .associate_req = lane2_associate_req,
96799+ .associate_indicator = NULL
96800 };
96801
96802 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96803diff --git a/net/atm/lec.h b/net/atm/lec.h
96804index 4149db1..f2ab682 100644
96805--- a/net/atm/lec.h
96806+++ b/net/atm/lec.h
96807@@ -48,7 +48,7 @@ struct lane2_ops {
96808 const u8 *tlvs, u32 sizeoftlvs);
96809 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96810 const u8 *tlvs, u32 sizeoftlvs);
96811-};
96812+} __no_const;
96813
96814 /*
96815 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96816diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96817index d1b2d9a..d549f7f 100644
96818--- a/net/atm/mpoa_caches.c
96819+++ b/net/atm/mpoa_caches.c
96820@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96821
96822
96823 static struct in_cache_ops ingress_ops = {
96824- in_cache_add_entry, /* add_entry */
96825- in_cache_get, /* get */
96826- in_cache_get_with_mask, /* get_with_mask */
96827- in_cache_get_by_vcc, /* get_by_vcc */
96828- in_cache_put, /* put */
96829- in_cache_remove_entry, /* remove_entry */
96830- cache_hit, /* cache_hit */
96831- clear_count_and_expired, /* clear_count */
96832- check_resolving_entries, /* check_resolving */
96833- refresh_entries, /* refresh */
96834- in_destroy_cache /* destroy_cache */
96835+ .add_entry = in_cache_add_entry,
96836+ .get = in_cache_get,
96837+ .get_with_mask = in_cache_get_with_mask,
96838+ .get_by_vcc = in_cache_get_by_vcc,
96839+ .put = in_cache_put,
96840+ .remove_entry = in_cache_remove_entry,
96841+ .cache_hit = cache_hit,
96842+ .clear_count = clear_count_and_expired,
96843+ .check_resolving = check_resolving_entries,
96844+ .refresh = refresh_entries,
96845+ .destroy_cache = in_destroy_cache
96846 };
96847
96848 static struct eg_cache_ops egress_ops = {
96849- eg_cache_add_entry, /* add_entry */
96850- eg_cache_get_by_cache_id, /* get_by_cache_id */
96851- eg_cache_get_by_tag, /* get_by_tag */
96852- eg_cache_get_by_vcc, /* get_by_vcc */
96853- eg_cache_get_by_src_ip, /* get_by_src_ip */
96854- eg_cache_put, /* put */
96855- eg_cache_remove_entry, /* remove_entry */
96856- update_eg_cache_entry, /* update */
96857- clear_expired, /* clear_expired */
96858- eg_destroy_cache /* destroy_cache */
96859+ .add_entry = eg_cache_add_entry,
96860+ .get_by_cache_id = eg_cache_get_by_cache_id,
96861+ .get_by_tag = eg_cache_get_by_tag,
96862+ .get_by_vcc = eg_cache_get_by_vcc,
96863+ .get_by_src_ip = eg_cache_get_by_src_ip,
96864+ .put = eg_cache_put,
96865+ .remove_entry = eg_cache_remove_entry,
96866+ .update = update_eg_cache_entry,
96867+ .clear_expired = clear_expired,
96868+ .destroy_cache = eg_destroy_cache
96869 };
96870
96871
96872diff --git a/net/atm/proc.c b/net/atm/proc.c
96873index bbb6461..cf04016 100644
96874--- a/net/atm/proc.c
96875+++ b/net/atm/proc.c
96876@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96877 const struct k_atm_aal_stats *stats)
96878 {
96879 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96880- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96881- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96882- atomic_read(&stats->rx_drop));
96883+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96884+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96885+ atomic_read_unchecked(&stats->rx_drop));
96886 }
96887
96888 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96889diff --git a/net/atm/resources.c b/net/atm/resources.c
96890index 0447d5d..3cf4728 100644
96891--- a/net/atm/resources.c
96892+++ b/net/atm/resources.c
96893@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96894 static void copy_aal_stats(struct k_atm_aal_stats *from,
96895 struct atm_aal_stats *to)
96896 {
96897-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96898+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96899 __AAL_STAT_ITEMS
96900 #undef __HANDLE_ITEM
96901 }
96902@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96903 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96904 struct atm_aal_stats *to)
96905 {
96906-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96907+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96908 __AAL_STAT_ITEMS
96909 #undef __HANDLE_ITEM
96910 }
96911diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96912index 919a5ce..cc6b444 100644
96913--- a/net/ax25/sysctl_net_ax25.c
96914+++ b/net/ax25/sysctl_net_ax25.c
96915@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96916 {
96917 char path[sizeof("net/ax25/") + IFNAMSIZ];
96918 int k;
96919- struct ctl_table *table;
96920+ ctl_table_no_const *table;
96921
96922 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96923 if (!table)
96924diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96925index 8323bce..a03130d 100644
96926--- a/net/batman-adv/bat_iv_ogm.c
96927+++ b/net/batman-adv/bat_iv_ogm.c
96928@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96929
96930 /* randomize initial seqno to avoid collision */
96931 get_random_bytes(&random_seqno, sizeof(random_seqno));
96932- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96933+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96934
96935 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96936 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96937@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96938 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96939
96940 /* change sequence number to network order */
96941- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96942+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96943 batadv_ogm_packet->seqno = htonl(seqno);
96944- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96945+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96946
96947 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96948
96949@@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
96950 return;
96951
96952 /* could be changed by schedule_own_packet() */
96953- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96954+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96955
96956 if (ogm_packet->flags & BATADV_DIRECTLINK)
96957 has_directlink_flag = true;
96958diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96959index 88df9b1..69cf7c0 100644
96960--- a/net/batman-adv/fragmentation.c
96961+++ b/net/batman-adv/fragmentation.c
96962@@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96963 frag_header.packet_type = BATADV_UNICAST_FRAG;
96964 frag_header.version = BATADV_COMPAT_VERSION;
96965 frag_header.ttl = BATADV_TTL;
96966- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96967+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96968 frag_header.reserved = 0;
96969 frag_header.no = 0;
96970 frag_header.total_size = htons(skb->len);
96971diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96972index f82c267..0e56d32 100644
96973--- a/net/batman-adv/soft-interface.c
96974+++ b/net/batman-adv/soft-interface.c
96975@@ -283,7 +283,7 @@ send:
96976 primary_if->net_dev->dev_addr, ETH_ALEN);
96977
96978 /* set broadcast sequence number */
96979- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96980+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96981 bcast_packet->seqno = htonl(seqno);
96982
96983 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96984@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96985 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96986
96987 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96988- atomic_set(&bat_priv->bcast_seqno, 1);
96989+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96990 atomic_set(&bat_priv->tt.vn, 0);
96991 atomic_set(&bat_priv->tt.local_changes, 0);
96992 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96993@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96994
96995 /* randomize initial seqno to avoid collision */
96996 get_random_bytes(&random_seqno, sizeof(random_seqno));
96997- atomic_set(&bat_priv->frag_seqno, random_seqno);
96998+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96999
97000 bat_priv->primary_if = NULL;
97001 bat_priv->num_ifaces = 0;
97002diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97003index 78370ab..1cb3614 100644
97004--- a/net/batman-adv/types.h
97005+++ b/net/batman-adv/types.h
97006@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
97007 struct batadv_hard_iface_bat_iv {
97008 unsigned char *ogm_buff;
97009 int ogm_buff_len;
97010- atomic_t ogm_seqno;
97011+ atomic_unchecked_t ogm_seqno;
97012 };
97013
97014 /**
97015@@ -714,7 +714,7 @@ struct batadv_priv {
97016 atomic_t bonding;
97017 atomic_t fragmentation;
97018 atomic_t packet_size_max;
97019- atomic_t frag_seqno;
97020+ atomic_unchecked_t frag_seqno;
97021 #ifdef CONFIG_BATMAN_ADV_BLA
97022 atomic_t bridge_loop_avoidance;
97023 #endif
97024@@ -730,7 +730,7 @@ struct batadv_priv {
97025 #endif
97026 uint32_t isolation_mark;
97027 uint32_t isolation_mark_mask;
97028- atomic_t bcast_seqno;
97029+ atomic_unchecked_t bcast_seqno;
97030 atomic_t bcast_queue_left;
97031 atomic_t batman_queue_left;
97032 char num_ifaces;
97033diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97034index 7552f9e..074ce29 100644
97035--- a/net/bluetooth/hci_sock.c
97036+++ b/net/bluetooth/hci_sock.c
97037@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97038 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97039 }
97040
97041- len = min_t(unsigned int, len, sizeof(uf));
97042+ len = min((size_t)len, sizeof(uf));
97043 if (copy_from_user(&uf, optval, len)) {
97044 err = -EFAULT;
97045 break;
97046diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97047index b0ad2c7..96f6a5e 100644
97048--- a/net/bluetooth/l2cap_core.c
97049+++ b/net/bluetooth/l2cap_core.c
97050@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97051 break;
97052
97053 case L2CAP_CONF_RFC:
97054- if (olen == sizeof(rfc))
97055- memcpy(&rfc, (void *)val, olen);
97056+ if (olen != sizeof(rfc))
97057+ break;
97058+
97059+ memcpy(&rfc, (void *)val, olen);
97060
97061 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97062 rfc.mode != chan->mode)
97063diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97064index d58f76b..b69600a 100644
97065--- a/net/bluetooth/l2cap_sock.c
97066+++ b/net/bluetooth/l2cap_sock.c
97067@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97068 struct sock *sk = sock->sk;
97069 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97070 struct l2cap_options opts;
97071- int len, err = 0;
97072+ int err = 0;
97073+ size_t len = optlen;
97074 u32 opt;
97075
97076 BT_DBG("sk %p", sk);
97077@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97078 opts.max_tx = chan->max_tx;
97079 opts.txwin_size = chan->tx_win;
97080
97081- len = min_t(unsigned int, sizeof(opts), optlen);
97082+ len = min(sizeof(opts), len);
97083 if (copy_from_user((char *) &opts, optval, len)) {
97084 err = -EFAULT;
97085 break;
97086@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97087 struct bt_security sec;
97088 struct bt_power pwr;
97089 struct l2cap_conn *conn;
97090- int len, err = 0;
97091+ int err = 0;
97092+ size_t len = optlen;
97093 u32 opt;
97094
97095 BT_DBG("sk %p", sk);
97096@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97097
97098 sec.level = BT_SECURITY_LOW;
97099
97100- len = min_t(unsigned int, sizeof(sec), optlen);
97101+ len = min(sizeof(sec), len);
97102 if (copy_from_user((char *) &sec, optval, len)) {
97103 err = -EFAULT;
97104 break;
97105@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97106
97107 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97108
97109- len = min_t(unsigned int, sizeof(pwr), optlen);
97110+ len = min(sizeof(pwr), len);
97111 if (copy_from_user((char *) &pwr, optval, len)) {
97112 err = -EFAULT;
97113 break;
97114diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97115index 3c2d3e4..884855a 100644
97116--- a/net/bluetooth/rfcomm/sock.c
97117+++ b/net/bluetooth/rfcomm/sock.c
97118@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97119 struct sock *sk = sock->sk;
97120 struct bt_security sec;
97121 int err = 0;
97122- size_t len;
97123+ size_t len = optlen;
97124 u32 opt;
97125
97126 BT_DBG("sk %p", sk);
97127@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97128
97129 sec.level = BT_SECURITY_LOW;
97130
97131- len = min_t(unsigned int, sizeof(sec), optlen);
97132+ len = min(sizeof(sec), len);
97133 if (copy_from_user((char *) &sec, optval, len)) {
97134 err = -EFAULT;
97135 break;
97136diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97137index f9c0980a..fcbbfeb 100644
97138--- a/net/bluetooth/rfcomm/tty.c
97139+++ b/net/bluetooth/rfcomm/tty.c
97140@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97141 BT_DBG("tty %p id %d", tty, tty->index);
97142
97143 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97144- dev->channel, dev->port.count);
97145+ dev->channel, atomic_read(&dev->port.count));
97146
97147 err = tty_port_open(&dev->port, tty, filp);
97148 if (err)
97149@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97150 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97151
97152 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97153- dev->port.count);
97154+ atomic_read(&dev->port.count));
97155
97156 tty_port_close(&dev->port, tty, filp);
97157 }
97158diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97159index 0e474b1..fb7109c 100644
97160--- a/net/bridge/netfilter/ebtables.c
97161+++ b/net/bridge/netfilter/ebtables.c
97162@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97163 tmp.valid_hooks = t->table->valid_hooks;
97164 }
97165 mutex_unlock(&ebt_mutex);
97166- if (copy_to_user(user, &tmp, *len) != 0) {
97167+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97168 BUGPRINT("c2u Didn't work\n");
97169 ret = -EFAULT;
97170 break;
97171@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97172 goto out;
97173 tmp.valid_hooks = t->valid_hooks;
97174
97175- if (copy_to_user(user, &tmp, *len) != 0) {
97176+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97177 ret = -EFAULT;
97178 break;
97179 }
97180@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97181 tmp.entries_size = t->table->entries_size;
97182 tmp.valid_hooks = t->table->valid_hooks;
97183
97184- if (copy_to_user(user, &tmp, *len) != 0) {
97185+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97186 ret = -EFAULT;
97187 break;
97188 }
97189diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97190index 0f45522..dab651f 100644
97191--- a/net/caif/cfctrl.c
97192+++ b/net/caif/cfctrl.c
97193@@ -10,6 +10,7 @@
97194 #include <linux/spinlock.h>
97195 #include <linux/slab.h>
97196 #include <linux/pkt_sched.h>
97197+#include <linux/sched.h>
97198 #include <net/caif/caif_layer.h>
97199 #include <net/caif/cfpkt.h>
97200 #include <net/caif/cfctrl.h>
97201@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97202 memset(&dev_info, 0, sizeof(dev_info));
97203 dev_info.id = 0xff;
97204 cfsrvl_init(&this->serv, 0, &dev_info, false);
97205- atomic_set(&this->req_seq_no, 1);
97206- atomic_set(&this->rsp_seq_no, 1);
97207+ atomic_set_unchecked(&this->req_seq_no, 1);
97208+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97209 this->serv.layer.receive = cfctrl_recv;
97210 sprintf(this->serv.layer.name, "ctrl");
97211 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97212@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97213 struct cfctrl_request_info *req)
97214 {
97215 spin_lock_bh(&ctrl->info_list_lock);
97216- atomic_inc(&ctrl->req_seq_no);
97217- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97218+ atomic_inc_unchecked(&ctrl->req_seq_no);
97219+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97220 list_add_tail(&req->list, &ctrl->list);
97221 spin_unlock_bh(&ctrl->info_list_lock);
97222 }
97223@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97224 if (p != first)
97225 pr_warn("Requests are not received in order\n");
97226
97227- atomic_set(&ctrl->rsp_seq_no,
97228+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97229 p->sequence_no);
97230 list_del(&p->list);
97231 goto out;
97232diff --git a/net/can/af_can.c b/net/can/af_can.c
97233index a27f8aa..67174a3 100644
97234--- a/net/can/af_can.c
97235+++ b/net/can/af_can.c
97236@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97237 };
97238
97239 /* notifier block for netdevice event */
97240-static struct notifier_block can_netdev_notifier __read_mostly = {
97241+static struct notifier_block can_netdev_notifier = {
97242 .notifier_call = can_notifier,
97243 };
97244
97245diff --git a/net/can/bcm.c b/net/can/bcm.c
97246index dcb75c0..24b1b43 100644
97247--- a/net/can/bcm.c
97248+++ b/net/can/bcm.c
97249@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97250 }
97251
97252 /* create /proc/net/can-bcm directory */
97253- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97254+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97255 return 0;
97256 }
97257
97258diff --git a/net/can/gw.c b/net/can/gw.c
97259index ac31891..4799c17 100644
97260--- a/net/can/gw.c
97261+++ b/net/can/gw.c
97262@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97263 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97264
97265 static HLIST_HEAD(cgw_list);
97266-static struct notifier_block notifier;
97267
97268 static struct kmem_cache *cgw_cache __read_mostly;
97269
97270@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97271 return err;
97272 }
97273
97274+static struct notifier_block notifier = {
97275+ .notifier_call = cgw_notifier
97276+};
97277+
97278 static __init int cgw_module_init(void)
97279 {
97280 /* sanitize given module parameter */
97281@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97282 return -ENOMEM;
97283
97284 /* set notifier */
97285- notifier.notifier_call = cgw_notifier;
97286 register_netdevice_notifier(&notifier);
97287
97288 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97289diff --git a/net/can/proc.c b/net/can/proc.c
97290index b543470..d2ddae2 100644
97291--- a/net/can/proc.c
97292+++ b/net/can/proc.c
97293@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97294 void can_init_proc(void)
97295 {
97296 /* create /proc/net/can directory */
97297- can_dir = proc_mkdir("can", init_net.proc_net);
97298+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97299
97300 if (!can_dir) {
97301 printk(KERN_INFO "can: failed to create /proc/net/can . "
97302diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97303index 30efc5c..cfa1bbc 100644
97304--- a/net/ceph/messenger.c
97305+++ b/net/ceph/messenger.c
97306@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97307 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97308
97309 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97310-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97311+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97312
97313 static struct page *zero_page; /* used in certain error cases */
97314
97315@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97316 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97317 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97318
97319- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97320+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97321 s = addr_str[i];
97322
97323 switch (ss->ss_family) {
97324diff --git a/net/compat.c b/net/compat.c
97325index f50161f..94fa415 100644
97326--- a/net/compat.c
97327+++ b/net/compat.c
97328@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97329 return -EFAULT;
97330 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97331 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97332- kmsg->msg_name = compat_ptr(tmp1);
97333- kmsg->msg_iov = compat_ptr(tmp2);
97334- kmsg->msg_control = compat_ptr(tmp3);
97335+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97336+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97337+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97338 return 0;
97339 }
97340
97341@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97342
97343 if (kern_msg->msg_namelen) {
97344 if (mode == VERIFY_READ) {
97345- int err = move_addr_to_kernel(kern_msg->msg_name,
97346+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97347 kern_msg->msg_namelen,
97348 kern_address);
97349 if (err < 0)
97350@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97351 kern_msg->msg_name = NULL;
97352
97353 tot_len = iov_from_user_compat_to_kern(kern_iov,
97354- (struct compat_iovec __user *)kern_msg->msg_iov,
97355+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97356 kern_msg->msg_iovlen);
97357 if (tot_len >= 0)
97358 kern_msg->msg_iov = kern_iov;
97359@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97360
97361 #define CMSG_COMPAT_FIRSTHDR(msg) \
97362 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97363- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97364+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97365 (struct compat_cmsghdr __user *)NULL)
97366
97367 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97368 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97369 (ucmlen) <= (unsigned long) \
97370 ((mhdr)->msg_controllen - \
97371- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97372+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97373
97374 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97375 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97376 {
97377 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97378- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97379+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97380 msg->msg_controllen)
97381 return NULL;
97382 return (struct compat_cmsghdr __user *)ptr;
97383@@ -222,7 +222,7 @@ Efault:
97384
97385 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97386 {
97387- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97388+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97389 struct compat_cmsghdr cmhdr;
97390 struct compat_timeval ctv;
97391 struct compat_timespec cts[3];
97392@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97393
97394 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97395 {
97396- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97397+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97398 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97399 int fdnum = scm->fp->count;
97400 struct file **fp = scm->fp->fp;
97401@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97402 return -EFAULT;
97403 old_fs = get_fs();
97404 set_fs(KERNEL_DS);
97405- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97406+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97407 set_fs(old_fs);
97408
97409 return err;
97410@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97411 len = sizeof(ktime);
97412 old_fs = get_fs();
97413 set_fs(KERNEL_DS);
97414- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97415+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97416 set_fs(old_fs);
97417
97418 if (!err) {
97419@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97420 case MCAST_JOIN_GROUP:
97421 case MCAST_LEAVE_GROUP:
97422 {
97423- struct compat_group_req __user *gr32 = (void *)optval;
97424+ struct compat_group_req __user *gr32 = (void __user *)optval;
97425 struct group_req __user *kgr =
97426 compat_alloc_user_space(sizeof(struct group_req));
97427 u32 interface;
97428@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97429 case MCAST_BLOCK_SOURCE:
97430 case MCAST_UNBLOCK_SOURCE:
97431 {
97432- struct compat_group_source_req __user *gsr32 = (void *)optval;
97433+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97434 struct group_source_req __user *kgsr = compat_alloc_user_space(
97435 sizeof(struct group_source_req));
97436 u32 interface;
97437@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97438 }
97439 case MCAST_MSFILTER:
97440 {
97441- struct compat_group_filter __user *gf32 = (void *)optval;
97442+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97443 struct group_filter __user *kgf;
97444 u32 interface, fmode, numsrc;
97445
97446@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97447 char __user *optval, int __user *optlen,
97448 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97449 {
97450- struct compat_group_filter __user *gf32 = (void *)optval;
97451+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97452 struct group_filter __user *kgf;
97453 int __user *koptlen;
97454 u32 interface, fmode, numsrc;
97455@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97456
97457 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97458 return -EINVAL;
97459- if (copy_from_user(a, args, nas[call]))
97460+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97461 return -EFAULT;
97462 a0 = a[0];
97463 a1 = a[1];
97464diff --git a/net/core/datagram.c b/net/core/datagram.c
97465index a16ed7b..eb44d17 100644
97466--- a/net/core/datagram.c
97467+++ b/net/core/datagram.c
97468@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97469 }
97470
97471 kfree_skb(skb);
97472- atomic_inc(&sk->sk_drops);
97473+ atomic_inc_unchecked(&sk->sk_drops);
97474 sk_mem_reclaim_partial(sk);
97475
97476 return err;
97477diff --git a/net/core/dev.c b/net/core/dev.c
97478index 45fa2f1..f3e28ec 100644
97479--- a/net/core/dev.c
97480+++ b/net/core/dev.c
97481@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97482 {
97483 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97484 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97485- atomic_long_inc(&dev->rx_dropped);
97486+ atomic_long_inc_unchecked(&dev->rx_dropped);
97487 kfree_skb(skb);
97488 return NET_RX_DROP;
97489 }
97490 }
97491
97492 if (unlikely(!is_skb_forwardable(dev, skb))) {
97493- atomic_long_inc(&dev->rx_dropped);
97494+ atomic_long_inc_unchecked(&dev->rx_dropped);
97495 kfree_skb(skb);
97496 return NET_RX_DROP;
97497 }
97498@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97499
97500 struct dev_gso_cb {
97501 void (*destructor)(struct sk_buff *skb);
97502-};
97503+} __no_const;
97504
97505 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97506
97507@@ -3227,7 +3227,7 @@ enqueue:
97508
97509 local_irq_restore(flags);
97510
97511- atomic_long_inc(&skb->dev->rx_dropped);
97512+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97513 kfree_skb(skb);
97514 return NET_RX_DROP;
97515 }
97516@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97517 }
97518 EXPORT_SYMBOL(netif_rx_ni);
97519
97520-static void net_tx_action(struct softirq_action *h)
97521+static __latent_entropy void net_tx_action(void)
97522 {
97523 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97524
97525@@ -3645,7 +3645,7 @@ ncls:
97526 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97527 } else {
97528 drop:
97529- atomic_long_inc(&skb->dev->rx_dropped);
97530+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97531 kfree_skb(skb);
97532 /* Jamal, now you will not able to escape explaining
97533 * me how you were going to use this. :-)
97534@@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97535 }
97536 EXPORT_SYMBOL(netif_napi_del);
97537
97538-static void net_rx_action(struct softirq_action *h)
97539+static __latent_entropy void net_rx_action(void)
97540 {
97541 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97542 unsigned long time_limit = jiffies + 2;
97543@@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97544 } else {
97545 netdev_stats_to_stats64(storage, &dev->stats);
97546 }
97547- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97548+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97549 return storage;
97550 }
97551 EXPORT_SYMBOL(dev_get_stats);
97552diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97553index cf999e0..c59a975 100644
97554--- a/net/core/dev_ioctl.c
97555+++ b/net/core/dev_ioctl.c
97556@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97557 if (no_module && capable(CAP_NET_ADMIN))
97558 no_module = request_module("netdev-%s", name);
97559 if (no_module && capable(CAP_SYS_MODULE)) {
97560+#ifdef CONFIG_GRKERNSEC_MODHARDEN
97561+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
97562+#else
97563 if (!request_module("%s", name))
97564 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97565 name);
97566+#endif
97567 }
97568 }
97569 EXPORT_SYMBOL(dev_load);
97570diff --git a/net/core/filter.c b/net/core/filter.c
97571index ad30d62..21c0743 100644
97572--- a/net/core/filter.c
97573+++ b/net/core/filter.c
97574@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97575 void *ptr;
97576 u32 A = 0; /* Accumulator */
97577 u32 X = 0; /* Index Register */
97578- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97579+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97580 u32 tmp;
97581 int k;
97582
97583@@ -292,10 +292,10 @@ load_b:
97584 X = K;
97585 continue;
97586 case BPF_S_LD_MEM:
97587- A = mem[K];
97588+ A = mem[K&15];
97589 continue;
97590 case BPF_S_LDX_MEM:
97591- X = mem[K];
97592+ X = mem[K&15];
97593 continue;
97594 case BPF_S_MISC_TAX:
97595 X = A;
97596@@ -308,10 +308,10 @@ load_b:
97597 case BPF_S_RET_A:
97598 return A;
97599 case BPF_S_ST:
97600- mem[K] = A;
97601+ mem[K&15] = A;
97602 continue;
97603 case BPF_S_STX:
97604- mem[K] = X;
97605+ mem[K&15] = X;
97606 continue;
97607 case BPF_S_ANC_PROTOCOL:
97608 A = ntohs(skb->protocol);
97609@@ -355,6 +355,10 @@ load_b:
97610
97611 if (skb_is_nonlinear(skb))
97612 return 0;
97613+
97614+ if (skb->len < sizeof(struct nlattr))
97615+ return 0;
97616+
97617 if (A > skb->len - sizeof(struct nlattr))
97618 return 0;
97619
97620@@ -371,11 +375,15 @@ load_b:
97621
97622 if (skb_is_nonlinear(skb))
97623 return 0;
97624+
97625+ if (skb->len < sizeof(struct nlattr))
97626+ return 0;
97627+
97628 if (A > skb->len - sizeof(struct nlattr))
97629 return 0;
97630
97631 nla = (struct nlattr *)&skb->data[A];
97632- if (nla->nla_len > A - skb->len)
97633+ if (nla->nla_len > skb->len - A)
97634 return 0;
97635
97636 nla = nla_find_nested(nla, X);
97637@@ -391,9 +399,10 @@ load_b:
97638 continue;
97639 #endif
97640 default:
97641- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97642+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97643 fentry->code, fentry->jt,
97644 fentry->jf, fentry->k);
97645+ BUG();
97646 return 0;
97647 }
97648 }
97649@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97650 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97651 int pc, ret = 0;
97652
97653- BUILD_BUG_ON(BPF_MEMWORDS > 16);
97654+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
97655 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97656 if (!masks)
97657 return -ENOMEM;
97658@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97659 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97660 if (!fp)
97661 return -ENOMEM;
97662- memcpy(fp->insns, fprog->filter, fsize);
97663+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97664
97665 atomic_set(&fp->refcnt, 1);
97666 fp->len = fprog->len;
97667diff --git a/net/core/flow.c b/net/core/flow.c
97668index dfa602c..3103d88 100644
97669--- a/net/core/flow.c
97670+++ b/net/core/flow.c
97671@@ -61,7 +61,7 @@ struct flow_cache {
97672 struct timer_list rnd_timer;
97673 };
97674
97675-atomic_t flow_cache_genid = ATOMIC_INIT(0);
97676+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97677 EXPORT_SYMBOL(flow_cache_genid);
97678 static struct flow_cache flow_cache_global;
97679 static struct kmem_cache *flow_cachep __read_mostly;
97680@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97681
97682 static int flow_entry_valid(struct flow_cache_entry *fle)
97683 {
97684- if (atomic_read(&flow_cache_genid) != fle->genid)
97685+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97686 return 0;
97687 if (fle->object && !fle->object->ops->check(fle->object))
97688 return 0;
97689@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97690 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97691 fcp->hash_count++;
97692 }
97693- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97694+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97695 flo = fle->object;
97696 if (!flo)
97697 goto ret_object;
97698@@ -279,7 +279,7 @@ nocache:
97699 }
97700 flo = resolver(net, key, family, dir, flo, ctx);
97701 if (fle) {
97702- fle->genid = atomic_read(&flow_cache_genid);
97703+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
97704 if (!IS_ERR(flo))
97705 fle->object = flo;
97706 else
97707diff --git a/net/core/iovec.c b/net/core/iovec.c
97708index b618694..192bbba 100644
97709--- a/net/core/iovec.c
97710+++ b/net/core/iovec.c
97711@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97712 if (m->msg_namelen) {
97713 if (mode == VERIFY_READ) {
97714 void __user *namep;
97715- namep = (void __user __force *) m->msg_name;
97716+ namep = (void __force_user *) m->msg_name;
97717 err = move_addr_to_kernel(namep, m->msg_namelen,
97718 address);
97719 if (err < 0)
97720@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97721 }
97722
97723 size = m->msg_iovlen * sizeof(struct iovec);
97724- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97725+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97726 return -EFAULT;
97727
97728 m->msg_iov = iov;
97729diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97730index e161290..8149aea 100644
97731--- a/net/core/neighbour.c
97732+++ b/net/core/neighbour.c
97733@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97734 void __user *buffer, size_t *lenp, loff_t *ppos)
97735 {
97736 int size, ret;
97737- struct ctl_table tmp = *ctl;
97738+ ctl_table_no_const tmp = *ctl;
97739
97740 tmp.extra1 = &zero;
97741 tmp.extra2 = &unres_qlen_max;
97742@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
97743 void __user *buffer,
97744 size_t *lenp, loff_t *ppos)
97745 {
97746- struct ctl_table tmp = *ctl;
97747+ ctl_table_no_const tmp = *ctl;
97748 int ret;
97749
97750 tmp.extra1 = &zero;
97751@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97752 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97753 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97754 } else {
97755+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97756 dev_name_source = "default";
97757- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97758- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97759- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97760- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97761+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97762+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97763+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97764+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97765 }
97766
97767 if (handler) {
97768diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97769index 2bf8329..2eb1423 100644
97770--- a/net/core/net-procfs.c
97771+++ b/net/core/net-procfs.c
97772@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
97773 struct rtnl_link_stats64 temp;
97774 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
97775
97776- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97777+ if (gr_proc_is_restricted())
97778+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97779+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
97780+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
97781+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
97782+ else
97783+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97784 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
97785 dev->name, stats->rx_bytes, stats->rx_packets,
97786 stats->rx_errors,
97787@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
97788 return 0;
97789 }
97790
97791-static const struct seq_operations dev_seq_ops = {
97792+const struct seq_operations dev_seq_ops = {
97793 .start = dev_seq_start,
97794 .next = dev_seq_next,
97795 .stop = dev_seq_stop,
97796@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
97797
97798 static int softnet_seq_open(struct inode *inode, struct file *file)
97799 {
97800- return seq_open(file, &softnet_seq_ops);
97801+ return seq_open_restrict(file, &softnet_seq_ops);
97802 }
97803
97804 static const struct file_operations softnet_seq_fops = {
97805@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97806 else
97807 seq_printf(seq, "%04x", ntohs(pt->type));
97808
97809+#ifdef CONFIG_GRKERNSEC_HIDESYM
97810+ seq_printf(seq, " %-8s %pf\n",
97811+ pt->dev ? pt->dev->name : "", NULL);
97812+#else
97813 seq_printf(seq, " %-8s %pf\n",
97814 pt->dev ? pt->dev->name : "", pt->func);
97815+#endif
97816 }
97817
97818 return 0;
97819diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97820index 81d3a9a..a0bd7a8 100644
97821--- a/net/core/net_namespace.c
97822+++ b/net/core/net_namespace.c
97823@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97824 int error;
97825 LIST_HEAD(net_exit_list);
97826
97827- list_add_tail(&ops->list, list);
97828+ pax_list_add_tail((struct list_head *)&ops->list, list);
97829 if (ops->init || (ops->id && ops->size)) {
97830 for_each_net(net) {
97831 error = ops_init(ops, net);
97832@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97833
97834 out_undo:
97835 /* If I have an error cleanup all namespaces I initialized */
97836- list_del(&ops->list);
97837+ pax_list_del((struct list_head *)&ops->list);
97838 ops_exit_list(ops, &net_exit_list);
97839 ops_free_list(ops, &net_exit_list);
97840 return error;
97841@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97842 struct net *net;
97843 LIST_HEAD(net_exit_list);
97844
97845- list_del(&ops->list);
97846+ pax_list_del((struct list_head *)&ops->list);
97847 for_each_net(net)
97848 list_add_tail(&net->exit_list, &net_exit_list);
97849 ops_exit_list(ops, &net_exit_list);
97850@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97851 mutex_lock(&net_mutex);
97852 error = register_pernet_operations(&pernet_list, ops);
97853 if (!error && (first_device == &pernet_list))
97854- first_device = &ops->list;
97855+ first_device = (struct list_head *)&ops->list;
97856 mutex_unlock(&net_mutex);
97857 return error;
97858 }
97859diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97860index df9e6b1..6e68e4e 100644
97861--- a/net/core/netpoll.c
97862+++ b/net/core/netpoll.c
97863@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97864 struct udphdr *udph;
97865 struct iphdr *iph;
97866 struct ethhdr *eth;
97867- static atomic_t ip_ident;
97868+ static atomic_unchecked_t ip_ident;
97869 struct ipv6hdr *ip6h;
97870
97871 udp_len = len + sizeof(*udph);
97872@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97873 put_unaligned(0x45, (unsigned char *)iph);
97874 iph->tos = 0;
97875 put_unaligned(htons(ip_len), &(iph->tot_len));
97876- iph->id = htons(atomic_inc_return(&ip_ident));
97877+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97878 iph->frag_off = 0;
97879 iph->ttl = 64;
97880 iph->protocol = IPPROTO_UDP;
97881diff --git a/net/core/pktgen.c b/net/core/pktgen.c
97882index fdac61c..e5e5b46 100644
97883--- a/net/core/pktgen.c
97884+++ b/net/core/pktgen.c
97885@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
97886 pn->net = net;
97887 INIT_LIST_HEAD(&pn->pktgen_threads);
97888 pn->pktgen_exiting = false;
97889- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
97890+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
97891 if (!pn->proc_dir) {
97892 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
97893 return -ENODEV;
97894diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97895index 120eecc..cd1ec44 100644
97896--- a/net/core/rtnetlink.c
97897+++ b/net/core/rtnetlink.c
97898@@ -58,7 +58,7 @@ struct rtnl_link {
97899 rtnl_doit_func doit;
97900 rtnl_dumpit_func dumpit;
97901 rtnl_calcit_func calcit;
97902-};
97903+} __no_const;
97904
97905 static DEFINE_MUTEX(rtnl_mutex);
97906
97907@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97908 if (rtnl_link_ops_get(ops->kind))
97909 return -EEXIST;
97910
97911- if (!ops->dellink)
97912- ops->dellink = unregister_netdevice_queue;
97913+ if (!ops->dellink) {
97914+ pax_open_kernel();
97915+ *(void **)&ops->dellink = unregister_netdevice_queue;
97916+ pax_close_kernel();
97917+ }
97918
97919- list_add_tail(&ops->list, &link_ops);
97920+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97921 return 0;
97922 }
97923 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97924@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97925 for_each_net(net) {
97926 __rtnl_kill_links(net, ops);
97927 }
97928- list_del(&ops->list);
97929+ pax_list_del((struct list_head *)&ops->list);
97930 }
97931 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97932
97933diff --git a/net/core/scm.c b/net/core/scm.c
97934index b442e7e..6f5b5a2 100644
97935--- a/net/core/scm.c
97936+++ b/net/core/scm.c
97937@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97938 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97939 {
97940 struct cmsghdr __user *cm
97941- = (__force struct cmsghdr __user *)msg->msg_control;
97942+ = (struct cmsghdr __force_user *)msg->msg_control;
97943 struct cmsghdr cmhdr;
97944 int cmlen = CMSG_LEN(len);
97945 int err;
97946@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97947 err = -EFAULT;
97948 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97949 goto out;
97950- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97951+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97952 goto out;
97953 cmlen = CMSG_SPACE(len);
97954 if (msg->msg_controllen < cmlen)
97955@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97956 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97957 {
97958 struct cmsghdr __user *cm
97959- = (__force struct cmsghdr __user*)msg->msg_control;
97960+ = (struct cmsghdr __force_user *)msg->msg_control;
97961
97962 int fdmax = 0;
97963 int fdnum = scm->fp->count;
97964@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97965 if (fdnum < fdmax)
97966 fdmax = fdnum;
97967
97968- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97969+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97970 i++, cmfptr++)
97971 {
97972 struct socket *sock;
97973diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97974index 90b96a1..cd18f16d 100644
97975--- a/net/core/skbuff.c
97976+++ b/net/core/skbuff.c
97977@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
97978 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97979 int len, __wsum csum)
97980 {
97981- const struct skb_checksum_ops ops = {
97982+ static const struct skb_checksum_ops ops = {
97983 .update = csum_partial_ext,
97984 .combine = csum_block_add_ext,
97985 };
97986@@ -3220,13 +3220,15 @@ void __init skb_init(void)
97987 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97988 sizeof(struct sk_buff),
97989 0,
97990- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97991+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97992+ SLAB_NO_SANITIZE,
97993 NULL);
97994 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97995 (2*sizeof(struct sk_buff)) +
97996 sizeof(atomic_t),
97997 0,
97998- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97999+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98000+ SLAB_NO_SANITIZE,
98001 NULL);
98002 }
98003
98004diff --git a/net/core/sock.c b/net/core/sock.c
98005index c0fc6bd..51d8326 100644
98006--- a/net/core/sock.c
98007+++ b/net/core/sock.c
98008@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98009 struct sk_buff_head *list = &sk->sk_receive_queue;
98010
98011 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98012- atomic_inc(&sk->sk_drops);
98013+ atomic_inc_unchecked(&sk->sk_drops);
98014 trace_sock_rcvqueue_full(sk, skb);
98015 return -ENOMEM;
98016 }
98017@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98018 return err;
98019
98020 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98021- atomic_inc(&sk->sk_drops);
98022+ atomic_inc_unchecked(&sk->sk_drops);
98023 return -ENOBUFS;
98024 }
98025
98026@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98027 skb_dst_force(skb);
98028
98029 spin_lock_irqsave(&list->lock, flags);
98030- skb->dropcount = atomic_read(&sk->sk_drops);
98031+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98032 __skb_queue_tail(list, skb);
98033 spin_unlock_irqrestore(&list->lock, flags);
98034
98035@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98036 skb->dev = NULL;
98037
98038 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98039- atomic_inc(&sk->sk_drops);
98040+ atomic_inc_unchecked(&sk->sk_drops);
98041 goto discard_and_relse;
98042 }
98043 if (nested)
98044@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98045 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98046 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98047 bh_unlock_sock(sk);
98048- atomic_inc(&sk->sk_drops);
98049+ atomic_inc_unchecked(&sk->sk_drops);
98050 goto discard_and_relse;
98051 }
98052
98053@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98054 struct timeval tm;
98055 } v;
98056
98057- int lv = sizeof(int);
98058- int len;
98059+ unsigned int lv = sizeof(int);
98060+ unsigned int len;
98061
98062 if (get_user(len, optlen))
98063 return -EFAULT;
98064- if (len < 0)
98065+ if (len > INT_MAX)
98066 return -EINVAL;
98067
98068 memset(&v, 0, sizeof(v));
98069@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98070
98071 case SO_PEERNAME:
98072 {
98073- char address[128];
98074+ char address[_K_SS_MAXSIZE];
98075
98076 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98077 return -ENOTCONN;
98078- if (lv < len)
98079+ if (lv < len || sizeof address < len)
98080 return -EINVAL;
98081 if (copy_to_user(optval, address, len))
98082 return -EFAULT;
98083@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98084
98085 if (len > lv)
98086 len = lv;
98087- if (copy_to_user(optval, &v, len))
98088+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98089 return -EFAULT;
98090 lenout:
98091 if (put_user(len, optlen))
98092@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98093 */
98094 smp_wmb();
98095 atomic_set(&sk->sk_refcnt, 1);
98096- atomic_set(&sk->sk_drops, 0);
98097+ atomic_set_unchecked(&sk->sk_drops, 0);
98098 }
98099 EXPORT_SYMBOL(sock_init_data);
98100
98101@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98102 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98103 int level, int type)
98104 {
98105+ struct sock_extended_err ee;
98106 struct sock_exterr_skb *serr;
98107 struct sk_buff *skb, *skb2;
98108 int copied, err;
98109@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98110 sock_recv_timestamp(msg, sk, skb);
98111
98112 serr = SKB_EXT_ERR(skb);
98113- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98114+ ee = serr->ee;
98115+ put_cmsg(msg, level, type, sizeof ee, &ee);
98116
98117 msg->msg_flags |= MSG_ERRQUEUE;
98118 err = copied;
98119diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98120index a0e9cf6..ef7f9ed 100644
98121--- a/net/core/sock_diag.c
98122+++ b/net/core/sock_diag.c
98123@@ -9,26 +9,33 @@
98124 #include <linux/inet_diag.h>
98125 #include <linux/sock_diag.h>
98126
98127-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98128+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98129 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98130 static DEFINE_MUTEX(sock_diag_table_mutex);
98131
98132 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98133 {
98134+#ifndef CONFIG_GRKERNSEC_HIDESYM
98135 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98136 cookie[1] != INET_DIAG_NOCOOKIE) &&
98137 ((u32)(unsigned long)sk != cookie[0] ||
98138 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98139 return -ESTALE;
98140 else
98141+#endif
98142 return 0;
98143 }
98144 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98145
98146 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98147 {
98148+#ifdef CONFIG_GRKERNSEC_HIDESYM
98149+ cookie[0] = 0;
98150+ cookie[1] = 0;
98151+#else
98152 cookie[0] = (u32)(unsigned long)sk;
98153 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98154+#endif
98155 }
98156 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98157
98158@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98159 mutex_lock(&sock_diag_table_mutex);
98160 if (sock_diag_handlers[hndl->family])
98161 err = -EBUSY;
98162- else
98163+ else {
98164+ pax_open_kernel();
98165 sock_diag_handlers[hndl->family] = hndl;
98166+ pax_close_kernel();
98167+ }
98168 mutex_unlock(&sock_diag_table_mutex);
98169
98170 return err;
98171@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98172
98173 mutex_lock(&sock_diag_table_mutex);
98174 BUG_ON(sock_diag_handlers[family] != hnld);
98175+ pax_open_kernel();
98176 sock_diag_handlers[family] = NULL;
98177+ pax_close_kernel();
98178 mutex_unlock(&sock_diag_table_mutex);
98179 }
98180 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98181diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98182index cf9cd13..8b56af3 100644
98183--- a/net/core/sysctl_net_core.c
98184+++ b/net/core/sysctl_net_core.c
98185@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98186 {
98187 unsigned int orig_size, size;
98188 int ret, i;
98189- struct ctl_table tmp = {
98190+ ctl_table_no_const tmp = {
98191 .data = &size,
98192 .maxlen = sizeof(size),
98193 .mode = table->mode
98194@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98195 void __user *buffer, size_t *lenp, loff_t *ppos)
98196 {
98197 char id[IFNAMSIZ];
98198- struct ctl_table tbl = {
98199+ ctl_table_no_const tbl = {
98200 .data = id,
98201 .maxlen = IFNAMSIZ,
98202 };
98203@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98204
98205 static __net_init int sysctl_core_net_init(struct net *net)
98206 {
98207- struct ctl_table *tbl;
98208+ ctl_table_no_const *tbl = NULL;
98209
98210 net->core.sysctl_somaxconn = SOMAXCONN;
98211
98212- tbl = netns_core_table;
98213 if (!net_eq(net, &init_net)) {
98214- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98215+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98216 if (tbl == NULL)
98217 goto err_dup;
98218
98219@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98220 if (net->user_ns != &init_user_ns) {
98221 tbl[0].procname = NULL;
98222 }
98223- }
98224-
98225- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98226+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98227+ } else
98228+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98229 if (net->core.sysctl_hdr == NULL)
98230 goto err_reg;
98231
98232 return 0;
98233
98234 err_reg:
98235- if (tbl != netns_core_table)
98236- kfree(tbl);
98237+ kfree(tbl);
98238 err_dup:
98239 return -ENOMEM;
98240 }
98241@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98242 kfree(tbl);
98243 }
98244
98245-static __net_initdata struct pernet_operations sysctl_core_ops = {
98246+static __net_initconst struct pernet_operations sysctl_core_ops = {
98247 .init = sysctl_core_net_init,
98248 .exit = sysctl_core_net_exit,
98249 };
98250diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98251index 4c04848..f575934 100644
98252--- a/net/decnet/af_decnet.c
98253+++ b/net/decnet/af_decnet.c
98254@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98255 .sysctl_rmem = sysctl_decnet_rmem,
98256 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98257 .obj_size = sizeof(struct dn_sock),
98258+ .slab_flags = SLAB_USERCOPY,
98259 };
98260
98261 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98262diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98263index a603823..a36ee0b 100644
98264--- a/net/decnet/dn_dev.c
98265+++ b/net/decnet/dn_dev.c
98266@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98267 .extra1 = &min_t3,
98268 .extra2 = &max_t3
98269 },
98270- {0}
98271+ { }
98272 },
98273 };
98274
98275diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98276index 5325b54..a0d4d69 100644
98277--- a/net/decnet/sysctl_net_decnet.c
98278+++ b/net/decnet/sysctl_net_decnet.c
98279@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98280
98281 if (len > *lenp) len = *lenp;
98282
98283- if (copy_to_user(buffer, addr, len))
98284+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98285 return -EFAULT;
98286
98287 *lenp = len;
98288@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98289
98290 if (len > *lenp) len = *lenp;
98291
98292- if (copy_to_user(buffer, devname, len))
98293+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98294 return -EFAULT;
98295
98296 *lenp = len;
98297diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98298index 1846c1f..96d4a9f 100644
98299--- a/net/ieee802154/dgram.c
98300+++ b/net/ieee802154/dgram.c
98301@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98302 if (saddr) {
98303 saddr->family = AF_IEEE802154;
98304 saddr->addr = mac_cb(skb)->sa;
98305+ }
98306+ if (addr_len)
98307 *addr_len = sizeof(*saddr);
98308- }
98309
98310 if (flags & MSG_TRUNC)
98311 copied = skb->len;
98312diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98313index 19ab78a..bf575c9 100644
98314--- a/net/ipv4/af_inet.c
98315+++ b/net/ipv4/af_inet.c
98316@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98317
98318 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98319
98320- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98321- if (!sysctl_local_reserved_ports)
98322- goto out;
98323-
98324 rc = proto_register(&tcp_prot, 1);
98325 if (rc)
98326- goto out_free_reserved_ports;
98327+ goto out;
98328
98329 rc = proto_register(&udp_prot, 1);
98330 if (rc)
98331@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98332 proto_unregister(&udp_prot);
98333 out_unregister_tcp_proto:
98334 proto_unregister(&tcp_prot);
98335-out_free_reserved_ports:
98336- kfree(sysctl_local_reserved_ports);
98337 goto out;
98338 }
98339
98340diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98341index bdbf68b..deb4759 100644
98342--- a/net/ipv4/devinet.c
98343+++ b/net/ipv4/devinet.c
98344@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98345 idx = 0;
98346 head = &net->dev_index_head[h];
98347 rcu_read_lock();
98348- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98349+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98350 net->dev_base_seq;
98351 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98352 if (idx < s_idx)
98353@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98354 idx = 0;
98355 head = &net->dev_index_head[h];
98356 rcu_read_lock();
98357- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98358+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98359 net->dev_base_seq;
98360 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98361 if (idx < s_idx)
98362@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98363 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98364 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98365
98366-static struct devinet_sysctl_table {
98367+static const struct devinet_sysctl_table {
98368 struct ctl_table_header *sysctl_header;
98369 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98370 } devinet_sysctl = {
98371@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98372 int err;
98373 struct ipv4_devconf *all, *dflt;
98374 #ifdef CONFIG_SYSCTL
98375- struct ctl_table *tbl = ctl_forward_entry;
98376+ ctl_table_no_const *tbl = NULL;
98377 struct ctl_table_header *forw_hdr;
98378 #endif
98379
98380@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98381 goto err_alloc_dflt;
98382
98383 #ifdef CONFIG_SYSCTL
98384- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98385+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98386 if (tbl == NULL)
98387 goto err_alloc_ctl;
98388
98389@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98390 goto err_reg_dflt;
98391
98392 err = -ENOMEM;
98393- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98394+ if (!net_eq(net, &init_net))
98395+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98396+ else
98397+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98398 if (forw_hdr == NULL)
98399 goto err_reg_ctl;
98400 net->ipv4.forw_hdr = forw_hdr;
98401@@ -2272,8 +2275,7 @@ err_reg_ctl:
98402 err_reg_dflt:
98403 __devinet_sysctl_unregister(all);
98404 err_reg_all:
98405- if (tbl != ctl_forward_entry)
98406- kfree(tbl);
98407+ kfree(tbl);
98408 err_alloc_ctl:
98409 #endif
98410 if (dflt != &ipv4_devconf_dflt)
98411diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98412index c7539e2..b455e51 100644
98413--- a/net/ipv4/fib_frontend.c
98414+++ b/net/ipv4/fib_frontend.c
98415@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98416 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98417 fib_sync_up(dev);
98418 #endif
98419- atomic_inc(&net->ipv4.dev_addr_genid);
98420+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98421 rt_cache_flush(dev_net(dev));
98422 break;
98423 case NETDEV_DOWN:
98424 fib_del_ifaddr(ifa, NULL);
98425- atomic_inc(&net->ipv4.dev_addr_genid);
98426+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98427 if (ifa->ifa_dev->ifa_list == NULL) {
98428 /* Last address was deleted from this interface.
98429 * Disable IP.
98430@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98431 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98432 fib_sync_up(dev);
98433 #endif
98434- atomic_inc(&net->ipv4.dev_addr_genid);
98435+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98436 rt_cache_flush(net);
98437 break;
98438 case NETDEV_DOWN:
98439diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98440index b53f0bf..3585b33 100644
98441--- a/net/ipv4/fib_semantics.c
98442+++ b/net/ipv4/fib_semantics.c
98443@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98444 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98445 nh->nh_gw,
98446 nh->nh_parent->fib_scope);
98447- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
98448+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
98449
98450 return nh->nh_saddr;
98451 }
98452diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
98453index 0d1e2cb..4501a2c 100644
98454--- a/net/ipv4/inet_connection_sock.c
98455+++ b/net/ipv4/inet_connection_sock.c
98456@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
98457 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
98458 #endif
98459
98460-unsigned long *sysctl_local_reserved_ports;
98461+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
98462 EXPORT_SYMBOL(sysctl_local_reserved_ports);
98463
98464 void inet_get_local_port_range(struct net *net, int *low, int *high)
98465diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
98466index 8b9cf27..0d8d592 100644
98467--- a/net/ipv4/inet_hashtables.c
98468+++ b/net/ipv4/inet_hashtables.c
98469@@ -18,6 +18,7 @@
98470 #include <linux/sched.h>
98471 #include <linux/slab.h>
98472 #include <linux/wait.h>
98473+#include <linux/security.h>
98474
98475 #include <net/inet_connection_sock.h>
98476 #include <net/inet_hashtables.h>
98477@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
98478 return inet_ehashfn(net, laddr, lport, faddr, fport);
98479 }
98480
98481+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
98482+
98483 /*
98484 * Allocate and initialize a new local port bind bucket.
98485 * The bindhash mutex for snum's hash chain must be held here.
98486@@ -554,6 +557,8 @@ ok:
98487 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98488 spin_unlock(&head->lock);
98489
98490+ gr_update_task_in_ip_table(current, inet_sk(sk));
98491+
98492 if (tw) {
98493 inet_twsk_deschedule(tw, death_row);
98494 while (twrefcnt) {
98495diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98496index 48f4244..f56d83a 100644
98497--- a/net/ipv4/inetpeer.c
98498+++ b/net/ipv4/inetpeer.c
98499@@ -496,8 +496,8 @@ relookup:
98500 if (p) {
98501 p->daddr = *daddr;
98502 atomic_set(&p->refcnt, 1);
98503- atomic_set(&p->rid, 0);
98504- atomic_set(&p->ip_id_count,
98505+ atomic_set_unchecked(&p->rid, 0);
98506+ atomic_set_unchecked(&p->ip_id_count,
98507 (daddr->family == AF_INET) ?
98508 secure_ip_id(daddr->addr.a4) :
98509 secure_ipv6_id(daddr->addr.a6));
98510diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98511index c10a3ce..dd71f84 100644
98512--- a/net/ipv4/ip_fragment.c
98513+++ b/net/ipv4/ip_fragment.c
98514@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98515 return 0;
98516
98517 start = qp->rid;
98518- end = atomic_inc_return(&peer->rid);
98519+ end = atomic_inc_return_unchecked(&peer->rid);
98520 qp->rid = end;
98521
98522 rc = qp->q.fragments && (end - start) > max;
98523@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98524
98525 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98526 {
98527- struct ctl_table *table;
98528+ ctl_table_no_const *table = NULL;
98529 struct ctl_table_header *hdr;
98530
98531- table = ip4_frags_ns_ctl_table;
98532 if (!net_eq(net, &init_net)) {
98533- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98534+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98535 if (table == NULL)
98536 goto err_alloc;
98537
98538@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98539 /* Don't export sysctls to unprivileged users */
98540 if (net->user_ns != &init_user_ns)
98541 table[0].procname = NULL;
98542- }
98543+ hdr = register_net_sysctl(net, "net/ipv4", table);
98544+ } else
98545+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98546
98547- hdr = register_net_sysctl(net, "net/ipv4", table);
98548 if (hdr == NULL)
98549 goto err_reg;
98550
98551@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98552 return 0;
98553
98554 err_reg:
98555- if (!net_eq(net, &init_net))
98556- kfree(table);
98557+ kfree(table);
98558 err_alloc:
98559 return -ENOMEM;
98560 }
98561diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98562index ec4f762..4ce3645 100644
98563--- a/net/ipv4/ip_gre.c
98564+++ b/net/ipv4/ip_gre.c
98565@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98566 module_param(log_ecn_error, bool, 0644);
98567 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98568
98569-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98570+static struct rtnl_link_ops ipgre_link_ops;
98571 static int ipgre_tunnel_init(struct net_device *dev);
98572
98573 static int ipgre_net_id __read_mostly;
98574@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98575 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98576 };
98577
98578-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98579+static struct rtnl_link_ops ipgre_link_ops = {
98580 .kind = "gre",
98581 .maxtype = IFLA_GRE_MAX,
98582 .policy = ipgre_policy,
98583@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98584 .fill_info = ipgre_fill_info,
98585 };
98586
98587-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98588+static struct rtnl_link_ops ipgre_tap_ops = {
98589 .kind = "gretap",
98590 .maxtype = IFLA_GRE_MAX,
98591 .policy = ipgre_policy,
98592diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98593index 580dd96..9fcef7e 100644
98594--- a/net/ipv4/ip_sockglue.c
98595+++ b/net/ipv4/ip_sockglue.c
98596@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98597 len = min_t(unsigned int, len, opt->optlen);
98598 if (put_user(len, optlen))
98599 return -EFAULT;
98600- if (copy_to_user(optval, opt->__data, len))
98601+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
98602+ copy_to_user(optval, opt->__data, len))
98603 return -EFAULT;
98604 return 0;
98605 }
98606@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98607 if (sk->sk_type != SOCK_STREAM)
98608 return -ENOPROTOOPT;
98609
98610- msg.msg_control = optval;
98611+ msg.msg_control = (void __force_kernel *)optval;
98612 msg.msg_controllen = len;
98613 msg.msg_flags = flags;
98614
98615diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98616index 48eafae..defff53 100644
98617--- a/net/ipv4/ip_vti.c
98618+++ b/net/ipv4/ip_vti.c
98619@@ -44,7 +44,7 @@
98620 #include <net/net_namespace.h>
98621 #include <net/netns/generic.h>
98622
98623-static struct rtnl_link_ops vti_link_ops __read_mostly;
98624+static struct rtnl_link_ops vti_link_ops;
98625
98626 static int vti_net_id __read_mostly;
98627 static int vti_tunnel_init(struct net_device *dev);
98628@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98629 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98630 };
98631
98632-static struct rtnl_link_ops vti_link_ops __read_mostly = {
98633+static struct rtnl_link_ops vti_link_ops = {
98634 .kind = "vti",
98635 .maxtype = IFLA_VTI_MAX,
98636 .policy = vti_policy,
98637diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98638index b3e86ea..18ce98c 100644
98639--- a/net/ipv4/ipconfig.c
98640+++ b/net/ipv4/ipconfig.c
98641@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98642
98643 mm_segment_t oldfs = get_fs();
98644 set_fs(get_ds());
98645- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98646+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98647 set_fs(oldfs);
98648 return res;
98649 }
98650@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98651
98652 mm_segment_t oldfs = get_fs();
98653 set_fs(get_ds());
98654- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98655+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98656 set_fs(oldfs);
98657 return res;
98658 }
98659@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
98660
98661 mm_segment_t oldfs = get_fs();
98662 set_fs(get_ds());
98663- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
98664+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
98665 set_fs(oldfs);
98666 return res;
98667 }
98668diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
98669index 812b183..56cbe9c 100644
98670--- a/net/ipv4/ipip.c
98671+++ b/net/ipv4/ipip.c
98672@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98673 static int ipip_net_id __read_mostly;
98674
98675 static int ipip_tunnel_init(struct net_device *dev);
98676-static struct rtnl_link_ops ipip_link_ops __read_mostly;
98677+static struct rtnl_link_ops ipip_link_ops;
98678
98679 static int ipip_err(struct sk_buff *skb, u32 info)
98680 {
98681@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
98682 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
98683 };
98684
98685-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
98686+static struct rtnl_link_ops ipip_link_ops = {
98687 .kind = "ipip",
98688 .maxtype = IFLA_IPTUN_MAX,
98689 .policy = ipip_policy,
98690diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
98691index 59da7cd..e318de1 100644
98692--- a/net/ipv4/netfilter/arp_tables.c
98693+++ b/net/ipv4/netfilter/arp_tables.c
98694@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
98695 #endif
98696
98697 static int get_info(struct net *net, void __user *user,
98698- const int *len, int compat)
98699+ int len, int compat)
98700 {
98701 char name[XT_TABLE_MAXNAMELEN];
98702 struct xt_table *t;
98703 int ret;
98704
98705- if (*len != sizeof(struct arpt_getinfo)) {
98706- duprintf("length %u != %Zu\n", *len,
98707+ if (len != sizeof(struct arpt_getinfo)) {
98708+ duprintf("length %u != %Zu\n", len,
98709 sizeof(struct arpt_getinfo));
98710 return -EINVAL;
98711 }
98712@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98713 info.size = private->size;
98714 strcpy(info.name, name);
98715
98716- if (copy_to_user(user, &info, *len) != 0)
98717+ if (copy_to_user(user, &info, len) != 0)
98718 ret = -EFAULT;
98719 else
98720 ret = 0;
98721@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98722
98723 switch (cmd) {
98724 case ARPT_SO_GET_INFO:
98725- ret = get_info(sock_net(sk), user, len, 1);
98726+ ret = get_info(sock_net(sk), user, *len, 1);
98727 break;
98728 case ARPT_SO_GET_ENTRIES:
98729 ret = compat_get_entries(sock_net(sk), user, len);
98730@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98731
98732 switch (cmd) {
98733 case ARPT_SO_GET_INFO:
98734- ret = get_info(sock_net(sk), user, len, 0);
98735+ ret = get_info(sock_net(sk), user, *len, 0);
98736 break;
98737
98738 case ARPT_SO_GET_ENTRIES:
98739diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98740index 718dfbd..cef4152 100644
98741--- a/net/ipv4/netfilter/ip_tables.c
98742+++ b/net/ipv4/netfilter/ip_tables.c
98743@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98744 #endif
98745
98746 static int get_info(struct net *net, void __user *user,
98747- const int *len, int compat)
98748+ int len, int compat)
98749 {
98750 char name[XT_TABLE_MAXNAMELEN];
98751 struct xt_table *t;
98752 int ret;
98753
98754- if (*len != sizeof(struct ipt_getinfo)) {
98755- duprintf("length %u != %zu\n", *len,
98756+ if (len != sizeof(struct ipt_getinfo)) {
98757+ duprintf("length %u != %zu\n", len,
98758 sizeof(struct ipt_getinfo));
98759 return -EINVAL;
98760 }
98761@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98762 info.size = private->size;
98763 strcpy(info.name, name);
98764
98765- if (copy_to_user(user, &info, *len) != 0)
98766+ if (copy_to_user(user, &info, len) != 0)
98767 ret = -EFAULT;
98768 else
98769 ret = 0;
98770@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98771
98772 switch (cmd) {
98773 case IPT_SO_GET_INFO:
98774- ret = get_info(sock_net(sk), user, len, 1);
98775+ ret = get_info(sock_net(sk), user, *len, 1);
98776 break;
98777 case IPT_SO_GET_ENTRIES:
98778 ret = compat_get_entries(sock_net(sk), user, len);
98779@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98780
98781 switch (cmd) {
98782 case IPT_SO_GET_INFO:
98783- ret = get_info(sock_net(sk), user, len, 0);
98784+ ret = get_info(sock_net(sk), user, *len, 0);
98785 break;
98786
98787 case IPT_SO_GET_ENTRIES:
98788diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
98789index 2510c02..cfb34fa 100644
98790--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
98791+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
98792@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
98793 spin_lock_init(&cn->lock);
98794
98795 #ifdef CONFIG_PROC_FS
98796- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
98797+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
98798 if (!cn->procdir) {
98799 pr_err("Unable to proc dir entry\n");
98800 return -ENOMEM;
98801diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98802index 2d11c09..3f153f8 100644
98803--- a/net/ipv4/ping.c
98804+++ b/net/ipv4/ping.c
98805@@ -59,7 +59,7 @@ struct ping_table {
98806 };
98807
98808 static struct ping_table ping_table;
98809-struct pingv6_ops pingv6_ops;
98810+struct pingv6_ops *pingv6_ops;
98811 EXPORT_SYMBOL_GPL(pingv6_ops);
98812
98813 static u16 ping_port_rover;
98814@@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
98815 struct group_info *group_info = get_current_groups();
98816 int i, j, count = group_info->ngroups;
98817 kgid_t low, high;
98818+ int ret = 0;
98819
98820 inet_get_ping_group_range_net(net, &low, &high);
98821 if (gid_lte(low, group) && gid_lte(group, high))
98822- return 0;
98823+ goto out_release_group;
98824
98825 for (i = 0; i < group_info->nblocks; i++) {
98826 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98827 for (j = 0; j < cp_count; j++) {
98828 kgid_t gid = group_info->blocks[i][j];
98829 if (gid_lte(low, gid) && gid_lte(gid, high))
98830- return 0;
98831+ goto out_release_group;
98832 }
98833
98834 count -= cp_count;
98835 }
98836
98837- return -EACCES;
98838+ ret = -EACCES;
98839+
98840+out_release_group:
98841+ put_group_info(group_info);
98842+ return ret;
98843 }
98844 EXPORT_SYMBOL_GPL(ping_init_sock);
98845
98846@@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98847 return -ENODEV;
98848 }
98849 }
98850- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98851+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98852 scoped);
98853 rcu_read_unlock();
98854
98855@@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98856 }
98857 #if IS_ENABLED(CONFIG_IPV6)
98858 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98859- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98860+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98861 #endif
98862 }
98863
98864@@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98865 info, (u8 *)icmph);
98866 #if IS_ENABLED(CONFIG_IPV6)
98867 } else if (family == AF_INET6) {
98868- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98869+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98870 info, (u8 *)icmph);
98871 #endif
98872 }
98873@@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98874 {
98875 struct inet_sock *isk = inet_sk(sk);
98876 int family = sk->sk_family;
98877+ struct sockaddr_in *sin;
98878+ struct sockaddr_in6 *sin6;
98879 struct sk_buff *skb;
98880 int copied, err;
98881
98882@@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98883 if (flags & MSG_OOB)
98884 goto out;
98885
98886+ if (addr_len) {
98887+ if (family == AF_INET)
98888+ *addr_len = sizeof(*sin);
98889+ else if (family == AF_INET6 && addr_len)
98890+ *addr_len = sizeof(*sin6);
98891+ }
98892+
98893 if (flags & MSG_ERRQUEUE) {
98894 if (family == AF_INET) {
98895 return ip_recv_error(sk, msg, len, addr_len);
98896 #if IS_ENABLED(CONFIG_IPV6)
98897 } else if (family == AF_INET6) {
98898- return pingv6_ops.ipv6_recv_error(sk, msg, len,
98899+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
98900 addr_len);
98901 #endif
98902 }
98903@@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98904 sin->sin_port = 0 /* skb->h.uh->source */;
98905 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98906 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98907- *addr_len = sizeof(*sin);
98908 }
98909
98910 if (isk->cmsg_flags)
98911@@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98912 sin6->sin6_scope_id =
98913 ipv6_iface_scope_id(&sin6->sin6_addr,
98914 IP6CB(skb)->iif);
98915- *addr_len = sizeof(*sin6);
98916 }
98917
98918 if (inet6_sk(sk)->rxopt.all)
98919- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
98920+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
98921 if (skb->protocol == htons(ETH_P_IPV6) &&
98922 inet6_sk(sk)->rxopt.all)
98923- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
98924+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
98925 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
98926 ip_cmsg_recv(msg, skb);
98927 #endif
98928@@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98929 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98930 0, sock_i_ino(sp),
98931 atomic_read(&sp->sk_refcnt), sp,
98932- atomic_read(&sp->sk_drops));
98933+ atomic_read_unchecked(&sp->sk_drops));
98934 }
98935
98936 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98937diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98938index c04518f..824ebe5 100644
98939--- a/net/ipv4/raw.c
98940+++ b/net/ipv4/raw.c
98941@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98942 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98943 {
98944 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98945- atomic_inc(&sk->sk_drops);
98946+ atomic_inc_unchecked(&sk->sk_drops);
98947 kfree_skb(skb);
98948 return NET_RX_DROP;
98949 }
98950@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98951 if (flags & MSG_OOB)
98952 goto out;
98953
98954+ if (addr_len)
98955+ *addr_len = sizeof(*sin);
98956+
98957 if (flags & MSG_ERRQUEUE) {
98958 err = ip_recv_error(sk, msg, len, addr_len);
98959 goto out;
98960@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98961 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98962 sin->sin_port = 0;
98963 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98964- *addr_len = sizeof(*sin);
98965 }
98966 if (inet->cmsg_flags)
98967 ip_cmsg_recv(msg, skb);
98968@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98969
98970 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98971 {
98972+ struct icmp_filter filter;
98973+
98974 if (optlen > sizeof(struct icmp_filter))
98975 optlen = sizeof(struct icmp_filter);
98976- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98977+ if (copy_from_user(&filter, optval, optlen))
98978 return -EFAULT;
98979+ raw_sk(sk)->filter = filter;
98980 return 0;
98981 }
98982
98983 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98984 {
98985 int len, ret = -EFAULT;
98986+ struct icmp_filter filter;
98987
98988 if (get_user(len, optlen))
98989 goto out;
98990@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98991 if (len > sizeof(struct icmp_filter))
98992 len = sizeof(struct icmp_filter);
98993 ret = -EFAULT;
98994- if (put_user(len, optlen) ||
98995- copy_to_user(optval, &raw_sk(sk)->filter, len))
98996+ filter = raw_sk(sk)->filter;
98997+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98998 goto out;
98999 ret = 0;
99000 out: return ret;
99001@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99002 0, 0L, 0,
99003 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99004 0, sock_i_ino(sp),
99005- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99006+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99007 }
99008
99009 static int raw_seq_show(struct seq_file *seq, void *v)
99010diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99011index 4c011ec..8fae66b 100644
99012--- a/net/ipv4/route.c
99013+++ b/net/ipv4/route.c
99014@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99015
99016 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99017 {
99018- return seq_open(file, &rt_cache_seq_ops);
99019+ return seq_open_restrict(file, &rt_cache_seq_ops);
99020 }
99021
99022 static const struct file_operations rt_cache_seq_fops = {
99023@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99024
99025 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99026 {
99027- return seq_open(file, &rt_cpu_seq_ops);
99028+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99029 }
99030
99031 static const struct file_operations rt_cpu_seq_fops = {
99032@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99033
99034 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99035 {
99036- return single_open(file, rt_acct_proc_show, NULL);
99037+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99038 }
99039
99040 static const struct file_operations rt_acct_proc_fops = {
99041@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99042 .maxlen = sizeof(int),
99043 .mode = 0200,
99044 .proc_handler = ipv4_sysctl_rtcache_flush,
99045+ .extra1 = &init_net,
99046 },
99047 { },
99048 };
99049
99050 static __net_init int sysctl_route_net_init(struct net *net)
99051 {
99052- struct ctl_table *tbl;
99053+ ctl_table_no_const *tbl = NULL;
99054
99055- tbl = ipv4_route_flush_table;
99056 if (!net_eq(net, &init_net)) {
99057- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99058+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99059 if (tbl == NULL)
99060 goto err_dup;
99061
99062 /* Don't export sysctls to unprivileged users */
99063 if (net->user_ns != &init_user_ns)
99064 tbl[0].procname = NULL;
99065- }
99066- tbl[0].extra1 = net;
99067+ tbl[0].extra1 = net;
99068+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99069+ } else
99070+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99071
99072- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99073 if (net->ipv4.route_hdr == NULL)
99074 goto err_reg;
99075 return 0;
99076
99077 err_reg:
99078- if (tbl != ipv4_route_flush_table)
99079- kfree(tbl);
99080+ kfree(tbl);
99081 err_dup:
99082 return -ENOMEM;
99083 }
99084@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99085
99086 static __net_init int rt_genid_init(struct net *net)
99087 {
99088- atomic_set(&net->ipv4.rt_genid, 0);
99089- atomic_set(&net->fnhe_genid, 0);
99090+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99091+ atomic_set_unchecked(&net->fnhe_genid, 0);
99092 get_random_bytes(&net->ipv4.dev_addr_genid,
99093 sizeof(net->ipv4.dev_addr_genid));
99094 return 0;
99095diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99096index 44eba05..b36864b 100644
99097--- a/net/ipv4/sysctl_net_ipv4.c
99098+++ b/net/ipv4/sysctl_net_ipv4.c
99099@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99100 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
99101 int ret;
99102 int range[2];
99103- struct ctl_table tmp = {
99104+ ctl_table_no_const tmp = {
99105 .data = &range,
99106 .maxlen = sizeof(range),
99107 .mode = table->mode,
99108@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99109 int ret;
99110 gid_t urange[2];
99111 kgid_t low, high;
99112- struct ctl_table tmp = {
99113+ ctl_table_no_const tmp = {
99114 .data = &urange,
99115 .maxlen = sizeof(urange),
99116 .mode = table->mode,
99117@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99118 void __user *buffer, size_t *lenp, loff_t *ppos)
99119 {
99120 char val[TCP_CA_NAME_MAX];
99121- struct ctl_table tbl = {
99122+ ctl_table_no_const tbl = {
99123 .data = val,
99124 .maxlen = TCP_CA_NAME_MAX,
99125 };
99126@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99127 void __user *buffer, size_t *lenp,
99128 loff_t *ppos)
99129 {
99130- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99131+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99132 int ret;
99133
99134 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99135@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99136 void __user *buffer, size_t *lenp,
99137 loff_t *ppos)
99138 {
99139- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99140+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99141 int ret;
99142
99143 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99144@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99145 void __user *buffer, size_t *lenp,
99146 loff_t *ppos)
99147 {
99148- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99149+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99150 struct tcp_fastopen_context *ctxt;
99151 int ret;
99152 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99153@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99154 },
99155 {
99156 .procname = "ip_local_reserved_ports",
99157- .data = NULL, /* initialized in sysctl_ipv4_init */
99158+ .data = sysctl_local_reserved_ports,
99159 .maxlen = 65536,
99160 .mode = 0644,
99161 .proc_handler = proc_do_large_bitmap,
99162@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99163
99164 static __net_init int ipv4_sysctl_init_net(struct net *net)
99165 {
99166- struct ctl_table *table;
99167+ ctl_table_no_const *table = NULL;
99168
99169- table = ipv4_net_table;
99170 if (!net_eq(net, &init_net)) {
99171 int i;
99172
99173- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99174+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99175 if (table == NULL)
99176 goto err_alloc;
99177
99178@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99179 net->ipv4.sysctl_local_ports.range[0] = 32768;
99180 net->ipv4.sysctl_local_ports.range[1] = 61000;
99181
99182- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99183+ if (!net_eq(net, &init_net))
99184+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99185+ else
99186+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99187 if (net->ipv4.ipv4_hdr == NULL)
99188 goto err_reg;
99189
99190 return 0;
99191
99192 err_reg:
99193- if (!net_eq(net, &init_net))
99194- kfree(table);
99195+ kfree(table);
99196 err_alloc:
99197 return -ENOMEM;
99198 }
99199@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99200 static __init int sysctl_ipv4_init(void)
99201 {
99202 struct ctl_table_header *hdr;
99203- struct ctl_table *i;
99204-
99205- for (i = ipv4_table; i->procname; i++) {
99206- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99207- i->data = sysctl_local_reserved_ports;
99208- break;
99209- }
99210- }
99211- if (!i->procname)
99212- return -EINVAL;
99213
99214 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99215 if (hdr == NULL)
99216diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99217index eeaac39..dc29942 100644
99218--- a/net/ipv4/tcp_input.c
99219+++ b/net/ipv4/tcp_input.c
99220@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99221 * without any lock. We want to make sure compiler wont store
99222 * intermediate values in this location.
99223 */
99224- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99225+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99226 sk->sk_max_pacing_rate);
99227 }
99228
99229@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99230 * simplifies code)
99231 */
99232 static void
99233-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99234+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99235 struct sk_buff *head, struct sk_buff *tail,
99236 u32 start, u32 end)
99237 {
99238@@ -5562,6 +5562,7 @@ discard:
99239 tcp_paws_reject(&tp->rx_opt, 0))
99240 goto discard_and_undo;
99241
99242+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99243 if (th->syn) {
99244 /* We see SYN without ACK. It is attempt of
99245 * simultaneous connect with crossed SYNs.
99246@@ -5612,6 +5613,7 @@ discard:
99247 goto discard;
99248 #endif
99249 }
99250+#endif
99251 /* "fifth, if neither of the SYN or RST bits is set then
99252 * drop the segment and return."
99253 */
99254@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99255 goto discard;
99256
99257 if (th->syn) {
99258- if (th->fin)
99259+ if (th->fin || th->urg || th->psh)
99260 goto discard;
99261 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99262 return 1;
99263diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99264index 1e4eac7..a66fa4a 100644
99265--- a/net/ipv4/tcp_ipv4.c
99266+++ b/net/ipv4/tcp_ipv4.c
99267@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99268 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99269
99270
99271+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99272+extern int grsec_enable_blackhole;
99273+#endif
99274+
99275 #ifdef CONFIG_TCP_MD5SIG
99276 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99277 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99278@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99279 return 0;
99280
99281 reset:
99282+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99283+ if (!grsec_enable_blackhole)
99284+#endif
99285 tcp_v4_send_reset(rsk, skb);
99286 discard:
99287 kfree_skb(skb);
99288@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99289 TCP_SKB_CB(skb)->sacked = 0;
99290
99291 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99292- if (!sk)
99293+ if (!sk) {
99294+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99295+ ret = 1;
99296+#endif
99297 goto no_tcp_socket;
99298-
99299+ }
99300 process:
99301- if (sk->sk_state == TCP_TIME_WAIT)
99302+ if (sk->sk_state == TCP_TIME_WAIT) {
99303+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99304+ ret = 2;
99305+#endif
99306 goto do_time_wait;
99307+ }
99308
99309 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99310 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99311@@ -2033,6 +2047,10 @@ csum_error:
99312 bad_packet:
99313 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99314 } else {
99315+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99316+ if (!grsec_enable_blackhole || (ret == 1 &&
99317+ (skb->dev->flags & IFF_LOOPBACK)))
99318+#endif
99319 tcp_v4_send_reset(NULL, skb);
99320 }
99321
99322diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99323index 7a436c5..1b05c59 100644
99324--- a/net/ipv4/tcp_minisocks.c
99325+++ b/net/ipv4/tcp_minisocks.c
99326@@ -27,6 +27,10 @@
99327 #include <net/inet_common.h>
99328 #include <net/xfrm.h>
99329
99330+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99331+extern int grsec_enable_blackhole;
99332+#endif
99333+
99334 int sysctl_tcp_syncookies __read_mostly = 1;
99335 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99336
99337@@ -709,7 +713,10 @@ embryonic_reset:
99338 * avoid becoming vulnerable to outside attack aiming at
99339 * resetting legit local connections.
99340 */
99341- req->rsk_ops->send_reset(sk, skb);
99342+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99343+ if (!grsec_enable_blackhole)
99344+#endif
99345+ req->rsk_ops->send_reset(sk, skb);
99346 } else if (fastopen) { /* received a valid RST pkt */
99347 reqsk_fastopen_remove(sk, req, true);
99348 tcp_reset(sk);
99349diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99350index 1f2d376..01d18c4 100644
99351--- a/net/ipv4/tcp_probe.c
99352+++ b/net/ipv4/tcp_probe.c
99353@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99354 if (cnt + width >= len)
99355 break;
99356
99357- if (copy_to_user(buf + cnt, tbuf, width))
99358+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99359 return -EFAULT;
99360 cnt += width;
99361 }
99362diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99363index 64f0354..a81b39d 100644
99364--- a/net/ipv4/tcp_timer.c
99365+++ b/net/ipv4/tcp_timer.c
99366@@ -22,6 +22,10 @@
99367 #include <linux/gfp.h>
99368 #include <net/tcp.h>
99369
99370+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99371+extern int grsec_lastack_retries;
99372+#endif
99373+
99374 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99375 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99376 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99377@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99378 }
99379 }
99380
99381+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99382+ if ((sk->sk_state == TCP_LAST_ACK) &&
99383+ (grsec_lastack_retries > 0) &&
99384+ (grsec_lastack_retries < retry_until))
99385+ retry_until = grsec_lastack_retries;
99386+#endif
99387+
99388 if (retransmits_timed_out(sk, retry_until,
99389 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99390 /* Has it gone just too far? */
99391diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99392index 77bd16f..5f7174a 100644
99393--- a/net/ipv4/udp.c
99394+++ b/net/ipv4/udp.c
99395@@ -87,6 +87,7 @@
99396 #include <linux/types.h>
99397 #include <linux/fcntl.h>
99398 #include <linux/module.h>
99399+#include <linux/security.h>
99400 #include <linux/socket.h>
99401 #include <linux/sockios.h>
99402 #include <linux/igmp.h>
99403@@ -113,6 +114,10 @@
99404 #include <net/busy_poll.h>
99405 #include "udp_impl.h"
99406
99407+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99408+extern int grsec_enable_blackhole;
99409+#endif
99410+
99411 struct udp_table udp_table __read_mostly;
99412 EXPORT_SYMBOL(udp_table);
99413
99414@@ -615,6 +620,9 @@ found:
99415 return s;
99416 }
99417
99418+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99419+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99420+
99421 /*
99422 * This routine is called by the ICMP module when it gets some
99423 * sort of error condition. If err < 0 then the socket should
99424@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99425 dport = usin->sin_port;
99426 if (dport == 0)
99427 return -EINVAL;
99428+
99429+ err = gr_search_udp_sendmsg(sk, usin);
99430+ if (err)
99431+ return err;
99432 } else {
99433 if (sk->sk_state != TCP_ESTABLISHED)
99434 return -EDESTADDRREQ;
99435+
99436+ err = gr_search_udp_sendmsg(sk, NULL);
99437+ if (err)
99438+ return err;
99439+
99440 daddr = inet->inet_daddr;
99441 dport = inet->inet_dport;
99442 /* Open fast path for connected socket.
99443@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
99444 IS_UDPLITE(sk));
99445 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99446 IS_UDPLITE(sk));
99447- atomic_inc(&sk->sk_drops);
99448+ atomic_inc_unchecked(&sk->sk_drops);
99449 __skb_unlink(skb, rcvq);
99450 __skb_queue_tail(&list_kill, skb);
99451 }
99452@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99453 int is_udplite = IS_UDPLITE(sk);
99454 bool slow;
99455
99456+ /*
99457+ * Check any passed addresses
99458+ */
99459+ if (addr_len)
99460+ *addr_len = sizeof(*sin);
99461+
99462 if (flags & MSG_ERRQUEUE)
99463 return ip_recv_error(sk, msg, len, addr_len);
99464
99465@@ -1243,6 +1266,10 @@ try_again:
99466 if (!skb)
99467 goto out;
99468
99469+ err = gr_search_udp_recvmsg(sk, skb);
99470+ if (err)
99471+ goto out_free;
99472+
99473 ulen = skb->len - sizeof(struct udphdr);
99474 copied = len;
99475 if (copied > ulen)
99476@@ -1276,7 +1303,7 @@ try_again:
99477 if (unlikely(err)) {
99478 trace_kfree_skb(skb, udp_recvmsg);
99479 if (!peeked) {
99480- atomic_inc(&sk->sk_drops);
99481+ atomic_inc_unchecked(&sk->sk_drops);
99482 UDP_INC_STATS_USER(sock_net(sk),
99483 UDP_MIB_INERRORS, is_udplite);
99484 }
99485@@ -1295,7 +1322,6 @@ try_again:
99486 sin->sin_port = udp_hdr(skb)->source;
99487 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99488 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99489- *addr_len = sizeof(*sin);
99490 }
99491 if (inet->cmsg_flags)
99492 ip_cmsg_recv(msg, skb);
99493@@ -1566,7 +1592,7 @@ csum_error:
99494 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99495 drop:
99496 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99497- atomic_inc(&sk->sk_drops);
99498+ atomic_inc_unchecked(&sk->sk_drops);
99499 kfree_skb(skb);
99500 return -1;
99501 }
99502@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99503 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99504
99505 if (!skb1) {
99506- atomic_inc(&sk->sk_drops);
99507+ atomic_inc_unchecked(&sk->sk_drops);
99508 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99509 IS_UDPLITE(sk));
99510 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99511@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99512 goto csum_error;
99513
99514 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99515+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99516+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99517+#endif
99518 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
99519
99520 /*
99521@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
99522 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99523 0, sock_i_ino(sp),
99524 atomic_read(&sp->sk_refcnt), sp,
99525- atomic_read(&sp->sk_drops));
99526+ atomic_read_unchecked(&sp->sk_drops));
99527 }
99528
99529 int udp4_seq_show(struct seq_file *seq, void *v)
99530diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99531index e1a6393..f634ce5 100644
99532--- a/net/ipv4/xfrm4_policy.c
99533+++ b/net/ipv4/xfrm4_policy.c
99534@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99535 fl4->flowi4_tos = iph->tos;
99536 }
99537
99538-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99539+static int xfrm4_garbage_collect(struct dst_ops *ops)
99540 {
99541 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99542
99543- xfrm4_policy_afinfo.garbage_collect(net);
99544+ xfrm_garbage_collect_deferred(net);
99545 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99546 }
99547
99548@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99549
99550 static int __net_init xfrm4_net_init(struct net *net)
99551 {
99552- struct ctl_table *table;
99553+ ctl_table_no_const *table = NULL;
99554 struct ctl_table_header *hdr;
99555
99556- table = xfrm4_policy_table;
99557 if (!net_eq(net, &init_net)) {
99558- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99559+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99560 if (!table)
99561 goto err_alloc;
99562
99563 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99564- }
99565-
99566- hdr = register_net_sysctl(net, "net/ipv4", table);
99567+ hdr = register_net_sysctl(net, "net/ipv4", table);
99568+ } else
99569+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99570 if (!hdr)
99571 goto err_reg;
99572
99573@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
99574 return 0;
99575
99576 err_reg:
99577- if (!net_eq(net, &init_net))
99578- kfree(table);
99579+ kfree(table);
99580 err_alloc:
99581 return -ENOMEM;
99582 }
99583diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99584index 6c7fa08..285086c 100644
99585--- a/net/ipv6/addrconf.c
99586+++ b/net/ipv6/addrconf.c
99587@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99588 idx = 0;
99589 head = &net->dev_index_head[h];
99590 rcu_read_lock();
99591- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99592+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99593 net->dev_base_seq;
99594 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99595 if (idx < s_idx)
99596@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
99597 p.iph.ihl = 5;
99598 p.iph.protocol = IPPROTO_IPV6;
99599 p.iph.ttl = 64;
99600- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
99601+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
99602
99603 if (ops->ndo_do_ioctl) {
99604 mm_segment_t oldfs = get_fs();
99605@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
99606 s_ip_idx = ip_idx = cb->args[2];
99607
99608 rcu_read_lock();
99609- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99610+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99611 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
99612 idx = 0;
99613 head = &net->dev_index_head[h];
99614@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
99615 dst_free(&ifp->rt->dst);
99616 break;
99617 }
99618- atomic_inc(&net->ipv6.dev_addr_genid);
99619+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
99620 rt_genid_bump_ipv6(net);
99621 }
99622
99623@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
99624 int *valp = ctl->data;
99625 int val = *valp;
99626 loff_t pos = *ppos;
99627- struct ctl_table lctl;
99628+ ctl_table_no_const lctl;
99629 int ret;
99630
99631 /*
99632@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
99633 int *valp = ctl->data;
99634 int val = *valp;
99635 loff_t pos = *ppos;
99636- struct ctl_table lctl;
99637+ ctl_table_no_const lctl;
99638 int ret;
99639
99640 /*
99641diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
99642index d935889..2f64330 100644
99643--- a/net/ipv6/af_inet6.c
99644+++ b/net/ipv6/af_inet6.c
99645@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
99646 net->ipv6.sysctl.bindv6only = 0;
99647 net->ipv6.sysctl.icmpv6_time = 1*HZ;
99648 net->ipv6.sysctl.flowlabel_consistency = 1;
99649- atomic_set(&net->ipv6.rt_genid, 0);
99650+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
99651
99652 err = ipv6_init_mibs(net);
99653 if (err)
99654diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
99655index c3bf2d2..1f00573 100644
99656--- a/net/ipv6/datagram.c
99657+++ b/net/ipv6/datagram.c
99658@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
99659 0,
99660 sock_i_ino(sp),
99661 atomic_read(&sp->sk_refcnt), sp,
99662- atomic_read(&sp->sk_drops));
99663+ atomic_read_unchecked(&sp->sk_drops));
99664 }
99665diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
99666index 7b32652..0bc348b 100644
99667--- a/net/ipv6/icmp.c
99668+++ b/net/ipv6/icmp.c
99669@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
99670
99671 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
99672 {
99673- struct ctl_table *table;
99674+ ctl_table_no_const *table;
99675
99676 table = kmemdup(ipv6_icmp_table_template,
99677 sizeof(ipv6_icmp_table_template),
99678diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
99679index f3ffb43..1172ba7 100644
99680--- a/net/ipv6/ip6_gre.c
99681+++ b/net/ipv6/ip6_gre.c
99682@@ -71,7 +71,7 @@ struct ip6gre_net {
99683 struct net_device *fb_tunnel_dev;
99684 };
99685
99686-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
99687+static struct rtnl_link_ops ip6gre_link_ops;
99688 static int ip6gre_tunnel_init(struct net_device *dev);
99689 static void ip6gre_tunnel_setup(struct net_device *dev);
99690 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
99691@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
99692 }
99693
99694
99695-static struct inet6_protocol ip6gre_protocol __read_mostly = {
99696+static struct inet6_protocol ip6gre_protocol = {
99697 .handler = ip6gre_rcv,
99698 .err_handler = ip6gre_err,
99699 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
99700@@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
99701 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
99702 };
99703
99704-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99705+static struct rtnl_link_ops ip6gre_link_ops = {
99706 .kind = "ip6gre",
99707 .maxtype = IFLA_GRE_MAX,
99708 .policy = ip6gre_policy,
99709@@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99710 .fill_info = ip6gre_fill_info,
99711 };
99712
99713-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
99714+static struct rtnl_link_ops ip6gre_tap_ops = {
99715 .kind = "ip6gretap",
99716 .maxtype = IFLA_GRE_MAX,
99717 .policy = ip6gre_policy,
99718diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
99719index 5db8d31..4a72c26 100644
99720--- a/net/ipv6/ip6_tunnel.c
99721+++ b/net/ipv6/ip6_tunnel.c
99722@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99723
99724 static int ip6_tnl_dev_init(struct net_device *dev);
99725 static void ip6_tnl_dev_setup(struct net_device *dev);
99726-static struct rtnl_link_ops ip6_link_ops __read_mostly;
99727+static struct rtnl_link_ops ip6_link_ops;
99728
99729 static int ip6_tnl_net_id __read_mostly;
99730 struct ip6_tnl_net {
99731@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
99732 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
99733 };
99734
99735-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
99736+static struct rtnl_link_ops ip6_link_ops = {
99737 .kind = "ip6tnl",
99738 .maxtype = IFLA_IPTUN_MAX,
99739 .policy = ip6_tnl_policy,
99740diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
99741index 2d19272..3a46322 100644
99742--- a/net/ipv6/ip6_vti.c
99743+++ b/net/ipv6/ip6_vti.c
99744@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99745
99746 static int vti6_dev_init(struct net_device *dev);
99747 static void vti6_dev_setup(struct net_device *dev);
99748-static struct rtnl_link_ops vti6_link_ops __read_mostly;
99749+static struct rtnl_link_ops vti6_link_ops;
99750
99751 static int vti6_net_id __read_mostly;
99752 struct vti6_net {
99753@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
99754 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
99755 };
99756
99757-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
99758+static struct rtnl_link_ops vti6_link_ops = {
99759 .kind = "vti6",
99760 .maxtype = IFLA_VTI_MAX,
99761 .policy = vti6_policy,
99762diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99763index 0a00f44..bec42b2 100644
99764--- a/net/ipv6/ipv6_sockglue.c
99765+++ b/net/ipv6/ipv6_sockglue.c
99766@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99767 if (sk->sk_type != SOCK_STREAM)
99768 return -ENOPROTOOPT;
99769
99770- msg.msg_control = optval;
99771+ msg.msg_control = (void __force_kernel *)optval;
99772 msg.msg_controllen = len;
99773 msg.msg_flags = flags;
99774
99775diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99776index 710238f..0fd1816 100644
99777--- a/net/ipv6/netfilter/ip6_tables.c
99778+++ b/net/ipv6/netfilter/ip6_tables.c
99779@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99780 #endif
99781
99782 static int get_info(struct net *net, void __user *user,
99783- const int *len, int compat)
99784+ int len, int compat)
99785 {
99786 char name[XT_TABLE_MAXNAMELEN];
99787 struct xt_table *t;
99788 int ret;
99789
99790- if (*len != sizeof(struct ip6t_getinfo)) {
99791- duprintf("length %u != %zu\n", *len,
99792+ if (len != sizeof(struct ip6t_getinfo)) {
99793+ duprintf("length %u != %zu\n", len,
99794 sizeof(struct ip6t_getinfo));
99795 return -EINVAL;
99796 }
99797@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99798 info.size = private->size;
99799 strcpy(info.name, name);
99800
99801- if (copy_to_user(user, &info, *len) != 0)
99802+ if (copy_to_user(user, &info, len) != 0)
99803 ret = -EFAULT;
99804 else
99805 ret = 0;
99806@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99807
99808 switch (cmd) {
99809 case IP6T_SO_GET_INFO:
99810- ret = get_info(sock_net(sk), user, len, 1);
99811+ ret = get_info(sock_net(sk), user, *len, 1);
99812 break;
99813 case IP6T_SO_GET_ENTRIES:
99814 ret = compat_get_entries(sock_net(sk), user, len);
99815@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99816
99817 switch (cmd) {
99818 case IP6T_SO_GET_INFO:
99819- ret = get_info(sock_net(sk), user, len, 0);
99820+ ret = get_info(sock_net(sk), user, *len, 0);
99821 break;
99822
99823 case IP6T_SO_GET_ENTRIES:
99824diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99825index 767ab8d..c5ec70a 100644
99826--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99827+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99828@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99829
99830 static int nf_ct_frag6_sysctl_register(struct net *net)
99831 {
99832- struct ctl_table *table;
99833+ ctl_table_no_const *table = NULL;
99834 struct ctl_table_header *hdr;
99835
99836- table = nf_ct_frag6_sysctl_table;
99837 if (!net_eq(net, &init_net)) {
99838- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99839+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99840 GFP_KERNEL);
99841 if (table == NULL)
99842 goto err_alloc;
99843@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99844 table[0].data = &net->nf_frag.frags.timeout;
99845 table[1].data = &net->nf_frag.frags.low_thresh;
99846 table[2].data = &net->nf_frag.frags.high_thresh;
99847- }
99848-
99849- hdr = register_net_sysctl(net, "net/netfilter", table);
99850+ hdr = register_net_sysctl(net, "net/netfilter", table);
99851+ } else
99852+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99853 if (hdr == NULL)
99854 goto err_reg;
99855
99856@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99857 return 0;
99858
99859 err_reg:
99860- if (!net_eq(net, &init_net))
99861- kfree(table);
99862+ kfree(table);
99863 err_alloc:
99864 return -ENOMEM;
99865 }
99866diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99867index 827f795..7e28e82 100644
99868--- a/net/ipv6/output_core.c
99869+++ b/net/ipv6/output_core.c
99870@@ -9,8 +9,8 @@
99871
99872 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99873 {
99874- static atomic_t ipv6_fragmentation_id;
99875- int old, new;
99876+ static atomic_unchecked_t ipv6_fragmentation_id;
99877+ int id;
99878
99879 #if IS_ENABLED(CONFIG_IPV6)
99880 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99881@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99882 }
99883 }
99884 #endif
99885- do {
99886- old = atomic_read(&ipv6_fragmentation_id);
99887- new = old + 1;
99888- if (!new)
99889- new = 1;
99890- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99891- fhdr->identification = htonl(new);
99892+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99893+ if (!id)
99894+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99895+ fhdr->identification = htonl(id);
99896 }
99897 EXPORT_SYMBOL(ipv6_select_ident);
99898
99899diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99900index bda7429..469b26b 100644
99901--- a/net/ipv6/ping.c
99902+++ b/net/ipv6/ping.c
99903@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
99904 };
99905 #endif
99906
99907+static struct pingv6_ops real_pingv6_ops = {
99908+ .ipv6_recv_error = ipv6_recv_error,
99909+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
99910+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
99911+ .icmpv6_err_convert = icmpv6_err_convert,
99912+ .ipv6_icmp_error = ipv6_icmp_error,
99913+ .ipv6_chk_addr = ipv6_chk_addr,
99914+};
99915+
99916+static struct pingv6_ops dummy_pingv6_ops = {
99917+ .ipv6_recv_error = dummy_ipv6_recv_error,
99918+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
99919+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
99920+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
99921+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
99922+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
99923+};
99924+
99925 int __init pingv6_init(void)
99926 {
99927 #ifdef CONFIG_PROC_FS
99928@@ -253,13 +271,7 @@ int __init pingv6_init(void)
99929 if (ret)
99930 return ret;
99931 #endif
99932- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99933- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
99934- pingv6_ops.ip6_datagram_recv_specific_ctl =
99935- ip6_datagram_recv_specific_ctl;
99936- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99937- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99938- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99939+ pingv6_ops = &real_pingv6_ops;
99940 return inet6_register_protosw(&pingv6_protosw);
99941 }
99942
99943@@ -268,14 +280,9 @@ int __init pingv6_init(void)
99944 */
99945 void pingv6_exit(void)
99946 {
99947- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99948- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
99949- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
99950- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99951- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99952- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99953 #ifdef CONFIG_PROC_FS
99954 unregister_pernet_subsys(&ping_v6_net_ops);
99955 #endif
99956+ pingv6_ops = &dummy_pingv6_ops;
99957 inet6_unregister_protosw(&pingv6_protosw);
99958 }
99959diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
99960index 091d066..139d410 100644
99961--- a/net/ipv6/proc.c
99962+++ b/net/ipv6/proc.c
99963@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
99964 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
99965 goto proc_snmp6_fail;
99966
99967- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
99968+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
99969 if (!net->mib.proc_net_devsnmp6)
99970 goto proc_dev_snmp6_fail;
99971 return 0;
99972diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99973index 1f29996..46fe0c7 100644
99974--- a/net/ipv6/raw.c
99975+++ b/net/ipv6/raw.c
99976@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99977 {
99978 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99979 skb_checksum_complete(skb)) {
99980- atomic_inc(&sk->sk_drops);
99981+ atomic_inc_unchecked(&sk->sk_drops);
99982 kfree_skb(skb);
99983 return NET_RX_DROP;
99984 }
99985@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99986 struct raw6_sock *rp = raw6_sk(sk);
99987
99988 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99989- atomic_inc(&sk->sk_drops);
99990+ atomic_inc_unchecked(&sk->sk_drops);
99991 kfree_skb(skb);
99992 return NET_RX_DROP;
99993 }
99994@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99995
99996 if (inet->hdrincl) {
99997 if (skb_checksum_complete(skb)) {
99998- atomic_inc(&sk->sk_drops);
99999+ atomic_inc_unchecked(&sk->sk_drops);
100000 kfree_skb(skb);
100001 return NET_RX_DROP;
100002 }
100003@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100004 if (flags & MSG_OOB)
100005 return -EOPNOTSUPP;
100006
100007+ if (addr_len)
100008+ *addr_len=sizeof(*sin6);
100009+
100010 if (flags & MSG_ERRQUEUE)
100011 return ipv6_recv_error(sk, msg, len, addr_len);
100012
100013@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100014 sin6->sin6_flowinfo = 0;
100015 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100016 IP6CB(skb)->iif);
100017- *addr_len = sizeof(*sin6);
100018 }
100019
100020 sock_recv_ts_and_drops(msg, sk, skb);
100021@@ -610,7 +612,7 @@ out:
100022 return err;
100023 }
100024
100025-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100026+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100027 struct flowi6 *fl6, struct dst_entry **dstp,
100028 unsigned int flags)
100029 {
100030@@ -922,12 +924,15 @@ do_confirm:
100031 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100032 char __user *optval, int optlen)
100033 {
100034+ struct icmp6_filter filter;
100035+
100036 switch (optname) {
100037 case ICMPV6_FILTER:
100038 if (optlen > sizeof(struct icmp6_filter))
100039 optlen = sizeof(struct icmp6_filter);
100040- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100041+ if (copy_from_user(&filter, optval, optlen))
100042 return -EFAULT;
100043+ raw6_sk(sk)->filter = filter;
100044 return 0;
100045 default:
100046 return -ENOPROTOOPT;
100047@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100048 char __user *optval, int __user *optlen)
100049 {
100050 int len;
100051+ struct icmp6_filter filter;
100052
100053 switch (optname) {
100054 case ICMPV6_FILTER:
100055@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100056 len = sizeof(struct icmp6_filter);
100057 if (put_user(len, optlen))
100058 return -EFAULT;
100059- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100060+ filter = raw6_sk(sk)->filter;
100061+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100062 return -EFAULT;
100063 return 0;
100064 default:
100065diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100066index cc85a9b..526a133 100644
100067--- a/net/ipv6/reassembly.c
100068+++ b/net/ipv6/reassembly.c
100069@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100070
100071 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100072 {
100073- struct ctl_table *table;
100074+ ctl_table_no_const *table = NULL;
100075 struct ctl_table_header *hdr;
100076
100077- table = ip6_frags_ns_ctl_table;
100078 if (!net_eq(net, &init_net)) {
100079- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100080+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100081 if (table == NULL)
100082 goto err_alloc;
100083
100084@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100085 /* Don't export sysctls to unprivileged users */
100086 if (net->user_ns != &init_user_ns)
100087 table[0].procname = NULL;
100088- }
100089+ hdr = register_net_sysctl(net, "net/ipv6", table);
100090+ } else
100091+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100092
100093- hdr = register_net_sysctl(net, "net/ipv6", table);
100094 if (hdr == NULL)
100095 goto err_reg;
100096
100097@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100098 return 0;
100099
100100 err_reg:
100101- if (!net_eq(net, &init_net))
100102- kfree(table);
100103+ kfree(table);
100104 err_alloc:
100105 return -ENOMEM;
100106 }
100107diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100108index fba54a4..73e374e 100644
100109--- a/net/ipv6/route.c
100110+++ b/net/ipv6/route.c
100111@@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
100112
100113 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100114 {
100115- struct ctl_table *table;
100116+ ctl_table_no_const *table;
100117
100118 table = kmemdup(ipv6_route_table_template,
100119 sizeof(ipv6_route_table_template),
100120diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100121index b4d74c8..b4f3fbe 100644
100122--- a/net/ipv6/sit.c
100123+++ b/net/ipv6/sit.c
100124@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100125 static void ipip6_dev_free(struct net_device *dev);
100126 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100127 __be32 *v4dst);
100128-static struct rtnl_link_ops sit_link_ops __read_mostly;
100129+static struct rtnl_link_ops sit_link_ops;
100130
100131 static int sit_net_id __read_mostly;
100132 struct sit_net {
100133@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100134 unregister_netdevice_queue(dev, head);
100135 }
100136
100137-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100138+static struct rtnl_link_ops sit_link_ops = {
100139 .kind = "sit",
100140 .maxtype = IFLA_IPTUN_MAX,
100141 .policy = ipip6_policy,
100142diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100143index 7f405a1..eabef92 100644
100144--- a/net/ipv6/sysctl_net_ipv6.c
100145+++ b/net/ipv6/sysctl_net_ipv6.c
100146@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100147
100148 static int __net_init ipv6_sysctl_net_init(struct net *net)
100149 {
100150- struct ctl_table *ipv6_table;
100151+ ctl_table_no_const *ipv6_table;
100152 struct ctl_table *ipv6_route_table;
100153 struct ctl_table *ipv6_icmp_table;
100154 int err;
100155diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100156index 889079b..a04512c 100644
100157--- a/net/ipv6/tcp_ipv6.c
100158+++ b/net/ipv6/tcp_ipv6.c
100159@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100160 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100161 }
100162
100163+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100164+extern int grsec_enable_blackhole;
100165+#endif
100166+
100167 static void tcp_v6_hash(struct sock *sk)
100168 {
100169 if (sk->sk_state != TCP_CLOSE) {
100170@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100171 return 0;
100172
100173 reset:
100174+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100175+ if (!grsec_enable_blackhole)
100176+#endif
100177 tcp_v6_send_reset(sk, skb);
100178 discard:
100179 if (opt_skb)
100180@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100181 TCP_SKB_CB(skb)->sacked = 0;
100182
100183 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100184- if (!sk)
100185+ if (!sk) {
100186+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100187+ ret = 1;
100188+#endif
100189 goto no_tcp_socket;
100190+ }
100191
100192 process:
100193- if (sk->sk_state == TCP_TIME_WAIT)
100194+ if (sk->sk_state == TCP_TIME_WAIT) {
100195+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100196+ ret = 2;
100197+#endif
100198 goto do_time_wait;
100199+ }
100200
100201 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100202 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100203@@ -1553,6 +1568,10 @@ csum_error:
100204 bad_packet:
100205 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100206 } else {
100207+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100208+ if (!grsec_enable_blackhole || (ret == 1 &&
100209+ (skb->dev->flags & IFF_LOOPBACK)))
100210+#endif
100211 tcp_v6_send_reset(NULL, skb);
100212 }
100213
100214diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100215index 1e586d9..384a9c9 100644
100216--- a/net/ipv6/udp.c
100217+++ b/net/ipv6/udp.c
100218@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100219 udp_ipv6_hash_secret + net_hash_mix(net));
100220 }
100221
100222+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100223+extern int grsec_enable_blackhole;
100224+#endif
100225+
100226 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100227 {
100228 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100229@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100230 int is_udp4;
100231 bool slow;
100232
100233+ if (addr_len)
100234+ *addr_len = sizeof(struct sockaddr_in6);
100235+
100236 if (flags & MSG_ERRQUEUE)
100237 return ipv6_recv_error(sk, msg, len, addr_len);
100238
100239@@ -435,7 +442,7 @@ try_again:
100240 if (unlikely(err)) {
100241 trace_kfree_skb(skb, udpv6_recvmsg);
100242 if (!peeked) {
100243- atomic_inc(&sk->sk_drops);
100244+ atomic_inc_unchecked(&sk->sk_drops);
100245 if (is_udp4)
100246 UDP_INC_STATS_USER(sock_net(sk),
100247 UDP_MIB_INERRORS,
100248@@ -475,7 +482,7 @@ try_again:
100249 ipv6_iface_scope_id(&sin6->sin6_addr,
100250 IP6CB(skb)->iif);
100251 }
100252- *addr_len = sizeof(*sin6);
100253+
100254 }
100255
100256 if (np->rxopt.all)
100257@@ -690,7 +697,7 @@ csum_error:
100258 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100259 drop:
100260 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100261- atomic_inc(&sk->sk_drops);
100262+ atomic_inc_unchecked(&sk->sk_drops);
100263 kfree_skb(skb);
100264 return -1;
100265 }
100266@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100267 if (likely(skb1 == NULL))
100268 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100269 if (!skb1) {
100270- atomic_inc(&sk->sk_drops);
100271+ atomic_inc_unchecked(&sk->sk_drops);
100272 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100273 IS_UDPLITE(sk));
100274 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100275@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100276 goto csum_error;
100277
100278 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100279+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100280+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100281+#endif
100282 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100283
100284 kfree_skb(skb);
100285diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100286index 5f8e128..865d38e 100644
100287--- a/net/ipv6/xfrm6_policy.c
100288+++ b/net/ipv6/xfrm6_policy.c
100289@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100290 }
100291 }
100292
100293-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100294+static int xfrm6_garbage_collect(struct dst_ops *ops)
100295 {
100296 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100297
100298- xfrm6_policy_afinfo.garbage_collect(net);
100299+ xfrm_garbage_collect_deferred(net);
100300 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100301 }
100302
100303@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100304
100305 static int __net_init xfrm6_net_init(struct net *net)
100306 {
100307- struct ctl_table *table;
100308+ ctl_table_no_const *table = NULL;
100309 struct ctl_table_header *hdr;
100310
100311- table = xfrm6_policy_table;
100312 if (!net_eq(net, &init_net)) {
100313- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100314+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100315 if (!table)
100316 goto err_alloc;
100317
100318 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100319- }
100320+ hdr = register_net_sysctl(net, "net/ipv6", table);
100321+ } else
100322+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100323
100324- hdr = register_net_sysctl(net, "net/ipv6", table);
100325 if (!hdr)
100326 goto err_reg;
100327
100328@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100329 return 0;
100330
100331 err_reg:
100332- if (!net_eq(net, &init_net))
100333- kfree(table);
100334+ kfree(table);
100335 err_alloc:
100336 return -ENOMEM;
100337 }
100338diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100339index e15c16a..7cf07aa 100644
100340--- a/net/ipx/ipx_proc.c
100341+++ b/net/ipx/ipx_proc.c
100342@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100343 struct proc_dir_entry *p;
100344 int rc = -ENOMEM;
100345
100346- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100347+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100348
100349 if (!ipx_proc_dir)
100350 goto out;
100351diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100352index 2ba8b97..6d33010 100644
100353--- a/net/irda/ircomm/ircomm_tty.c
100354+++ b/net/irda/ircomm/ircomm_tty.c
100355@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100356 add_wait_queue(&port->open_wait, &wait);
100357
100358 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100359- __FILE__, __LINE__, tty->driver->name, port->count);
100360+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100361
100362 spin_lock_irqsave(&port->lock, flags);
100363 if (!tty_hung_up_p(filp))
100364- port->count--;
100365+ atomic_dec(&port->count);
100366 port->blocked_open++;
100367 spin_unlock_irqrestore(&port->lock, flags);
100368
100369@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100370 }
100371
100372 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100373- __FILE__, __LINE__, tty->driver->name, port->count);
100374+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100375
100376 schedule();
100377 }
100378@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100379
100380 spin_lock_irqsave(&port->lock, flags);
100381 if (!tty_hung_up_p(filp))
100382- port->count++;
100383+ atomic_inc(&port->count);
100384 port->blocked_open--;
100385 spin_unlock_irqrestore(&port->lock, flags);
100386
100387 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100388- __FILE__, __LINE__, tty->driver->name, port->count);
100389+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100390
100391 if (!retval)
100392 port->flags |= ASYNC_NORMAL_ACTIVE;
100393@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100394
100395 /* ++ is not atomic, so this should be protected - Jean II */
100396 spin_lock_irqsave(&self->port.lock, flags);
100397- self->port.count++;
100398+ atomic_inc(&self->port.count);
100399 spin_unlock_irqrestore(&self->port.lock, flags);
100400 tty_port_tty_set(&self->port, tty);
100401
100402 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100403- self->line, self->port.count);
100404+ self->line, atomic_read(&self->port.count));
100405
100406 /* Not really used by us, but lets do it anyway */
100407 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100408@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100409 tty_kref_put(port->tty);
100410 }
100411 port->tty = NULL;
100412- port->count = 0;
100413+ atomic_set(&port->count, 0);
100414 spin_unlock_irqrestore(&port->lock, flags);
100415
100416 wake_up_interruptible(&port->open_wait);
100417@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100418 seq_putc(m, '\n');
100419
100420 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100421- seq_printf(m, "Open count: %d\n", self->port.count);
100422+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100423 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100424 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100425
100426diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100427index b9ac598..f88cc56 100644
100428--- a/net/irda/irproc.c
100429+++ b/net/irda/irproc.c
100430@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100431 {
100432 int i;
100433
100434- proc_irda = proc_mkdir("irda", init_net.proc_net);
100435+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100436 if (proc_irda == NULL)
100437 return;
100438
100439diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100440index c4b7218..3e83259 100644
100441--- a/net/iucv/af_iucv.c
100442+++ b/net/iucv/af_iucv.c
100443@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100444
100445 write_lock_bh(&iucv_sk_list.lock);
100446
100447- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100448+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100449 while (__iucv_get_sock_by_name(name)) {
100450 sprintf(name, "%08x",
100451- atomic_inc_return(&iucv_sk_list.autobind_name));
100452+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100453 }
100454
100455 write_unlock_bh(&iucv_sk_list.lock);
100456diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
100457index cd5b8ec..f205e6b 100644
100458--- a/net/iucv/iucv.c
100459+++ b/net/iucv/iucv.c
100460@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
100461 return NOTIFY_OK;
100462 }
100463
100464-static struct notifier_block __refdata iucv_cpu_notifier = {
100465+static struct notifier_block iucv_cpu_notifier = {
100466 .notifier_call = iucv_cpu_notify,
100467 };
100468
100469diff --git a/net/key/af_key.c b/net/key/af_key.c
100470index 7932697..a13d158 100644
100471--- a/net/key/af_key.c
100472+++ b/net/key/af_key.c
100473@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
100474 static u32 get_acqseq(void)
100475 {
100476 u32 res;
100477- static atomic_t acqseq;
100478+ static atomic_unchecked_t acqseq;
100479
100480 do {
100481- res = atomic_inc_return(&acqseq);
100482+ res = atomic_inc_return_unchecked(&acqseq);
100483 } while (!res);
100484 return res;
100485 }
100486diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
100487index 0b44d85..1a7f88b 100644
100488--- a/net/l2tp/l2tp_ip.c
100489+++ b/net/l2tp/l2tp_ip.c
100490@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100491 if (flags & MSG_OOB)
100492 goto out;
100493
100494+ if (addr_len)
100495+ *addr_len = sizeof(*sin);
100496+
100497 skb = skb_recv_datagram(sk, flags, noblock, &err);
100498 if (!skb)
100499 goto out;
100500@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100501 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100502 sin->sin_port = 0;
100503 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100504- *addr_len = sizeof(*sin);
100505 }
100506 if (inet->cmsg_flags)
100507 ip_cmsg_recv(msg, skb);
100508diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
100509index 1a3c7e0..80f8b0c 100644
100510--- a/net/llc/llc_proc.c
100511+++ b/net/llc/llc_proc.c
100512@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
100513 int rc = -ENOMEM;
100514 struct proc_dir_entry *p;
100515
100516- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
100517+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
100518 if (!llc_proc_dir)
100519 goto out;
100520
100521diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
100522index 453e974..b3a43a5 100644
100523--- a/net/mac80211/cfg.c
100524+++ b/net/mac80211/cfg.c
100525@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
100526 ret = ieee80211_vif_use_channel(sdata, chandef,
100527 IEEE80211_CHANCTX_EXCLUSIVE);
100528 }
100529- } else if (local->open_count == local->monitors) {
100530+ } else if (local_read(&local->open_count) == local->monitors) {
100531 local->_oper_chandef = *chandef;
100532 ieee80211_hw_config(local, 0);
100533 }
100534@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
100535 else
100536 local->probe_req_reg--;
100537
100538- if (!local->open_count)
100539+ if (!local_read(&local->open_count))
100540 break;
100541
100542 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
100543@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
100544 if (chanctx_conf) {
100545 *chandef = chanctx_conf->def;
100546 ret = 0;
100547- } else if (local->open_count > 0 &&
100548- local->open_count == local->monitors &&
100549+ } else if (local_read(&local->open_count) > 0 &&
100550+ local_read(&local->open_count) == local->monitors &&
100551 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
100552 if (local->use_chanctx)
100553 *chandef = local->monitor_chandef;
100554diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
100555index 5e44e317..3d404a6 100644
100556--- a/net/mac80211/ieee80211_i.h
100557+++ b/net/mac80211/ieee80211_i.h
100558@@ -28,6 +28,7 @@
100559 #include <net/ieee80211_radiotap.h>
100560 #include <net/cfg80211.h>
100561 #include <net/mac80211.h>
100562+#include <asm/local.h>
100563 #include "key.h"
100564 #include "sta_info.h"
100565 #include "debug.h"
100566@@ -994,7 +995,7 @@ struct ieee80211_local {
100567 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
100568 spinlock_t queue_stop_reason_lock;
100569
100570- int open_count;
100571+ local_t open_count;
100572 int monitors, cooked_mntrs;
100573 /* number of interfaces with corresponding FIF_ flags */
100574 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
100575diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
100576index ce1c443..6cd39e1 100644
100577--- a/net/mac80211/iface.c
100578+++ b/net/mac80211/iface.c
100579@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100580 break;
100581 }
100582
100583- if (local->open_count == 0) {
100584+ if (local_read(&local->open_count) == 0) {
100585 res = drv_start(local);
100586 if (res)
100587 goto err_del_bss;
100588@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100589 res = drv_add_interface(local, sdata);
100590 if (res)
100591 goto err_stop;
100592- } else if (local->monitors == 0 && local->open_count == 0) {
100593+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
100594 res = ieee80211_add_virtual_monitor(local);
100595 if (res)
100596 goto err_stop;
100597@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100598 atomic_inc(&local->iff_promiscs);
100599
100600 if (coming_up)
100601- local->open_count++;
100602+ local_inc(&local->open_count);
100603
100604 if (hw_reconf_flags)
100605 ieee80211_hw_config(local, hw_reconf_flags);
100606@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100607 err_del_interface:
100608 drv_remove_interface(local, sdata);
100609 err_stop:
100610- if (!local->open_count)
100611+ if (!local_read(&local->open_count))
100612 drv_stop(local);
100613 err_del_bss:
100614 sdata->bss = NULL;
100615@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100616 }
100617
100618 if (going_down)
100619- local->open_count--;
100620+ local_dec(&local->open_count);
100621
100622 switch (sdata->vif.type) {
100623 case NL80211_IFTYPE_AP_VLAN:
100624@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100625 }
100626 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
100627
100628- if (local->open_count == 0)
100629+ if (local_read(&local->open_count) == 0)
100630 ieee80211_clear_tx_pending(local);
100631
100632 /*
100633@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100634
100635 ieee80211_recalc_ps(local, -1);
100636
100637- if (local->open_count == 0) {
100638+ if (local_read(&local->open_count) == 0) {
100639 ieee80211_stop_device(local);
100640
100641 /* no reconfiguring after stop! */
100642@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100643 ieee80211_configure_filter(local);
100644 ieee80211_hw_config(local, hw_reconf_flags);
100645
100646- if (local->monitors == local->open_count)
100647+ if (local->monitors == local_read(&local->open_count))
100648 ieee80211_add_virtual_monitor(local);
100649 }
100650
100651diff --git a/net/mac80211/main.c b/net/mac80211/main.c
100652index d767cfb..b4cd07d 100644
100653--- a/net/mac80211/main.c
100654+++ b/net/mac80211/main.c
100655@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
100656 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
100657 IEEE80211_CONF_CHANGE_POWER);
100658
100659- if (changed && local->open_count) {
100660+ if (changed && local_read(&local->open_count)) {
100661 ret = drv_config(local, changed);
100662 /*
100663 * Goal:
100664diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
100665index af64fb8..366e371 100644
100666--- a/net/mac80211/pm.c
100667+++ b/net/mac80211/pm.c
100668@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100669 struct ieee80211_sub_if_data *sdata;
100670 struct sta_info *sta;
100671
100672- if (!local->open_count)
100673+ if (!local_read(&local->open_count))
100674 goto suspend;
100675
100676 ieee80211_scan_cancel(local);
100677@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100678 cancel_work_sync(&local->dynamic_ps_enable_work);
100679 del_timer_sync(&local->dynamic_ps_timer);
100680
100681- local->wowlan = wowlan && local->open_count;
100682+ local->wowlan = wowlan && local_read(&local->open_count);
100683 if (local->wowlan) {
100684 int err = drv_suspend(local, wowlan);
100685 if (err < 0) {
100686@@ -115,7 +115,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100687 WARN_ON(!list_empty(&local->chanctx_list));
100688
100689 /* stop hardware - this must stop RX */
100690- if (local->open_count)
100691+ if (local_read(&local->open_count))
100692 ieee80211_stop_device(local);
100693
100694 suspend:
100695diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
100696index 22b223f..ab70070 100644
100697--- a/net/mac80211/rate.c
100698+++ b/net/mac80211/rate.c
100699@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
100700
100701 ASSERT_RTNL();
100702
100703- if (local->open_count)
100704+ if (local_read(&local->open_count))
100705 return -EBUSY;
100706
100707 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
100708diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
100709index 6ff1346..936ca9a 100644
100710--- a/net/mac80211/rc80211_pid_debugfs.c
100711+++ b/net/mac80211/rc80211_pid_debugfs.c
100712@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
100713
100714 spin_unlock_irqrestore(&events->lock, status);
100715
100716- if (copy_to_user(buf, pb, p))
100717+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
100718 return -EFAULT;
100719
100720 return p;
100721diff --git a/net/mac80211/util.c b/net/mac80211/util.c
100722index b8700d4..89086d5 100644
100723--- a/net/mac80211/util.c
100724+++ b/net/mac80211/util.c
100725@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100726 }
100727 #endif
100728 /* everything else happens only if HW was up & running */
100729- if (!local->open_count)
100730+ if (!local_read(&local->open_count))
100731 goto wake_up;
100732
100733 /*
100734@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100735 local->in_reconfig = false;
100736 barrier();
100737
100738- if (local->monitors == local->open_count && local->monitors > 0)
100739+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
100740 ieee80211_add_virtual_monitor(local);
100741
100742 /*
100743diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
100744index e9410d1..77b6378 100644
100745--- a/net/netfilter/Kconfig
100746+++ b/net/netfilter/Kconfig
100747@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
100748
100749 To compile it as a module, choose M here. If unsure, say N.
100750
100751+config NETFILTER_XT_MATCH_GRADM
100752+ tristate '"gradm" match support'
100753+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
100754+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
100755+ ---help---
100756+ The gradm match allows to match on grsecurity RBAC being enabled.
100757+ It is useful when iptables rules are applied early on bootup to
100758+ prevent connections to the machine (except from a trusted host)
100759+ while the RBAC system is disabled.
100760+
100761 config NETFILTER_XT_MATCH_HASHLIMIT
100762 tristate '"hashlimit" match support'
100763 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
100764diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
100765index bffdad7..f9317d1 100644
100766--- a/net/netfilter/Makefile
100767+++ b/net/netfilter/Makefile
100768@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
100769 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
100770 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
100771 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
100772+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
100773 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
100774 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
100775 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
100776diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
100777index de770ec..3fc49d2 100644
100778--- a/net/netfilter/ipset/ip_set_core.c
100779+++ b/net/netfilter/ipset/ip_set_core.c
100780@@ -1922,7 +1922,7 @@ done:
100781 return ret;
100782 }
100783
100784-static struct nf_sockopt_ops so_set __read_mostly = {
100785+static struct nf_sockopt_ops so_set = {
100786 .pf = PF_INET,
100787 .get_optmin = SO_IP_SET,
100788 .get_optmax = SO_IP_SET + 1,
100789diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
100790index a8eb0a8..86f2de4 100644
100791--- a/net/netfilter/ipvs/ip_vs_conn.c
100792+++ b/net/netfilter/ipvs/ip_vs_conn.c
100793@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
100794 /* Increase the refcnt counter of the dest */
100795 ip_vs_dest_hold(dest);
100796
100797- conn_flags = atomic_read(&dest->conn_flags);
100798+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
100799 if (cp->protocol != IPPROTO_UDP)
100800 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
100801 flags = cp->flags;
100802@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
100803
100804 cp->control = NULL;
100805 atomic_set(&cp->n_control, 0);
100806- atomic_set(&cp->in_pkts, 0);
100807+ atomic_set_unchecked(&cp->in_pkts, 0);
100808
100809 cp->packet_xmit = NULL;
100810 cp->app = NULL;
100811@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
100812
100813 /* Don't drop the entry if its number of incoming packets is not
100814 located in [0, 8] */
100815- i = atomic_read(&cp->in_pkts);
100816+ i = atomic_read_unchecked(&cp->in_pkts);
100817 if (i > 8 || i < 0) return 0;
100818
100819 if (!todrop_rate[i]) return 0;
100820diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100821index 4f26ee4..6a9d7c3 100644
100822--- a/net/netfilter/ipvs/ip_vs_core.c
100823+++ b/net/netfilter/ipvs/ip_vs_core.c
100824@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100825 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100826 /* do not touch skb anymore */
100827
100828- atomic_inc(&cp->in_pkts);
100829+ atomic_inc_unchecked(&cp->in_pkts);
100830 ip_vs_conn_put(cp);
100831 return ret;
100832 }
100833@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100834 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100835 pkts = sysctl_sync_threshold(ipvs);
100836 else
100837- pkts = atomic_add_return(1, &cp->in_pkts);
100838+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100839
100840 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100841 ip_vs_sync_conn(net, cp, pkts);
100842diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100843index 35be035..50f8834 100644
100844--- a/net/netfilter/ipvs/ip_vs_ctl.c
100845+++ b/net/netfilter/ipvs/ip_vs_ctl.c
100846@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100847 */
100848 ip_vs_rs_hash(ipvs, dest);
100849 }
100850- atomic_set(&dest->conn_flags, conn_flags);
100851+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
100852
100853 /* bind the service */
100854 old_svc = rcu_dereference_protected(dest->svc, 1);
100855@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100856 * align with netns init in ip_vs_control_net_init()
100857 */
100858
100859-static struct ctl_table vs_vars[] = {
100860+static ctl_table_no_const vs_vars[] __read_only = {
100861 {
100862 .procname = "amemthresh",
100863 .maxlen = sizeof(int),
100864@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100865 " %-7s %-6d %-10d %-10d\n",
100866 &dest->addr.in6,
100867 ntohs(dest->port),
100868- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100869+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100870 atomic_read(&dest->weight),
100871 atomic_read(&dest->activeconns),
100872 atomic_read(&dest->inactconns));
100873@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100874 "%-7s %-6d %-10d %-10d\n",
100875 ntohl(dest->addr.ip),
100876 ntohs(dest->port),
100877- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100878+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100879 atomic_read(&dest->weight),
100880 atomic_read(&dest->activeconns),
100881 atomic_read(&dest->inactconns));
100882@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100883
100884 entry.addr = dest->addr.ip;
100885 entry.port = dest->port;
100886- entry.conn_flags = atomic_read(&dest->conn_flags);
100887+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100888 entry.weight = atomic_read(&dest->weight);
100889 entry.u_threshold = dest->u_threshold;
100890 entry.l_threshold = dest->l_threshold;
100891@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100892 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100893 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100894 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100895- (atomic_read(&dest->conn_flags) &
100896+ (atomic_read_unchecked(&dest->conn_flags) &
100897 IP_VS_CONN_F_FWD_MASK)) ||
100898 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100899 atomic_read(&dest->weight)) ||
100900@@ -3580,7 +3580,7 @@ out:
100901 }
100902
100903
100904-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100905+static const struct genl_ops ip_vs_genl_ops[] = {
100906 {
100907 .cmd = IPVS_CMD_NEW_SERVICE,
100908 .flags = GENL_ADMIN_PERM,
100909@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100910 {
100911 int idx;
100912 struct netns_ipvs *ipvs = net_ipvs(net);
100913- struct ctl_table *tbl;
100914+ ctl_table_no_const *tbl;
100915
100916 atomic_set(&ipvs->dropentry, 0);
100917 spin_lock_init(&ipvs->dropentry_lock);
100918diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100919index ca056a3..9cf01ef 100644
100920--- a/net/netfilter/ipvs/ip_vs_lblc.c
100921+++ b/net/netfilter/ipvs/ip_vs_lblc.c
100922@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100923 * IPVS LBLC sysctl table
100924 */
100925 #ifdef CONFIG_SYSCTL
100926-static struct ctl_table vs_vars_table[] = {
100927+static ctl_table_no_const vs_vars_table[] __read_only = {
100928 {
100929 .procname = "lblc_expiration",
100930 .data = NULL,
100931diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100932index 3f21a2f..a112e85 100644
100933--- a/net/netfilter/ipvs/ip_vs_lblcr.c
100934+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100935@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100936 * IPVS LBLCR sysctl table
100937 */
100938
100939-static struct ctl_table vs_vars_table[] = {
100940+static ctl_table_no_const vs_vars_table[] __read_only = {
100941 {
100942 .procname = "lblcr_expiration",
100943 .data = NULL,
100944diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100945index db80126..ef7110e 100644
100946--- a/net/netfilter/ipvs/ip_vs_sync.c
100947+++ b/net/netfilter/ipvs/ip_vs_sync.c
100948@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100949 cp = cp->control;
100950 if (cp) {
100951 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100952- pkts = atomic_add_return(1, &cp->in_pkts);
100953+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100954 else
100955 pkts = sysctl_sync_threshold(ipvs);
100956 ip_vs_sync_conn(net, cp->control, pkts);
100957@@ -771,7 +771,7 @@ control:
100958 if (!cp)
100959 return;
100960 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100961- pkts = atomic_add_return(1, &cp->in_pkts);
100962+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100963 else
100964 pkts = sysctl_sync_threshold(ipvs);
100965 goto sloop;
100966@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100967
100968 if (opt)
100969 memcpy(&cp->in_seq, opt, sizeof(*opt));
100970- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100971+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100972 cp->state = state;
100973 cp->old_state = cp->state;
100974 /*
100975diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100976index c47444e..b0961c6 100644
100977--- a/net/netfilter/ipvs/ip_vs_xmit.c
100978+++ b/net/netfilter/ipvs/ip_vs_xmit.c
100979@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100980 else
100981 rc = NF_ACCEPT;
100982 /* do not touch skb anymore */
100983- atomic_inc(&cp->in_pkts);
100984+ atomic_inc_unchecked(&cp->in_pkts);
100985 goto out;
100986 }
100987
100988@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100989 else
100990 rc = NF_ACCEPT;
100991 /* do not touch skb anymore */
100992- atomic_inc(&cp->in_pkts);
100993+ atomic_inc_unchecked(&cp->in_pkts);
100994 goto out;
100995 }
100996
100997diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100998index a4b5e2a..13b1de3 100644
100999--- a/net/netfilter/nf_conntrack_acct.c
101000+++ b/net/netfilter/nf_conntrack_acct.c
101001@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101002 #ifdef CONFIG_SYSCTL
101003 static int nf_conntrack_acct_init_sysctl(struct net *net)
101004 {
101005- struct ctl_table *table;
101006+ ctl_table_no_const *table;
101007
101008 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101009 GFP_KERNEL);
101010diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101011index 356bef5..99932cb 100644
101012--- a/net/netfilter/nf_conntrack_core.c
101013+++ b/net/netfilter/nf_conntrack_core.c
101014@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
101015 #define DYING_NULLS_VAL ((1<<30)+1)
101016 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101017
101018+#ifdef CONFIG_GRKERNSEC_HIDESYM
101019+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101020+#endif
101021+
101022 int nf_conntrack_init_net(struct net *net)
101023 {
101024 int ret;
101025@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
101026 goto err_stat;
101027 }
101028
101029+#ifdef CONFIG_GRKERNSEC_HIDESYM
101030+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101031+#else
101032 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101033+#endif
101034 if (!net->ct.slabname) {
101035 ret = -ENOMEM;
101036 goto err_slabname;
101037diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101038index 1df1761..ce8b88a 100644
101039--- a/net/netfilter/nf_conntrack_ecache.c
101040+++ b/net/netfilter/nf_conntrack_ecache.c
101041@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101042 #ifdef CONFIG_SYSCTL
101043 static int nf_conntrack_event_init_sysctl(struct net *net)
101044 {
101045- struct ctl_table *table;
101046+ ctl_table_no_const *table;
101047
101048 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101049 GFP_KERNEL);
101050diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101051index 974a2a4..52cc6ff 100644
101052--- a/net/netfilter/nf_conntrack_helper.c
101053+++ b/net/netfilter/nf_conntrack_helper.c
101054@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101055
101056 static int nf_conntrack_helper_init_sysctl(struct net *net)
101057 {
101058- struct ctl_table *table;
101059+ ctl_table_no_const *table;
101060
101061 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101062 GFP_KERNEL);
101063diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101064index b65d586..beec902 100644
101065--- a/net/netfilter/nf_conntrack_proto.c
101066+++ b/net/netfilter/nf_conntrack_proto.c
101067@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101068
101069 static void
101070 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101071- struct ctl_table **table,
101072+ ctl_table_no_const **table,
101073 unsigned int users)
101074 {
101075 if (users > 0)
101076diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101077index f641751..d3c5b51 100644
101078--- a/net/netfilter/nf_conntrack_standalone.c
101079+++ b/net/netfilter/nf_conntrack_standalone.c
101080@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101081
101082 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101083 {
101084- struct ctl_table *table;
101085+ ctl_table_no_const *table;
101086
101087 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101088 GFP_KERNEL);
101089diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101090index 7a394df..bd91a8a 100644
101091--- a/net/netfilter/nf_conntrack_timestamp.c
101092+++ b/net/netfilter/nf_conntrack_timestamp.c
101093@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101094 #ifdef CONFIG_SYSCTL
101095 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101096 {
101097- struct ctl_table *table;
101098+ ctl_table_no_const *table;
101099
101100 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101101 GFP_KERNEL);
101102diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101103index 85296d4..8becdec 100644
101104--- a/net/netfilter/nf_log.c
101105+++ b/net/netfilter/nf_log.c
101106@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101107
101108 #ifdef CONFIG_SYSCTL
101109 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101110-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101111+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101112
101113 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101114 void __user *buffer, size_t *lenp, loff_t *ppos)
101115@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101116 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101117 mutex_unlock(&nf_log_mutex);
101118 } else {
101119+ ctl_table_no_const nf_log_table = *table;
101120+
101121 mutex_lock(&nf_log_mutex);
101122 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101123 lockdep_is_held(&nf_log_mutex));
101124 if (!logger)
101125- table->data = "NONE";
101126+ nf_log_table.data = "NONE";
101127 else
101128- table->data = logger->name;
101129- r = proc_dostring(table, write, buffer, lenp, ppos);
101130+ nf_log_table.data = logger->name;
101131+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101132 mutex_unlock(&nf_log_mutex);
101133 }
101134
101135diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101136index f042ae5..30ea486 100644
101137--- a/net/netfilter/nf_sockopt.c
101138+++ b/net/netfilter/nf_sockopt.c
101139@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101140 }
101141 }
101142
101143- list_add(&reg->list, &nf_sockopts);
101144+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101145 out:
101146 mutex_unlock(&nf_sockopt_mutex);
101147 return ret;
101148@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101149 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101150 {
101151 mutex_lock(&nf_sockopt_mutex);
101152- list_del(&reg->list);
101153+ pax_list_del((struct list_head *)&reg->list);
101154 mutex_unlock(&nf_sockopt_mutex);
101155 }
101156 EXPORT_SYMBOL(nf_unregister_sockopt);
101157diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101158index adce01e..8d52d50 100644
101159--- a/net/netfilter/nf_tables_api.c
101160+++ b/net/netfilter/nf_tables_api.c
101161@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101162 #ifdef CONFIG_MODULES
101163 if (autoload) {
101164 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101165- request_module("nft-chain-%u-%*.s", afi->family,
101166- nla_len(nla)-1, (const char *)nla_data(nla));
101167+ request_module("nft-chain-%u-%.*s", afi->family,
101168+ nla_len(nla), (const char *)nla_data(nla));
101169 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101170 type = __nf_tables_chain_type_lookup(afi->family, nla);
101171 if (type != NULL)
101172@@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
101173
101174 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
101175 [NFTA_SET_TABLE] = { .type = NLA_STRING },
101176- [NFTA_SET_NAME] = { .type = NLA_STRING },
101177+ [NFTA_SET_NAME] = { .type = NLA_STRING,
101178+ .len = IFNAMSIZ - 1 },
101179 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
101180 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
101181 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
101182diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101183index a155d19..726b0f2 100644
101184--- a/net/netfilter/nfnetlink_log.c
101185+++ b/net/netfilter/nfnetlink_log.c
101186@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101187 struct nfnl_log_net {
101188 spinlock_t instances_lock;
101189 struct hlist_head instance_table[INSTANCE_BUCKETS];
101190- atomic_t global_seq;
101191+ atomic_unchecked_t global_seq;
101192 };
101193
101194 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101195@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101196 /* global sequence number */
101197 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101198 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101199- htonl(atomic_inc_return(&log->global_seq))))
101200+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101201 goto nla_put_failure;
101202
101203 if (data_len) {
101204diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101205index 82cb823..5685dd5 100644
101206--- a/net/netfilter/nft_compat.c
101207+++ b/net/netfilter/nft_compat.c
101208@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101209 /* We want to reuse existing compat_to_user */
101210 old_fs = get_fs();
101211 set_fs(KERNEL_DS);
101212- t->compat_to_user(out, in);
101213+ t->compat_to_user((void __force_user *)out, in);
101214 set_fs(old_fs);
101215 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101216 kfree(out);
101217@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101218 /* We want to reuse existing compat_to_user */
101219 old_fs = get_fs();
101220 set_fs(KERNEL_DS);
101221- m->compat_to_user(out, in);
101222+ m->compat_to_user((void __force_user *)out, in);
101223 set_fs(old_fs);
101224 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101225 kfree(out);
101226diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101227new file mode 100644
101228index 0000000..c566332
101229--- /dev/null
101230+++ b/net/netfilter/xt_gradm.c
101231@@ -0,0 +1,51 @@
101232+/*
101233+ * gradm match for netfilter
101234